mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
comment authorize
This commit is contained in:
@@ -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 "<a target=\"show_comment\" href=\"{$url}\">".__('Show')."</a>";
|
||||
|
||||
})->asHtml(),
|
||||
})
|
||||
->asHtml(),
|
||||
|
||||
Text::make(__('Status'), function(CommentModel $comment) {
|
||||
Text::make(__('Status'), function (CommentModel $comment) {
|
||||
if ($comment->isApproved()) {
|
||||
return "<div class='inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-green-100 text-green-800'>Approved</div>";
|
||||
}
|
||||
|
||||
return "<div class='inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800'>Pending</div>";
|
||||
})->asHtml(),
|
||||
})
|
||||
->asHtml(),
|
||||
|
||||
DateTime::make(__('Created at'), 'created_at'),
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ class OrangePill extends Resource
|
||||
BelongsTo::make('User'),
|
||||
BelongsTo::make('BookCase'),
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user