From 31e5c39a797996da82c0e1e3ee458c5cb9632b8a Mon Sep 17 00:00:00 2001 From: Benjamin Takats Date: Mon, 12 Dec 2022 21:20:31 +0100 Subject: [PATCH] comment authorize --- app/Nova/Comment.php | 35 +++++++++++++++++++++++++++-------- app/Nova/OrangePill.php | 1 - 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/Nova/Comment.php b/app/Nova/Comment.php index a88e1689..3b0c7e4e 100644 --- a/app/Nova/Comment.php +++ b/app/Nova/Comment.php @@ -2,6 +2,7 @@ namespace App\Nova; +use Illuminate\Http\Request; use Laravel\Nova\Fields\DateTime; use Laravel\Nova\Fields\Markdown; use Laravel\Nova\Fields\MorphTo; @@ -17,35 +18,53 @@ class Comment extends Resource 'id', 'text', ]; + public static function authorizedToCreate(Request $request) + { + return auth() + ->user() + ?->hasRole('super-admin'); + } + + public function authorizedToUpdate(Request $request) + { + return auth() + ->user() + ?->hasRole('super-admin'); + } + public function fields(NovaRequest $request) { return [ Text::make(__('Title'), function (CommentModel $comment) { return $comment->topLevel()->commentable?->commentableName() ?? 'Deleted...'; - })->readonly(), + }) + ->readonly(), - MorphTo::make(__('Commentator'), 'commentator')->types([ - User::class, - ]), + MorphTo::make(__('Commentator'), 'commentator') + ->types([ + User::class, + ]), Markdown::make(__('Original text'), 'original_text'), Text::make('', function (CommentModel $comment) { - if (! $url = $comment?->commentUrl()) { + if (!$url = $comment?->commentUrl()) { return ''; } return "".__('Show').""; - })->asHtml(), + }) + ->asHtml(), - Text::make(__('Status'), function(CommentModel $comment) { + Text::make(__('Status'), function (CommentModel $comment) { if ($comment->isApproved()) { return "
Approved
"; } return "
Pending
"; - })->asHtml(), + }) + ->asHtml(), DateTime::make(__('Created at'), 'created_at'), diff --git a/app/Nova/OrangePill.php b/app/Nova/OrangePill.php index 34d6861a..34b11a16 100644 --- a/app/Nova/OrangePill.php +++ b/app/Nova/OrangePill.php @@ -58,7 +58,6 @@ class OrangePill extends Resource BelongsTo::make('User'), BelongsTo::make('BookCase'), - ]; }