usamamuneerchaudhary /
commentify
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Usamamuneerchaudhary\Commentify\Policies; |
||
| 4 | |||
| 5 | use Illuminate\Auth\Access\HandlesAuthorization; |
||
| 6 | use Illuminate\Auth\Access\Response; |
||
| 7 | use Usamamuneerchaudhary\Commentify\Models\Comment; |
||
| 8 | |||
| 9 | class CommentPolicy |
||
| 10 | { |
||
| 11 | use HandlesAuthorization; |
||
| 12 | |||
| 13 | |||
| 14 | /** |
||
| 15 | * Determine whether the user can view any comments. |
||
| 16 | * @param $user |
||
| 17 | * @return Response |
||
| 18 | */ |
||
| 19 | public function create($user): Response |
||
| 20 | { |
||
| 21 | // Check if the user is temporarily banned from commenting |
||
| 22 | if (method_exists($user, 'isCommentBanned') && $user->isCommentBanned()) { |
||
| 23 | return Response::deny(__('commentify::commentify.comments.banned_message'), 403); |
||
| 24 | } |
||
| 25 | |||
| 26 | return Response::allow(); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param $user |
||
| 31 | * @param Comment $comment |
||
| 32 | * @return Response |
||
| 33 | */ |
||
| 34 | public function update($user, Comment $comment): Response |
||
| 35 | { |
||
| 36 | if (method_exists($user, 'isCommentBanned') && $user->isCommentBanned()) { |
||
| 37 | return Response::deny(__('commentify::commentify.comments.banned_message'), 403); |
||
| 38 | } |
||
| 39 | return $user->id === $comment->user_id |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 40 | ? Response::allow() |
||
| 41 | : Response::denyWithStatus(401); |
||
| 42 | } |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * @param $user |
||
| 47 | * @param Comment $comment |
||
| 48 | * @return Response |
||
| 49 | */ |
||
| 50 | public function destroy($user, Comment $comment): Response |
||
| 51 | { |
||
| 52 | if (method_exists($user, 'isCommentBanned') && $user->isCommentBanned()) { |
||
| 53 | return Response::deny(__('commentify::commentify.comments.banned_message'), 403); |
||
| 54 | } |
||
| 55 | return $user->id === $comment->user_id |
||
|
0 ignored issues
–
show
|
|||
| 56 | ? Response::allow() |
||
| 57 | : Response::denyWithStatus(401); |
||
| 58 | } |
||
| 59 | } |
||
| 60 |