From 14c378bd80dc58c6fd9579ada49c8a1b076faae2 Mon Sep 17 00:00:00 2001 From: Kyrch Date: Mon, 12 Aug 2024 20:14:05 -0300 Subject: [PATCH] feat(filament): added developer dashboard (#722) --- .../Models/Wiki/BackfillAnimeAction.php | 26 +- app/Concerns/Models/CanCreateAnimeSynonym.php | 43 ++ app/Console/Kernel.php | 7 + app/Exceptions/Handler.php | 17 + app/Filament/Dashboards/AdminDashboard.php | 4 +- .../Dashboards/DeveloperDashboard.php | 68 ++ app/Filament/Resources/Admin/Exception.php | 124 ++++ .../Admin/Exception/Pages/ListExceptions.php | 16 + .../Admin/Exception/Pages/ViewException.php | 16 + .../Resources/Discord/DiscordThread.php | 2 +- app/Filament/Resources/Wiki/Anime/Theme.php | 5 +- .../Widgets/Admin/ExceptionsTableWidget.php | 29 + app/Filament/Widgets/BaseTableWidget.php | 15 + app/Models/Admin/ActionLog.php | 24 +- app/Policies/Admin/AnnouncementPolicy.php | 109 +-- app/Policies/Admin/DumpPolicy.php | 109 +-- app/Policies/Admin/FeaturePolicy.php | 57 +- app/Policies/Admin/FeaturedThemePolicy.php | 95 +-- app/Policies/Auth/PermissionPolicy.php | 68 +- app/Policies/Auth/RolePolicy.php | 64 +- app/Policies/Auth/UserPolicy.php | 59 +- app/Policies/BasePolicy.php | 146 ++++ app/Policies/Discord/DiscordThreadPolicy.php | 91 +-- app/Policies/Document/PagePolicy.php | 109 +-- .../List/External/ExternalEntryPolicy.php | 27 +- app/Policies/List/ExternalProfilePolicy.php | 27 +- .../List/Playlist/PlaylistTrackPolicy.php | 27 +- app/Policies/List/PlaylistPolicy.php | 27 +- .../Wiki/Anime/AnimeSynonymPolicy.php | 109 +-- app/Policies/Wiki/Anime/AnimeThemePolicy.php | 109 +-- .../Anime/Theme/AnimeThemeEntryPolicy.php | 107 +-- app/Policies/Wiki/AnimePolicy.php | 107 +-- app/Policies/Wiki/ArtistPolicy.php | 107 +-- app/Policies/Wiki/AudioPolicy.php | 107 +-- app/Policies/Wiki/ExternalResourcePolicy.php | 107 +-- app/Policies/Wiki/GroupPolicy.php | 96 +-- app/Policies/Wiki/ImagePolicy.php | 107 +-- app/Policies/Wiki/SeriesPolicy.php | 107 +-- app/Policies/Wiki/SongPolicy.php | 107 +-- app/Policies/Wiki/StudioPolicy.php | 107 +-- app/Policies/Wiki/Video/VideoScriptPolicy.php | 109 +-- app/Policies/Wiki/VideoPolicy.php | 107 +-- app/Providers/FilamentPanelProvider.php | 3 + composer.json | 1 + composer.lock | 691 ++++++++++-------- config/filament-exceptions.php | 61 ++ ...52046_create_filament_exceptions_table.php | 44 ++ lang/en/filament.php | 4 +- .../en/filament-exceptions.php | 33 + .../filament-exceptions.css | 1 + .../filament-exceptions.js | 639 ++++++++++++++++ .../Enums/Models/Wiki/ResourceSiteTest.php | 32 +- 52 files changed, 1834 insertions(+), 2579 deletions(-) create mode 100644 app/Concerns/Models/CanCreateAnimeSynonym.php create mode 100644 app/Filament/Dashboards/DeveloperDashboard.php create mode 100644 app/Filament/Resources/Admin/Exception.php create mode 100644 app/Filament/Resources/Admin/Exception/Pages/ListExceptions.php create mode 100644 app/Filament/Resources/Admin/Exception/Pages/ViewException.php create mode 100644 app/Filament/Widgets/Admin/ExceptionsTableWidget.php create mode 100644 app/Filament/Widgets/BaseTableWidget.php create mode 100644 app/Policies/BasePolicy.php create mode 100644 config/filament-exceptions.php create mode 100644 database/migrations/2024_08_12_052046_create_filament_exceptions_table.php create mode 100644 lang/vendor/filament-exceptions/en/filament-exceptions.php create mode 100644 public/css/bezhansalleh/filament-exceptions/filament-exceptions.css create mode 100644 public/js/bezhansalleh/filament-exceptions/filament-exceptions.js diff --git a/app/Actions/Models/Wiki/BackfillAnimeAction.php b/app/Actions/Models/Wiki/BackfillAnimeAction.php index 6295817f1..08d4b8496 100644 --- a/app/Actions/Models/Wiki/BackfillAnimeAction.php +++ b/app/Actions/Models/Wiki/BackfillAnimeAction.php @@ -10,11 +10,10 @@ use App\Actions\Models\Wiki\Anime\ApiAction\AnilistAnimeApiAction; use App\Actions\Models\Wiki\Anime\ApiAction\JikanAnimeApiAction; use App\Actions\Models\Wiki\Anime\ApiAction\LivechartAnimeApiAction; use App\Actions\Models\Wiki\Anime\ApiAction\MalAnimeApiAction; +use App\Concerns\Models\CanCreateAnimeSynonym; use App\Concerns\Models\CanCreateStudio; use App\Enums\Actions\ActionStatus; -use App\Enums\Models\Wiki\AnimeSynonymType; use App\Models\Wiki\Anime; -use App\Models\Wiki\Anime\AnimeSynonym; use Exception; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; @@ -25,6 +24,7 @@ use Illuminate\Support\Facades\Log; */ class BackfillAnimeAction extends BackfillWikiAction { + use CanCreateAnimeSynonym; use CanCreateStudio; final public const STUDIOS = 'studios'; @@ -124,10 +124,10 @@ class BackfillAnimeAction extends BackfillWikiAction Log::info("Attaching Studio of name '$name' to Anime {$this->getModel()->getName()}"); $this->getModel()->studios()->attach($studio); - $this->toBackfill[self::STUDIOS] = false; - $this->ensureStudioHasResource($studio, $response->getSite(), $id); } + + $this->toBackfill[self::STUDIOS] = false; } /** @@ -141,22 +141,10 @@ class BackfillAnimeAction extends BackfillWikiAction if (!$this->toBackfill[self::SYNONYMS]) return; foreach ($api->getSynonyms() as $type => $text) { - if ( - $text === null - || empty($text) - || ($type === AnimeSynonymType::OTHER->value && $text === $this->getModel()->getName()) - ) continue; - - Log::info("Creating {$text}"); - - AnimeSynonym::query()->create([ - AnimeSynonym::ATTRIBUTE_TEXT => $text, - AnimeSynonym::ATTRIBUTE_TYPE => $type, - AnimeSynonym::ATTRIBUTE_ANIME => $this->getModel()->getKey(), - ]); - - $this->toBackfill[self::SYNONYMS] = false; + $this->createAnimeSynonym($text, $type, $this->getModel()); } + + $this->toBackfill[self::SYNONYMS] = false; } /** diff --git a/app/Concerns/Models/CanCreateAnimeSynonym.php b/app/Concerns/Models/CanCreateAnimeSynonym.php new file mode 100644 index 000000000..f1eba118d --- /dev/null +++ b/app/Concerns/Models/CanCreateAnimeSynonym.php @@ -0,0 +1,43 @@ +value && $text === $anime->getName()) + ) { + return; + } + + Log::info("Creating {$text} for Anime {$anime->getName()}"); + + AnimeSynonym::query()->create([ + AnimeSynonym::ATTRIBUTE_TEXT => $text, + AnimeSynonym::ATTRIBUTE_TYPE => $type, + AnimeSynonym::ATTRIBUTE_ANIME => $anime->getKey(), + ]); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index cd2378f4b..f128885ab 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -8,6 +8,7 @@ use App\Console\Commands\Storage\Admin\DocumentDumpCommand; use App\Console\Commands\Storage\Admin\DumpPruneCommand; use App\Console\Commands\Storage\Admin\WikiDumpCommand; use App\Models\BaseModel; +use BezhanSalleh\FilamentExceptions\Models\Exception; use Illuminate\Auth\Console\ClearResetsCommand; use Illuminate\Cache\Console\PruneStaleTagsCommand; use Illuminate\Console\Scheduling\Schedule; @@ -97,6 +98,12 @@ class Kernel extends ConsoleKernel ->storeOutput() ->daily(); + $schedule->command(PruneModelsCommand::class, ['--model' => [Exception::class]]) // Filament Exception Viewer Plugin + ->withoutOverlapping() + ->runInBackground() + ->storeOutput() + ->daily(); + $schedule->command(PruneStaleTagsCommand::class) ->withoutOverlapping() ->runInBackground() diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 8b7f36e83..c48bb5a10 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,7 +4,10 @@ declare(strict_types=1); namespace App\Exceptions; +use BezhanSalleh\FilamentExceptions\FilamentExceptions; +use Filament\Facades\Filament; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Throwable; /** * Class Handler. @@ -21,4 +24,18 @@ class Handler extends ExceptionHandler 'password', 'password_confirmation', ]; + + /** + * Register the exception handling callbacks for the application. + * + * @return void + */ + public function register(): void + { + $this->reportable(function (Throwable $e) { + if (Filament::isServing() && $this->shouldReport($e)) { + FilamentExceptions::report($e); + } + }); + } } diff --git a/app/Filament/Dashboards/AdminDashboard.php b/app/Filament/Dashboards/AdminDashboard.php index 4f27bab62..a7dd4f8af 100644 --- a/app/Filament/Dashboards/AdminDashboard.php +++ b/app/Filament/Dashboards/AdminDashboard.php @@ -10,7 +10,7 @@ use App\Filament\Widgets\List\ExternalProfileChart; use App\Filament\Widgets\List\PlaylistChart; use App\Filament\Widgets\List\PlaylistTrackChart; use App\Models\Auth\User; -use Illuminate\Support\Facades\Auth; +use Filament\Facades\Filament; /** * Class AdminDashboard. @@ -34,7 +34,7 @@ class AdminDashboard extends BaseDashboard */ public static function canAccess(): bool { - return User::find(Auth::id())->hasRole(RoleEnum::ADMIN->value); + return User::find(Filament::auth()->id())->hasRole(RoleEnum::ADMIN->value); } /** diff --git a/app/Filament/Dashboards/DeveloperDashboard.php b/app/Filament/Dashboards/DeveloperDashboard.php new file mode 100644 index 000000000..b1bf1b709 --- /dev/null +++ b/app/Filament/Dashboards/DeveloperDashboard.php @@ -0,0 +1,68 @@ +id())->hasRole(RoleEnum::ADMIN->value); + } + + /** + * Get the displayed label for the dashboard. + * + * @return string + */ + public static function getNavigationLabel(): string + { + return __('filament.dashboards.label.dev'); + } + + /** + * Get the icon for the dashboard. + * + * @return string + */ + public static function getNavigationIcon(): string + { + return __('filament.dashboards.icon.dev');; + } + + /** + * Get the widgets available for the dashboard. + * + * @return class-string[] + */ + public function getWidgets(): array + { + return [ + ExceptionsTableWidget::class, + ]; + } +} \ No newline at end of file diff --git a/app/Filament/Resources/Admin/Exception.php b/app/Filament/Resources/Admin/Exception.php new file mode 100644 index 000000000..0f7881911 --- /dev/null +++ b/app/Filament/Resources/Admin/Exception.php @@ -0,0 +1,124 @@ +query(ExceptionModel::query()) + ->columns([ + TextColumn::make('method') + ->label(__('filament-exceptions::filament-exceptions.columns.method')) + ->badge() + ->colors([ + 'gray', + 'success' => fn ($state): bool => $state === 'GET', + 'primary' => fn ($state): bool => $state === 'POST', + 'warning' => fn ($state): bool => $state === 'PUT' || $state === 'PATCH', + 'danger' => fn ($state): bool => $state === 'DELETE', + 'gray' => fn ($state): bool => $state === 'OPTIONS', + ]) + ->searchable() + ->sortable(), + + TextColumn::make('path') + ->label(__('filament-exceptions::filament-exceptions.columns.path')) + ->searchable(), + + TextColumn::make('type') + ->label(__('filament-exceptions::filament-exceptions.columns.type')) + ->sortable() + ->searchable(), + + TextColumn::make('code') + ->label(__('filament-exceptions::filament-exceptions.columns.code')) + ->searchable() + ->sortable() + ->toggleable(), + + TextColumn::make('created_at') + ->label(__('filament-exceptions::filament-exceptions.columns.occurred_at')) + ->sortable() + ->searchable() + ->dateTime() + ->toggleable(), + ]) + ->actions([ + ViewAction::make('view') + ->url(fn (ExceptionModel $record): string => ExceptionResource::getUrl('view', ['record' => $record])) + ]) + ->bulkActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ]), + ]) + ->defaultSort('created_at', 'desc'); + } + + /** + * Determine if the user can access the table. + * + * @return bool + */ + public static function canViewAny(): bool + { + /** @var User $user */ + $user = Filament::auth()->user(); + return $user->hasRole(Role::ADMIN->value); + } + + /** + * Get the pages available for the resource. + * + * @return array + * + * @noinspection PhpMissingParentCallCommonInspection + */ + public static function getPages(): array + { + return [ + 'index' => ListExceptions::route('/'), + 'view' => ViewException::route('/{record}') + ]; + } +} diff --git a/app/Filament/Resources/Admin/Exception/Pages/ListExceptions.php b/app/Filament/Resources/Admin/Exception/Pages/ListExceptions.php new file mode 100644 index 000000000..21114ca0e --- /dev/null +++ b/app/Filament/Resources/Admin/Exception/Pages/ListExceptions.php @@ -0,0 +1,16 @@ +label(__('filament.fields.discord_thread.name.name')) ->sortable() ->copyableWithMessage() + ->searchable() ->toggleable(), BelongsToColumn::make(DiscordThreadModel::RELATION_ANIME.'.'.Anime::ATTRIBUTE_NAME) ->resource(AnimeResource::class) ->toggleable(), ]) - ->searchable() ->defaultSort(BaseModel::CREATED_AT, 'desc'); } diff --git a/app/Filament/Resources/Wiki/Anime/Theme.php b/app/Filament/Resources/Wiki/Anime/Theme.php index b6a816c59..77bff98c4 100644 --- a/app/Filament/Resources/Wiki/Anime/Theme.php +++ b/app/Filament/Resources/Wiki/Anime/Theme.php @@ -434,7 +434,10 @@ class Theme extends BaseResource if ($slug->isNotEmpty()) { $group = $get(ThemeModel::ATTRIBUTE_GROUP); - $slug = $slug->append(empty($group) ? '' : '-' . Group::find(intval($group))->slug); + + if (!empty($group)) { + $slug = $slug->append('-' . Group::find(intval($group))->slug); + } } $set(ThemeModel::ATTRIBUTE_SLUG, $slug->__toString()); diff --git a/app/Filament/Widgets/Admin/ExceptionsTableWidget.php b/app/Filament/Widgets/Admin/ExceptionsTableWidget.php new file mode 100644 index 000000000..96e4b5af8 --- /dev/null +++ b/app/Filament/Widgets/Admin/ExceptionsTableWidget.php @@ -0,0 +1,29 @@ +heading(__('filament-exceptions::filament-exceptions.labels.model_plural')); + } +} diff --git a/app/Filament/Widgets/BaseTableWidget.php b/app/Filament/Widgets/BaseTableWidget.php new file mode 100644 index 000000000..41efdfa4c --- /dev/null +++ b/app/Filament/Widgets/BaseTableWidget.php @@ -0,0 +1,15 @@ +user(); + return Filament::auth()->id(); } /** @@ -180,8 +180,8 @@ class ActionLog extends Model implements Nameable, HasSubtitle public static function modelCreated(Model $model): ActionLog { return ActionLog::query()->create([ - ActionLog::ATTRIBUTE_BATCH_ID => (string) Str::orderedUuid(), - ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), + ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), + ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(), ActionLog::ATTRIBUTE_NAME => 'Create', ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), @@ -203,8 +203,8 @@ class ActionLog extends Model implements Nameable, HasSubtitle public static function modelUpdated(Model $model): ActionLog { return ActionLog::query()->create([ - ActionLog::ATTRIBUTE_BATCH_ID => (string) Str::orderedUuid(), - ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), + ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), + ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(), ActionLog::ATTRIBUTE_NAME => 'Update', ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), @@ -250,7 +250,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle { return ActionLog::query()->create([ ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), - ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), + ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(), ActionLog::ATTRIBUTE_NAME => $actionName, ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), @@ -276,7 +276,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle { return ActionLog::query()->create([ ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), - ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), + ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(), ActionLog::ATTRIBUTE_NAME => $action, ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $related->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $related->getKey(), @@ -301,7 +301,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle { return ActionLog::query()->create([ ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), - ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), + ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(), ActionLog::ATTRIBUTE_NAME => $action, ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $related->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $related->getKey(), @@ -326,7 +326,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle { return ActionLog::query()->create([ ActionLog::ATTRIBUTE_BATCH_ID => $batchId, - ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), + ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(), ActionLog::ATTRIBUTE_NAME => $action->getLabel(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), diff --git a/app/Policies/Admin/AnnouncementPolicy.php b/app/Policies/Admin/AnnouncementPolicy.php index da2e7af66..933004052 100644 --- a/app/Policies/Admin/AnnouncementPolicy.php +++ b/app/Policies/Admin/AnnouncementPolicy.php @@ -4,116 +4,11 @@ declare(strict_types=1); namespace App\Policies\Admin; -use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; -use App\Models\Admin\Announcement; -use App\Models\Auth\User; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class AnnouncementPolicy. */ -class AnnouncementPolicy +class AnnouncementPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Announcement::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Announcement::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Announcement::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Announcement $announcement - * @return bool - */ - public function update(User $user, Announcement $announcement): bool - { - return ! $announcement->trashed() && $user->can(CrudPermission::UPDATE->format(Announcement::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Announcement $announcement - * @return bool - */ - public function delete(User $user, Announcement $announcement): bool - { - return ! $announcement->trashed() && $user->can(CrudPermission::DELETE->format(Announcement::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Announcement $announcement - * @return bool - */ - public function restore(User $user, Announcement $announcement): bool - { - return $announcement->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Announcement::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Announcement::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Announcement::class)); - } } diff --git a/app/Policies/Admin/DumpPolicy.php b/app/Policies/Admin/DumpPolicy.php index 0985b8fc2..d7f316d46 100644 --- a/app/Policies/Admin/DumpPolicy.php +++ b/app/Policies/Admin/DumpPolicy.php @@ -4,116 +4,11 @@ declare(strict_types=1); namespace App\Policies\Admin; -use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; -use App\Models\Admin\Dump; -use App\Models\Auth\User; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class DumpPolicy. */ -class DumpPolicy +class DumpPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Dump::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Dump::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Dump::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Dump $dump - * @return bool - */ - public function update(User $user, Dump $dump): bool - { - return ! $dump->trashed() && $user->can(CrudPermission::UPDATE->format(Dump::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Dump $dump - * @return bool - */ - public function delete(User $user, Dump $dump): bool - { - return ! $dump->trashed() && $user->can(CrudPermission::DELETE->format(Dump::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Dump $dump - * @return bool - */ - public function restore(User $user, Dump $dump): bool - { - return $dump->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Dump::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Dump::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Dump::class)); - } } diff --git a/app/Policies/Admin/FeaturePolicy.php b/app/Policies/Admin/FeaturePolicy.php index 0aee01e46..4bd2a9c2d 100644 --- a/app/Policies/Admin/FeaturePolicy.php +++ b/app/Policies/Admin/FeaturePolicy.php @@ -7,31 +7,15 @@ namespace App\Policies\Admin; use App\Enums\Auth\CrudPermission; use App\Models\Admin\Feature; use App\Models\Auth\User; +use App\Policies\BasePolicy; use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Database\Eloquent\Model; /** * Class FeaturePolicy. */ -class FeaturePolicy +class FeaturePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)); - } - - return true; - } - /** * Determine whether the user can view the model. * @@ -39,7 +23,7 @@ class FeaturePolicy * @param Feature $feature * @return bool */ - public function view(?User $user, Feature $feature): bool + public function view(?User $user, Model $feature): bool { if (Filament::isServing()) { return $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)); @@ -47,37 +31,4 @@ class FeaturePolicy return $feature->isNullScope(); } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Feature::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @return bool - */ - public function update(User $user): bool - { - return $user->can(CrudPermission::UPDATE->format(Feature::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @return bool - */ - public function delete(User $user): bool - { - return $user->can(CrudPermission::DELETE->format(Feature::class)); - } } diff --git a/app/Policies/Admin/FeaturedThemePolicy.php b/app/Policies/Admin/FeaturedThemePolicy.php index bcaeb8aff..c5398b025 100644 --- a/app/Policies/Admin/FeaturedThemePolicy.php +++ b/app/Policies/Admin/FeaturedThemePolicy.php @@ -5,35 +5,19 @@ declare(strict_types=1); namespace App\Policies\Admin; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Admin\FeaturedTheme; use App\Models\Auth\User; +use App\Models\BaseModel; +use App\Policies\BasePolicy; use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Date; /** * Class FeaturedThemePolicy. */ -class FeaturedThemePolicy +class FeaturedThemePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(FeaturedTheme::class)); - } - - return true; - } - /** * Determine whether the user can view the model. * @@ -41,7 +25,7 @@ class FeaturedThemePolicy * @param FeaturedTheme $featuredtheme * @return bool */ - public function view(?User $user, FeaturedTheme $featuredtheme): bool + public function view(?User $user, BaseModel|Model $featuredtheme): bool { if (Filament::isServing()) { return $user !== null && $user->can(CrudPermission::VIEW->format(FeaturedTheme::class)); @@ -49,73 +33,4 @@ class FeaturedThemePolicy return $featuredtheme->start_at->isBefore(Date::now()); } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(FeaturedTheme::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param FeaturedTheme $featuredtheme - * @return bool - */ - public function update(User $user, FeaturedTheme $featuredtheme): bool - { - return ! $featuredtheme->trashed() && $user->can(CrudPermission::UPDATE->format(FeaturedTheme::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param FeaturedTheme $featuredtheme - * @return bool - */ - public function delete(User $user, FeaturedTheme $featuredtheme): bool - { - return ! $featuredtheme->trashed() && $user->can(CrudPermission::DELETE->format(FeaturedTheme::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param FeaturedTheme $featuredtheme - * @return bool - */ - public function restore(User $user, FeaturedTheme $featuredtheme): bool - { - return $featuredtheme->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(FeaturedTheme::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(FeaturedTheme::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(FeaturedTheme::class)); - } } diff --git a/app/Policies/Auth/PermissionPolicy.php b/app/Policies/Auth/PermissionPolicy.php index 02e951e3d..abe68d054 100644 --- a/app/Policies/Auth/PermissionPolicy.php +++ b/app/Policies/Auth/PermissionPolicy.php @@ -8,55 +8,49 @@ use App\Enums\Auth\CrudPermission; use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\Permission; use App\Models\Auth\User; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; +use Illuminate\Database\Eloquent\Model; /** * Class PermissionPolicy. */ -class PermissionPolicy +class PermissionPolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * - * @param User $user + * @param User|null $user * @return bool */ - public function viewAny(User $user): bool + public function viewAny(?User $user): bool { - return $user->can(CrudPermission::VIEW->format(Permission::class)); + return $user !== null && $user->can(CrudPermission::VIEW->format(Permission::class)); } /** * Determine whether the user can view the model. * - * @param User $user + * @param User|null $user + * @param Permission $permission * @return bool - */ - public function view(User $user): bool - { - return $user->can(CrudPermission::VIEW->format(Permission::class)); - } - - /** - * Determine whether the user can create models. * - * @param User $user - * @return bool + * @noinspection PhpUnusedParameterInspection */ - public function create(User $user): bool + public function view(?User $user, Model $permission): bool { - return $user->can(CrudPermission::CREATE->format(Permission::class)); + return $user !== null && $user->can(CrudPermission::VIEW->format(Permission::class)); } /** * Determine whether the user can update the model. * * @param User $user + * @param Permission $permission * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function update(User $user): bool + public function update(User $user, Model $permission): bool { return $user->can(CrudPermission::UPDATE->format(Permission::class)); } @@ -65,9 +59,12 @@ class PermissionPolicy * Determine whether the user can delete the model. * * @param User $user + * @param Permission $permission * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function delete(User $user): bool + public function delete(User $user, Model $permission): bool { return $user->can(CrudPermission::DELETE->format(Permission::class)); } @@ -76,35 +73,16 @@ class PermissionPolicy * Determine whether the user can restore the model. * * @param User $user + * @param Permission $permission * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function restore(User $user): bool + public function restore(User $user, Model $permission): bool { return $user->can(ExtendedCrudPermission::RESTORE->format(Permission::class)); } - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Permission::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Permission::class)); - } - /** * Determine whether the user can attach any role to the permission. * diff --git a/app/Policies/Auth/RolePolicy.php b/app/Policies/Auth/RolePolicy.php index fcf3d49f9..f41fbd5f3 100644 --- a/app/Policies/Auth/RolePolicy.php +++ b/app/Policies/Auth/RolePolicy.php @@ -8,22 +8,21 @@ use App\Enums\Auth\CrudPermission; use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\Role; use App\Models\Auth\User; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; +use Illuminate\Database\Eloquent\Model; /** * Class RolePolicy. */ -class RolePolicy +class RolePolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * - * @param User $user + * @param User|null $user * @return bool */ - public function viewAny(User $user): bool + public function viewAny(?User $user): bool { return $user->can(CrudPermission::VIEW->format(Role::class)); } @@ -31,32 +30,25 @@ class RolePolicy /** * Determine whether the user can view the model. * - * @param User $user + * @param User|null $user + * @param Role $role * @return bool */ - public function view(User $user): bool + public function view(?User $user, Model $role): bool { return $user->can(CrudPermission::VIEW->format(Role::class)); } - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Role::class)); - } - /** * Determine whether the user can update the model. * * @param User $user + * @param Role $role * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function update(User $user): bool + public function update(User $user, Model $role): bool { return $user->can(CrudPermission::UPDATE->format(Role::class)); } @@ -65,9 +57,12 @@ class RolePolicy * Determine whether the user can delete the model. * * @param User $user + * @param Role $role * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function delete(User $user): bool + public function delete(User $user, Model $role): bool { return $user->can(CrudPermission::DELETE->format(Role::class)); } @@ -76,35 +71,16 @@ class RolePolicy * Determine whether the user can restore the model. * * @param User $user + * @param Role $role * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function restore(User $user): bool + public function restore(User $user, Model $role): bool { return $user->can(ExtendedCrudPermission::RESTORE->format(Role::class)); } - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Role::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Role::class)); - } - /** * Determine whether the user can attach any permission to the role. * diff --git a/app/Policies/Auth/UserPolicy.php b/app/Policies/Auth/UserPolicy.php index 87a1733fb..1bfebc6b5 100644 --- a/app/Policies/Auth/UserPolicy.php +++ b/app/Policies/Auth/UserPolicy.php @@ -8,55 +8,49 @@ use App\Enums\Auth\CrudPermission; use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\Role as RoleEnum; use App\Models\Auth\User; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; +use Illuminate\Database\Eloquent\Model; /** * Class UserPolicy. */ -class UserPolicy +class UserPolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * - * @param User $user + * @param User|null $user * @return bool */ - public function viewAny(User $user): bool + public function viewAny(?User $user): bool { - return $user->can(CrudPermission::VIEW->format(User::class)); + return $user !== null && $user->can(CrudPermission::VIEW->format(User::class)); } /** * Determine whether the user can view the model. * - * @param User $user + * @param User|null $user + * @param User $userModel * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function view(User $user): bool + public function view(?User $user, Model $userModel): bool { - return $user->can(CrudPermission::VIEW->format(User::class)); - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(User::class)); + return $user !== null && $user->can(CrudPermission::VIEW->format(User::class)); } /** * Determine whether the user can update the model. * * @param User $user + * @param User $userModel * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function update(User $user): bool + public function update(User $user, Model $userModel): bool { return $user->can(CrudPermission::UPDATE->format(User::class)); } @@ -65,9 +59,12 @@ class UserPolicy * Determine whether the user can delete the model. * * @param User $user + * @param User $userModel * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function delete(User $user): bool + public function delete(User $user, Model $userModel): bool { return $user->can(CrudPermission::DELETE->format(User::class)); } @@ -76,24 +73,16 @@ class UserPolicy * Determine whether the user can restore the model. * * @param User $user + * @param User $userModel * @return bool + * + * @noinspection PhpUnusedParameterInspection */ - public function restore(User $user): bool + public function restore(User $user, Model $userModel): bool { return $user->can(ExtendedCrudPermission::RESTORE->format(User::class)); } - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(User::class)); - } - /** * Determine whether the user can attach any role to the user. * diff --git a/app/Policies/BasePolicy.php b/app/Policies/BasePolicy.php new file mode 100644 index 000000000..425f8be57 --- /dev/null +++ b/app/Policies/BasePolicy.php @@ -0,0 +1,146 @@ +replace('Policies', 'Models') + ->remove('Policy') + ->__toString(); + } + + /** + * Determine whether the user can view any models. + * + * @param User|null $user + * @return bool + */ + public function viewAny(?User $user): bool + { + if (Filament::isServing()) { + return $user !== null && $user->can(CrudPermission::VIEW->format(static::getModel())); + } + + return true; + } + + /** + * Determine whether the user can view the model. + * + * @param User|null $user + * @param BaseModel|Model $model + * @return bool + */ + public function view(?User $user, BaseModel|Model $model): bool + { + if (Filament::isServing()) { + return $user !== null && $user->can(CrudPermission::VIEW->format(static::getModel())); + } + + return true; + } + + /** + * Determine whether the user can create models. + * + * @param User $user + * @return bool + */ + public function create(User $user): bool + { + return $user->can(CrudPermission::CREATE->format(static::getModel())); + } + + /** + * Determine whether the user can update the model. + * + * @param User $user + * @param BaseModel|Model $model + * @return bool + */ + public function update(User $user, BaseModel|Model $model): bool + { + return (!($model instanceof BaseModel) || !$model->trashed()) && $user->can(CrudPermission::UPDATE->format(static::getModel())); + } + + /** + * Determine whether the user can delete the model. + * + * @param User $user + * @param BaseModel|Model $model + * @return bool + */ + public function delete(User $user, BaseModel|Model $model): bool + { + return (!($model instanceof BaseModel) || !$model->trashed()) && $user->can(CrudPermission::DELETE->format(static::getModel())); + } + + /** + * Determine whether the user can permanently delete the model. + * + * @param User $user + * @return bool + */ + public function forceDelete(User $user): bool + { + return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(static::getModel())); + } + + /** + * Determine whether the user can permanently delete any model. + * + * @param User $user + * @return bool + */ + public function forceDeleteAny(User $user): bool + { + return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(static::getModel())); + } + + /** + * Determine whether the user can restore the model. + * + * @param User $user + * @param BaseModel|Model $model + * @return bool + */ + public function restore(User $user, BaseModel|Model $model): bool + { + return (!($model instanceof BaseModel) || $model->trashed()) && $user->can(ExtendedCrudPermission::RESTORE->format(static::getModel())); + } + + /** + * Determine whether the user can restore any model. + * + * @param User $user + * @return bool + */ + public function restoreAny(User $user): bool + { + return $user->can(ExtendedCrudPermission::RESTORE->format(static::getModel())); + } +} diff --git a/app/Policies/Discord/DiscordThreadPolicy.php b/app/Policies/Discord/DiscordThreadPolicy.php index beb4addd2..27b51c32f 100644 --- a/app/Policies/Discord/DiscordThreadPolicy.php +++ b/app/Policies/Discord/DiscordThreadPolicy.php @@ -4,98 +4,11 @@ declare(strict_types=1); namespace App\Policies\Discord; -use App\Enums\Auth\CrudPermission; -use App\Models\Auth\User; -use App\Models\Discord\DiscordThread; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class DiscordThreadPolicy. */ -class DiscordThreadPolicy +class DiscordThreadPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - return Filament::isServing() - ? $user !== null && $user->can(CrudPermission::VIEW->format(DiscordThread::class)) - : true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - return Filament::isServing() - ? $user !== null && $user->can(CrudPermission::VIEW->format(DiscordThread::class)) - : true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(DiscordThread::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param DiscordThread $discordThread - * @return bool - */ - public function update(User $user, DiscordThread $discordThread): bool - { - return ! $discordThread->trashed() && $user->can(CrudPermission::UPDATE->format(DiscordThread::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @return bool - */ - public function delete(User $user): bool - { - return $user->can(CrudPermission::DELETE->format(DiscordThread::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(CrudPermission::DELETE->format(DiscordThread::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(CrudPermission::DELETE->format(DiscordThread::class)); - } } diff --git a/app/Policies/Document/PagePolicy.php b/app/Policies/Document/PagePolicy.php index 7b9821695..a3d98ca75 100644 --- a/app/Policies/Document/PagePolicy.php +++ b/app/Policies/Document/PagePolicy.php @@ -4,116 +4,11 @@ declare(strict_types=1); namespace App\Policies\Document; -use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; -use App\Models\Auth\User; -use App\Models\Document\Page; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class PagePolicy. */ -class PagePolicy +class PagePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Page::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Page::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Page::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Page $page - * @return bool - */ - public function update(User $user, Page $page): bool - { - return ! $page->trashed() && $user->can(CrudPermission::UPDATE->format(Page::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Page $page - * @return bool - */ - public function delete(User $user, Page $page): bool - { - return ! $page->trashed() && $user->can(CrudPermission::DELETE->format(Page::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Page $page - * @return bool - */ - public function restore(User $user, Page $page): bool - { - return $page->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Page::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Page::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Page::class)); - } } diff --git a/app/Policies/List/External/ExternalEntryPolicy.php b/app/Policies/List/External/ExternalEntryPolicy.php index 4f8c533a9..997172fca 100644 --- a/app/Policies/List/External/ExternalEntryPolicy.php +++ b/app/Policies/List/External/ExternalEntryPolicy.php @@ -8,18 +8,18 @@ use App\Enums\Auth\CrudPermission; use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Models\List\ExternalProfileVisibility; use App\Models\Auth\User; +use App\Models\BaseModel; use App\Models\List\ExternalProfile; use App\Models\List\External\ExternalEntry; +use App\Policies\BasePolicy; use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Database\Eloquent\Model; /** * Class ExternalEntryPolicy. */ -class ExternalEntryPolicy +class ExternalEntryPolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * @@ -49,7 +49,7 @@ class ExternalEntryPolicy * * @noinspection PhpUnusedParameterInspection */ - public function view(?User $user, ExternalEntry $entry): bool + public function view(?User $user, BaseModel|Model $entry): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -90,7 +90,7 @@ class ExternalEntryPolicy * * @noinspection PhpUnusedParameterInspection */ - public function update(User $user, ExternalEntry $entry): bool + public function update(User $user, BaseModel|Model $entry): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -111,7 +111,7 @@ class ExternalEntryPolicy * * @noinspection PhpUnusedParameterInspection */ - public function delete(User $user, ExternalEntry $entry): bool + public function delete(User $user, BaseModel|Model $entry): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -132,7 +132,7 @@ class ExternalEntryPolicy * * @noinspection PhpUnusedParameterInspection */ - public function restore(User $user, ExternalEntry $entry): bool + public function restore(User $user, BaseModel|Model $entry): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -143,15 +143,4 @@ class ExternalEntryPolicy return $entry->trashed() && $user->getKey() === $profile?->user_id && $user->can(ExtendedCrudPermission::RESTORE->format(ExternalEntry::class)); } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(ExternalEntry::class)); - } } diff --git a/app/Policies/List/ExternalProfilePolicy.php b/app/Policies/List/ExternalProfilePolicy.php index dcbd9da31..afbaecdd9 100644 --- a/app/Policies/List/ExternalProfilePolicy.php +++ b/app/Policies/List/ExternalProfilePolicy.php @@ -8,17 +8,17 @@ use App\Enums\Auth\CrudPermission; use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Models\List\ExternalProfileVisibility; use App\Models\Auth\User; +use App\Models\BaseModel; use App\Models\List\ExternalProfile; +use App\Policies\BasePolicy; use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Database\Eloquent\Model; /** * Class ExternalProfilePolicy. */ -class ExternalProfilePolicy +class ExternalProfilePolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * @@ -41,7 +41,7 @@ class ExternalProfilePolicy * @param ExternalProfile $profile * @return bool */ - public function view(?User $user, ExternalProfile $profile): bool + public function view(?User $user, BaseModel|Model $profile): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -74,7 +74,7 @@ class ExternalProfilePolicy * @param ExternalProfile $profile * @return bool */ - public function update(User $user, ExternalProfile $profile): bool + public function update(User $user, BaseModel|Model $profile): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -90,7 +90,7 @@ class ExternalProfilePolicy * @param ExternalProfile $profile * @return bool */ - public function delete(User $user, ExternalProfile $profile): bool + public function delete(User $user, BaseModel|Model $profile): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -106,7 +106,7 @@ class ExternalProfilePolicy * @param ExternalProfile $profile * @return bool */ - public function restore(User $user, ExternalProfile $profile): bool + public function restore(User $user, BaseModel|Model $profile): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole('Admin'); @@ -115,17 +115,6 @@ class ExternalProfilePolicy return $profile->trashed() && $user->getKey() === $profile->user_id && $user->can(ExtendedCrudPermission::RESTORE->format(ExternalProfile::class)); } - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(ExternalProfile::class)); - } - /** * Determine whether the user can add a entry to the profile. * diff --git a/app/Policies/List/Playlist/PlaylistTrackPolicy.php b/app/Policies/List/Playlist/PlaylistTrackPolicy.php index a3c86ca77..cd85874bd 100644 --- a/app/Policies/List/Playlist/PlaylistTrackPolicy.php +++ b/app/Policies/List/Playlist/PlaylistTrackPolicy.php @@ -9,18 +9,18 @@ use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\Role as RoleEnum; use App\Enums\Models\List\PlaylistVisibility; use App\Models\Auth\User; +use App\Models\BaseModel; use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; +use App\Policies\BasePolicy; use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Database\Eloquent\Model; /** * Class TrackPolicy. */ -class PlaylistTrackPolicy +class PlaylistTrackPolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * @@ -50,7 +50,7 @@ class PlaylistTrackPolicy * * @noinspection PhpUnusedParameterInspection */ - public function view(?User $user, PlaylistTrack $track): bool + public function view(?User $user, BaseModel|Model $track): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); @@ -91,7 +91,7 @@ class PlaylistTrackPolicy * * @noinspection PhpUnusedParameterInspection */ - public function update(User $user, PlaylistTrack $track): bool + public function update(User $user, BaseModel|Model $track): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); @@ -112,7 +112,7 @@ class PlaylistTrackPolicy * * @noinspection PhpUnusedParameterInspection */ - public function delete(User $user, PlaylistTrack $track): bool + public function delete(User $user, BaseModel|Model $track): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); @@ -133,7 +133,7 @@ class PlaylistTrackPolicy * * @noinspection PhpUnusedParameterInspection */ - public function restore(User $user, PlaylistTrack $track): bool + public function restore(User $user, BaseModel|Model $track): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); @@ -144,15 +144,4 @@ class PlaylistTrackPolicy return $track->trashed() && $user->getKey() === $playlist?->user_id && $user->can(ExtendedCrudPermission::RESTORE->format(PlaylistTrack::class)); } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(PlaylistTrack::class)); - } } diff --git a/app/Policies/List/PlaylistPolicy.php b/app/Policies/List/PlaylistPolicy.php index 6aca91251..89d164f5c 100644 --- a/app/Policies/List/PlaylistPolicy.php +++ b/app/Policies/List/PlaylistPolicy.php @@ -9,19 +9,19 @@ use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\Role as RoleEnum; use App\Enums\Models\List\PlaylistVisibility; use App\Models\Auth\User; +use App\Models\BaseModel; use App\Models\List\Playlist; use App\Models\Wiki\Image; use App\Pivots\List\PlaylistImage; +use App\Policies\BasePolicy; use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Database\Eloquent\Model; /** * Class PlaylistPolicy. */ -class PlaylistPolicy +class PlaylistPolicy extends BasePolicy { - use HandlesAuthorization; - /** * Determine whether the user can view any models. * @@ -44,7 +44,7 @@ class PlaylistPolicy * @param Playlist $playlist * @return bool */ - public function view(?User $user, Playlist $playlist): bool + public function view(?User $user, BaseModel|Model $playlist): bool { if (Filament::isServing()) { return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); @@ -77,7 +77,7 @@ class PlaylistPolicy * @param Playlist $playlist * @return bool */ - public function update(User $user, Playlist $playlist): bool + public function update(User $user, BaseModel|Model $playlist): bool { if (Filament::isServing()) { return $user->hasRole(RoleEnum::ADMIN->value); @@ -93,7 +93,7 @@ class PlaylistPolicy * @param Playlist $playlist * @return bool */ - public function delete(User $user, Playlist $playlist): bool + public function delete(User $user, BaseModel|Model $playlist): bool { if (Filament::isServing()) { return $user->hasRole(RoleEnum::ADMIN->value); @@ -109,7 +109,7 @@ class PlaylistPolicy * @param Playlist $playlist * @return bool */ - public function restore(User $user, Playlist $playlist): bool + public function restore(User $user, BaseModel|Model $playlist): bool { if (Filament::isServing()) { return $user->hasRole(RoleEnum::ADMIN->value); @@ -118,17 +118,6 @@ class PlaylistPolicy return $playlist->trashed() && $user->getKey() === $playlist->user_id && $user->can(ExtendedCrudPermission::RESTORE->format(Playlist::class)); } - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Playlist::class)); - } - /** * Determine whether the user can add a track to the playlist. * diff --git a/app/Policies/Wiki/Anime/AnimeSynonymPolicy.php b/app/Policies/Wiki/Anime/AnimeSynonymPolicy.php index a764671d3..fc82a523d 100644 --- a/app/Policies/Wiki/Anime/AnimeSynonymPolicy.php +++ b/app/Policies/Wiki/Anime/AnimeSynonymPolicy.php @@ -4,116 +4,11 @@ declare(strict_types=1); namespace App\Policies\Wiki\Anime; -use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; -use App\Models\Auth\User; -use App\Models\Wiki\Anime\AnimeSynonym; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class AnimeSynonymPolicy. */ -class AnimeSynonymPolicy +class AnimeSynonymPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(AnimeSynonym::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(AnimeSynonym::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(AnimeSynonym::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param AnimeSynonym $animesynonym - * @return bool - */ - public function update(User $user, AnimeSynonym $animesynonym): bool - { - return !$animesynonym->trashed() && $user->can(CrudPermission::UPDATE->format(AnimeSynonym::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param AnimeSynonym $animesynonym - * @return bool - */ - public function delete(User $user, AnimeSynonym $animesynonym): bool - { - return !$animesynonym->trashed() && $user->can(CrudPermission::DELETE->format(AnimeSynonym::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param AnimeSynonym $animesynonym - * @return bool - */ - public function restore(User $user, AnimeSynonym $animesynonym): bool - { - return $animesynonym->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(AnimeSynonym::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(AnimeSynonym::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(AnimeSynonym::class)); - } } diff --git a/app/Policies/Wiki/Anime/AnimeThemePolicy.php b/app/Policies/Wiki/Anime/AnimeThemePolicy.php index cc463986d..b20f914bd 100644 --- a/app/Policies/Wiki/Anime/AnimeThemePolicy.php +++ b/app/Policies/Wiki/Anime/AnimeThemePolicy.php @@ -4,116 +4,11 @@ declare(strict_types=1); namespace App\Policies\Wiki\Anime; -use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; -use App\Models\Auth\User; -use App\Models\Wiki\Anime\AnimeTheme; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class AnimeThemePolicy. */ -class AnimeThemePolicy +class AnimeThemePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(AnimeTheme::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(AnimeTheme::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(AnimeTheme::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param AnimeTheme $animetheme - * @return bool - */ - public function update(User $user, AnimeTheme $animetheme): bool - { - return !$animetheme->trashed() && $user->can(CrudPermission::UPDATE->format(AnimeTheme::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param AnimeTheme $animetheme - * @return bool - */ - public function delete(User $user, AnimeTheme $animetheme): bool - { - return !$animetheme->trashed() && $user->can(CrudPermission::DELETE->format(AnimeTheme::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param AnimeTheme $animetheme - * @return bool - */ - public function restore(User $user, AnimeTheme $animetheme): bool - { - return $animetheme->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(AnimeTheme::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(AnimeTheme::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(AnimeTheme::class)); - } } diff --git a/app/Policies/Wiki/Anime/Theme/AnimeThemeEntryPolicy.php b/app/Policies/Wiki/Anime/Theme/AnimeThemeEntryPolicy.php index 8ed5a7e56..dd482e3f7 100644 --- a/app/Policies/Wiki/Anime/Theme/AnimeThemeEntryPolicy.php +++ b/app/Policies/Wiki/Anime/Theme/AnimeThemeEntryPolicy.php @@ -5,120 +5,17 @@ declare(strict_types=1); namespace App\Policies\Wiki\Anime\Theme; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Anime\Theme\AnimeThemeEntry; use App\Models\Wiki\Video; use App\Pivots\Wiki\AnimeThemeEntryVideo; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class AnimeThemeEntryPolicy. */ -class AnimeThemeEntryPolicy +class AnimeThemeEntryPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(AnimeThemeEntry::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(AnimeThemeEntry::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(AnimeThemeEntry::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param AnimeThemeEntry $animethemeentry - * @return bool - */ - public function update(User $user, AnimeThemeEntry $animethemeentry): bool - { - return !$animethemeentry->trashed() && $user->can(CrudPermission::UPDATE->format(AnimeThemeEntry::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param AnimeThemeEntry $animethemeentry - * @return bool - */ - public function delete(User $user, AnimeThemeEntry $animethemeentry): bool - { - return !$animethemeentry->trashed() && $user->can(CrudPermission::DELETE->format(AnimeThemeEntry::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param AnimeThemeEntry $animethemeentry - * @return bool - */ - public function restore(User $user, AnimeThemeEntry $animethemeentry): bool - { - return $animethemeentry->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(AnimeThemeEntry::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(AnimeThemeEntry::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(AnimeThemeEntry::class)); - } - /** * Determine whether the user can attach any video to the entry. * diff --git a/app/Policies/Wiki/AnimePolicy.php b/app/Policies/Wiki/AnimePolicy.php index 2e126ed56..df1a9132a 100644 --- a/app/Policies/Wiki/AnimePolicy.php +++ b/app/Policies/Wiki/AnimePolicy.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Anime; use App\Models\Wiki\Image; @@ -14,115 +13,13 @@ use App\Models\Wiki\Studio; use App\Pivots\Wiki\AnimeImage; use App\Pivots\Wiki\AnimeSeries; use App\Pivots\Wiki\AnimeStudio; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class AnimePolicy. */ -class AnimePolicy +class AnimePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Anime::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Anime::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Anime::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Anime $anime - * @return bool - */ - public function update(User $user, Anime $anime): bool - { - return !$anime->trashed() && $user->can(CrudPermission::UPDATE->format(Anime::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Anime $anime - * @return bool - */ - public function delete(User $user, Anime $anime): bool - { - return !$anime->trashed() && $user->can(CrudPermission::DELETE->format(Anime::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Anime $anime - * @return bool - */ - public function restore(User $user, Anime $anime): bool - { - return $anime->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Anime::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Anime::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Anime::class)); - } - /** * Determine whether the user can attach any series to the anime. * diff --git a/app/Policies/Wiki/ArtistPolicy.php b/app/Policies/Wiki/ArtistPolicy.php index b6dd126c0..b377f7e5f 100644 --- a/app/Policies/Wiki/ArtistPolicy.php +++ b/app/Policies/Wiki/ArtistPolicy.php @@ -5,120 +5,17 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Artist; use App\Models\Wiki\Image; use App\Pivots\Wiki\ArtistImage; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class ArtistPolicy. */ -class ArtistPolicy +class ArtistPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Artist::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Artist::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Artist::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Artist $artist - * @return bool - */ - public function update(User $user, Artist $artist): bool - { - return !$artist->trashed() && $user->can(CrudPermission::UPDATE->format(Artist::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Artist $artist - * @return bool - */ - public function delete(User $user, Artist $artist): bool - { - return !$artist->trashed() && $user->can(CrudPermission::DELETE->format(Artist::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Artist $artist - * @return bool - */ - public function restore(User $user, Artist $artist): bool - { - return $artist->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Artist::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Artist::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Artist::class)); - } - /** * Determine whether the user can attach any resource to the artist. * diff --git a/app/Policies/Wiki/AudioPolicy.php b/app/Policies/Wiki/AudioPolicy.php index 531a8aa32..7d9c1fdb7 100644 --- a/app/Policies/Wiki/AudioPolicy.php +++ b/app/Policies/Wiki/AudioPolicy.php @@ -5,118 +5,15 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Audio; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class AudioPolicy. */ -class AudioPolicy +class AudioPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Audio::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Audio::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Audio::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Audio $audio - * @return bool - */ - public function update(User $user, Audio $audio): bool - { - return !$audio->trashed() && $user->can(CrudPermission::UPDATE->format(Audio::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Audio $audio - * @return bool - */ - public function delete(User $user, Audio $audio): bool - { - return !$audio->trashed() && $user->can(CrudPermission::DELETE->format(Audio::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Audio $audio - * @return bool - */ - public function restore(User $user, Audio $audio): bool - { - return $audio->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Audio::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Audio::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Audio::class)); - } - /** * Determine whether the user can add a video to the audio. * diff --git a/app/Policies/Wiki/ExternalResourcePolicy.php b/app/Policies/Wiki/ExternalResourcePolicy.php index c7c0583ed..c86650bce 100644 --- a/app/Policies/Wiki/ExternalResourcePolicy.php +++ b/app/Policies/Wiki/ExternalResourcePolicy.php @@ -5,118 +5,15 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\ExternalResource; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class ExternalResourcePolicy. */ -class ExternalResourcePolicy +class ExternalResourcePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(ExternalResource::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(ExternalResource::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(ExternalResource::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param ExternalResource $resource - * @return bool - */ - public function update(User $user, ExternalResource $resource): bool - { - return !$resource->trashed() && $user->can(CrudPermission::UPDATE->format(ExternalResource::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param ExternalResource $resource - * @return bool - */ - public function delete(User $user, ExternalResource $resource): bool - { - return !$resource->trashed() && $user->can(CrudPermission::DELETE->format(ExternalResource::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param ExternalResource $resource - * @return bool - */ - public function restore(User $user, ExternalResource $resource): bool - { - return $resource->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(ExternalResource::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(ExternalResource::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(ExternalResource::class)); - } - /** * Determine whether the user can attach any artist to the resource. * diff --git a/app/Policies/Wiki/GroupPolicy.php b/app/Policies/Wiki/GroupPolicy.php index dd629e094..64b7df85f 100644 --- a/app/Policies/Wiki/GroupPolicy.php +++ b/app/Policies/Wiki/GroupPolicy.php @@ -5,107 +5,15 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Group; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class GroupPolicy. */ -class GroupPolicy +class GroupPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Group::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Group::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Group::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Group $group - * @return bool - */ - public function update(User $user, Group $group): bool - { - return !$group->trashed() && $user->can(CrudPermission::UPDATE->format(Group::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Group $group - * @return bool - */ - public function delete(User $user, Group $group): bool - { - return !$group->trashed() && $user->can(CrudPermission::DELETE->format(Group::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Group $group - * @return bool - */ - public function restore(User $user, Group $group): bool - { - return $group->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Group::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Group::class)); - } - /** * Determine whether the user can add a theme to the group. * diff --git a/app/Policies/Wiki/ImagePolicy.php b/app/Policies/Wiki/ImagePolicy.php index a8ff541f4..4460bf8ec 100644 --- a/app/Policies/Wiki/ImagePolicy.php +++ b/app/Policies/Wiki/ImagePolicy.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\Role as RoleEnum; use App\Models\Auth\User; use App\Models\List\Playlist; @@ -17,115 +16,13 @@ use App\Pivots\List\PlaylistImage; use App\Pivots\Wiki\AnimeImage; use App\Pivots\Wiki\ArtistImage; use App\Pivots\Wiki\StudioImage; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class ImagePolicy. */ -class ImagePolicy +class ImagePolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Image::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Image::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Image::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Image $image - * @return bool - */ - public function update(User $user, Image $image): bool - { - return !$image->trashed() && $user->can(CrudPermission::UPDATE->format(Image::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Image $image - * @return bool - */ - public function delete(User $user, Image $image): bool - { - return !$image->trashed() && $user->can(CrudPermission::DELETE->format(Image::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Image $image - * @return bool - */ - public function restore(User $user, Image $image): bool - { - return $image->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Image::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Image::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Image::class)); - } - /** * Determine whether the user can attach any artist to the image. * diff --git a/app/Policies/Wiki/SeriesPolicy.php b/app/Policies/Wiki/SeriesPolicy.php index 053c7d70d..18930f427 100644 --- a/app/Policies/Wiki/SeriesPolicy.php +++ b/app/Policies/Wiki/SeriesPolicy.php @@ -5,120 +5,17 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Anime; use App\Models\Wiki\Series; use App\Pivots\Wiki\AnimeSeries; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class SeriesPolicy. */ -class SeriesPolicy +class SeriesPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Series::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Series::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Series::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Series $series - * @return bool - */ - public function update(User $user, Series $series): bool - { - return !$series->trashed() && $user->can(CrudPermission::UPDATE->format(Series::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Series $series - * @return bool - */ - public function delete(User $user, Series $series): bool - { - return !$series->trashed() && $user->can(CrudPermission::DELETE->format(Series::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Series $series - * @return bool - */ - public function restore(User $user, Series $series): bool - { - return $series->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Series::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Series::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Series::class)); - } - /** * Determine whether the user can attach any anime to the series. * diff --git a/app/Policies/Wiki/SongPolicy.php b/app/Policies/Wiki/SongPolicy.php index c8721f535..60193b400 100644 --- a/app/Policies/Wiki/SongPolicy.php +++ b/app/Policies/Wiki/SongPolicy.php @@ -5,118 +5,15 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Song; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class SongPolicy. */ -class SongPolicy +class SongPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Song::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Song::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Song::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Song $song - * @return bool - */ - public function update(User $user, Song $song): bool - { - return !$song->trashed() && $user->can(CrudPermission::UPDATE->format(Song::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Song $song - * @return bool - */ - public function delete(User $user, Song $song): bool - { - return !$song->trashed() && $user->can(CrudPermission::DELETE->format(Song::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Song $song - * @return bool - */ - public function restore(User $user, Song $song): bool - { - return $song->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Song::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Song::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Song::class)); - } - /** * Determine whether the user can add a theme to the song. * diff --git a/app/Policies/Wiki/StudioPolicy.php b/app/Policies/Wiki/StudioPolicy.php index c20aa047d..4642bf98b 100644 --- a/app/Policies/Wiki/StudioPolicy.php +++ b/app/Policies/Wiki/StudioPolicy.php @@ -5,122 +5,19 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Models\Auth\User; use App\Models\Wiki\Anime; use App\Models\Wiki\Image; use App\Models\Wiki\Studio; use App\Pivots\Wiki\AnimeStudio; use App\Pivots\Wiki\StudioImage; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class StudioPolicy. */ -class StudioPolicy +class StudioPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Studio::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Studio::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Studio::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Studio $studio - * @return bool - */ - public function update(User $user, Studio $studio): bool - { - return !$studio->trashed() && $user->can(CrudPermission::UPDATE->format(Studio::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Studio $studio - * @return bool - */ - public function delete(User $user, Studio $studio): bool - { - return !$studio->trashed() && $user->can(CrudPermission::DELETE->format(Studio::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Studio $studio - * @return bool - */ - public function restore(User $user, Studio $studio): bool - { - return $studio->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Studio::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Studio::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Studio::class)); - } - /** * Determine whether the user can attach any anime to the studio. * diff --git a/app/Policies/Wiki/Video/VideoScriptPolicy.php b/app/Policies/Wiki/Video/VideoScriptPolicy.php index f02ce4202..08c87bfe4 100644 --- a/app/Policies/Wiki/Video/VideoScriptPolicy.php +++ b/app/Policies/Wiki/Video/VideoScriptPolicy.php @@ -4,116 +4,11 @@ declare(strict_types=1); namespace App\Policies\Wiki\Video; -use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; -use App\Models\Auth\User; -use App\Models\Wiki\Video\VideoScript; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class VideoScriptPolicy. */ -class VideoScriptPolicy +class VideoScriptPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(VideoScript::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(VideoScript::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(VideoScript::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param VideoScript $videoscript - * @return bool - */ - public function update(User $user, VideoScript $videoscript): bool - { - return !$videoscript->trashed() && $user->can(CrudPermission::UPDATE->format(VideoScript::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param VideoScript $videoscript - * @return bool - */ - public function delete(User $user, VideoScript $videoscript): bool - { - return !$videoscript->trashed() && $user->can(CrudPermission::DELETE->format(VideoScript::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param VideoScript $videoscript - * @return bool - */ - public function restore(User $user, VideoScript $videoscript): bool - { - return $videoscript->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(VideoScript::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(VideoScript::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(VideoScript::class)); - } } diff --git a/app/Policies/Wiki/VideoPolicy.php b/app/Policies/Wiki/VideoPolicy.php index 87733f71e..b0f8c808d 100644 --- a/app/Policies/Wiki/VideoPolicy.php +++ b/app/Policies/Wiki/VideoPolicy.php @@ -5,119 +5,16 @@ declare(strict_types=1); namespace App\Policies\Wiki; use App\Enums\Auth\CrudPermission; -use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\Role as RoleEnum; use App\Models\Auth\User; use App\Models\Wiki\Video; -use Filament\Facades\Filament; -use Illuminate\Auth\Access\HandlesAuthorization; +use App\Policies\BasePolicy; /** * Class VideoPolicy. */ -class VideoPolicy +class VideoPolicy extends BasePolicy { - use HandlesAuthorization; - - /** - * Determine whether the user can view any models. - * - * @param User|null $user - * @return bool - */ - public function viewAny(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Video::class)); - } - - return true; - } - - /** - * Determine whether the user can view the model. - * - * @param User|null $user - * @return bool - */ - public function view(?User $user): bool - { - if (Filament::isServing()) { - return $user !== null && $user->can(CrudPermission::VIEW->format(Video::class)); - } - - return true; - } - - /** - * Determine whether the user can create models. - * - * @param User $user - * @return bool - */ - public function create(User $user): bool - { - return $user->can(CrudPermission::CREATE->format(Video::class)); - } - - /** - * Determine whether the user can update the model. - * - * @param User $user - * @param Video $video - * @return bool - */ - public function update(User $user, Video $video): bool - { - return !$video->trashed() && $user->can(CrudPermission::UPDATE->format(Video::class)); - } - - /** - * Determine whether the user can delete the model. - * - * @param User $user - * @param Video $video - * @return bool - */ - public function delete(User $user, Video $video): bool - { - return !$video->trashed() && $user->can(CrudPermission::DELETE->format(Video::class)); - } - - /** - * Determine whether the user can restore the model. - * - * @param User $user - * @param Video $video - * @return bool - */ - public function restore(User $user, Video $video): bool - { - return $video->trashed() && $user->can(ExtendedCrudPermission::RESTORE->format(Video::class)); - } - - /** - * Determine whether the user can permanently delete the model. - * - * @param User $user - * @return bool - */ - public function forceDelete(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Video::class)); - } - - /** - * Determine whether the user can permanently delete any model. - * - * @param User $user - * @return bool - */ - public function forceDeleteAny(User $user): bool - { - return $user->can(ExtendedCrudPermission::FORCE_DELETE->format(Video::class)); - } - /** * Determine whether the user can attach any entry to a video. * diff --git a/app/Providers/FilamentPanelProvider.php b/app/Providers/FilamentPanelProvider.php index d68caede5..f1467df06 100644 --- a/app/Providers/FilamentPanelProvider.php +++ b/app/Providers/FilamentPanelProvider.php @@ -22,6 +22,9 @@ use Illuminate\Support\Facades\Config; use Illuminate\View\Middleware\ShareErrorsFromSession; use Leandrocfe\FilamentApexCharts\FilamentApexChartsPlugin; +/** + * Class FilamentPanelProvider. + */ class FilamentPanelProvider extends PanelProvider { public function panel(Panel $panel): Panel diff --git a/composer.json b/composer.json index 334ebab30..810ae75e2 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "babenkoivan/elastic-migrations": "^3.3", "babenkoivan/elastic-scout-driver-plus": "^4.3", "bepsvpt/secure-headers": "^7.4", + "bezhansalleh/filament-exceptions": "^2.1", "cyrildewit/eloquent-viewable": "^7.0", "fakerphp/faker": "^1.21", "filament/filament": "3.2", diff --git a/composer.lock b/composer.lock index faf2aa93a..30a35d3ae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c7d34b5fdbb2830f142160c61242e4c7", + "content-hash": "afa45066fd7c02b838003727586a268f", "packages": [ { "name": "anourvalar/eloquent-serialize", @@ -715,6 +715,83 @@ ], "time": "2023-02-06T13:24:48+00:00" }, + { + "name": "bezhansalleh/filament-exceptions", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/bezhanSalleh/filament-exceptions.git", + "reference": "14a9be86fbb88087f2ae9167289d1fbcf0024db2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bezhanSalleh/filament-exceptions/zipball/14a9be86fbb88087f2ae9167289d1fbcf0024db2", + "reference": "14a9be86fbb88087f2ae9167289d1fbcf0024db2", + "shasum": "" + }, + "require": { + "filament/filament": "^3.0", + "php": "^8.1|^8.2", + "spatie/laravel-ignition": "^2.0", + "spatie/laravel-package-tools": "^1.9" + }, + "require-dev": { + "larastan/larastan": "^2.0", + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.0", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.9", + "phpunit/phpunit": "^10.0", + "spatie/laravel-ray": "^1.26" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "BezhanSalleh\\FilamentExceptions\\FilamentExceptionsServiceProvider" + ], + "aliases": { + "FilamentExceptions": "BezhanSalleh\\FilamentExceptions\\Facades\\FilamentExceptions" + } + } + }, + "autoload": { + "psr-4": { + "BezhanSalleh\\FilamentExceptions\\": "src", + "BezhanSalleh\\FilamentExceptions\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bezhan Salleh", + "email": "bezhan_salleh@yahoo.com", + "role": "Developer" + } + ], + "description": "A Simple & Beautiful Pluggable Exception Viewer for FilamentPHP's Admin Panel", + "homepage": "https://github.com/bezhansalleh/filament-exceptions", + "keywords": [ + "bezhanSalleh", + "filament-exception-viewer", + "filament-exceptions", + "laravel" + ], + "support": { + "issues": "https://github.com/bezhanSalleh/filament-exceptions/issues", + "source": "https://github.com/bezhanSalleh/filament-exceptions/tree/2.1.1" + }, + "funding": [ + { + "url": "https://github.com/bezhanSalleh", + "type": "github" + } + ], + "time": "2024-01-25T16:42:20+00:00" + }, { "name": "blade-ui-kit/blade-heroicons", "version": "2.3.0", @@ -7255,6 +7332,68 @@ ], "time": "2023-02-14T16:54:54+00:00" }, + { + "name": "spatie/backtrace", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/backtrace.git", + "reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/backtrace/zipball/ec4dd16476b802dbdc6b4467f84032837e316b8c", + "reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0" + }, + "require-dev": { + "ext-json": "*", + "phpunit/phpunit": "^9.3", + "spatie/phpunit-snapshot-assertions": "^4.2", + "symfony/var-dumper": "^5.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Backtrace\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van de Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A better backtrace", + "homepage": "https://github.com/spatie/backtrace", + "keywords": [ + "Backtrace", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/backtrace/tree/1.4.0" + }, + "funding": [ + { + "url": "https://github.com/sponsors/spatie", + "type": "github" + }, + { + "url": "https://spatie.be/open-source/support-us", + "type": "other" + } + ], + "time": "2023-03-04T08:57:24+00:00" + }, { "name": "spatie/color", "version": "1.5.3", @@ -7377,6 +7516,158 @@ ], "time": "2023-05-02T11:05:31+00:00" }, + { + "name": "spatie/flare-client-php", + "version": "1.3.6", + "source": { + "type": "git", + "url": "https://github.com/spatie/flare-client-php.git", + "reference": "530ac81255af79f114344286e4275f8869c671e2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/530ac81255af79f114344286e4275f8869c671e2", + "reference": "530ac81255af79f114344286e4275f8869c671e2", + "shasum": "" + }, + "require": { + "illuminate/pipeline": "^8.0|^9.0|^10.0", + "php": "^8.0", + "spatie/backtrace": "^1.2", + "symfony/http-foundation": "^5.0|^6.0", + "symfony/mime": "^5.2|^6.0", + "symfony/process": "^5.2|^6.0", + "symfony/var-dumper": "^5.2|^6.0" + }, + "require-dev": { + "dms/phpunit-arraysubset-asserts": "^0.3.0", + "pestphp/pest": "^1.20", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "spatie/phpunit-snapshot-assertions": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.1.x-dev" + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\FlareClient\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Send PHP errors to Flare", + "homepage": "https://github.com/spatie/flare-client-php", + "keywords": [ + "exception", + "flare", + "reporting", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/flare-client-php/issues", + "source": "https://github.com/spatie/flare-client-php/tree/1.3.6" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-04-12T07:57:12+00:00" + }, + { + "name": "spatie/ignition", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/ignition.git", + "reference": "d8eb8ea1ed27f48a694405cff363746ffd37f13e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/ignition/zipball/d8eb8ea1ed27f48a694405cff363746ffd37f13e", + "reference": "d8eb8ea1ed27f48a694405cff363746ffd37f13e", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "php": "^8.0", + "spatie/backtrace": "^1.4", + "spatie/flare-client-php": "^1.1", + "symfony/console": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0" + }, + "require-dev": { + "illuminate/cache": "^9.52", + "mockery/mockery": "^1.4", + "pestphp/pest": "^1.20", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "psr/simple-cache-implementation": "*", + "symfony/cache": "^6.2", + "symfony/process": "^5.4|^6.0", + "vlucas/phpdotenv": "^5.5" + }, + "suggest": { + "openai-php/client": "Require get solutions from OpenAI", + "simple-cache-implementation": "To cache solutions from OpenAI" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Spatie\\Ignition\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Spatie", + "email": "info@spatie.be", + "role": "Developer" + } + ], + "description": "A beautiful error page for PHP applications.", + "homepage": "https://flareapp.io/ignition", + "keywords": [ + "error", + "flare", + "laravel", + "page" + ], + "support": { + "docs": "https://flareapp.io/docs/ignition-for-laravel/introduction", + "forum": "https://twitter.com/flareappio", + "issues": "https://github.com/spatie/ignition/issues", + "source": "https://github.com/spatie/ignition" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-06-06T14:14:58+00:00" + }, { "name": "spatie/invade", "version": "2.0.0", @@ -7436,6 +7727,98 @@ ], "time": "2023-07-19T18:55:36+00:00" }, + { + "name": "spatie/laravel-ignition", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-ignition.git", + "reference": "35711943d4725aa80f8033e4f1cb3a6775530b25" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/35711943d4725aa80f8033e4f1cb3a6775530b25", + "reference": "35711943d4725aa80f8033e4f1cb3a6775530b25", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "illuminate/support": "^10.0", + "php": "^8.1", + "spatie/flare-client-php": "^1.3.5", + "spatie/ignition": "^1.5.0", + "symfony/console": "^6.2.3", + "symfony/var-dumper": "^6.2.3" + }, + "require-dev": { + "livewire/livewire": "^2.11", + "mockery/mockery": "^1.5.1", + "openai-php/client": "^0.3.4", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^1.22.3", + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan-deprecation-rules": "^1.1.1", + "phpstan/phpstan-phpunit": "^1.3.3", + "vlucas/phpdotenv": "^5.5" + }, + "suggest": { + "openai-php/client": "Require get solutions from OpenAI", + "psr/simple-cache-implementation": "Needed to cache solutions from OpenAI" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\LaravelIgnition\\IgnitionServiceProvider" + ], + "aliases": { + "Flare": "Spatie\\LaravelIgnition\\Facades\\Flare" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\LaravelIgnition\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Spatie", + "email": "info@spatie.be", + "role": "Developer" + } + ], + "description": "A beautiful error page for Laravel applications.", + "homepage": "https://flareapp.io/ignition", + "keywords": [ + "error", + "flare", + "laravel", + "page" + ], + "support": { + "docs": "https://flareapp.io/docs/ignition-for-laravel/introduction", + "forum": "https://twitter.com/flareappio", + "issues": "https://github.com/spatie/laravel-ignition/issues", + "source": "https://github.com/spatie/laravel-ignition" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-05-25T11:30:27+00:00" + }, { "name": "spatie/laravel-package-tools", "version": "1.16.4", @@ -13163,312 +13546,6 @@ ], "time": "2023-02-07T11:34:05+00:00" }, - { - "name": "spatie/backtrace", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/spatie/backtrace.git", - "reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/backtrace/zipball/ec4dd16476b802dbdc6b4467f84032837e316b8c", - "reference": "ec4dd16476b802dbdc6b4467f84032837e316b8c", - "shasum": "" - }, - "require": { - "php": "^7.3|^8.0" - }, - "require-dev": { - "ext-json": "*", - "phpunit/phpunit": "^9.3", - "spatie/phpunit-snapshot-assertions": "^4.2", - "symfony/var-dumper": "^5.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "Spatie\\Backtrace\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Freek Van de Herten", - "email": "freek@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - } - ], - "description": "A better backtrace", - "homepage": "https://github.com/spatie/backtrace", - "keywords": [ - "Backtrace", - "spatie" - ], - "support": { - "source": "https://github.com/spatie/backtrace/tree/1.4.0" - }, - "funding": [ - { - "url": "https://github.com/sponsors/spatie", - "type": "github" - }, - { - "url": "https://spatie.be/open-source/support-us", - "type": "other" - } - ], - "time": "2023-03-04T08:57:24+00:00" - }, - { - "name": "spatie/flare-client-php", - "version": "1.3.6", - "source": { - "type": "git", - "url": "https://github.com/spatie/flare-client-php.git", - "reference": "530ac81255af79f114344286e4275f8869c671e2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/530ac81255af79f114344286e4275f8869c671e2", - "reference": "530ac81255af79f114344286e4275f8869c671e2", - "shasum": "" - }, - "require": { - "illuminate/pipeline": "^8.0|^9.0|^10.0", - "php": "^8.0", - "spatie/backtrace": "^1.2", - "symfony/http-foundation": "^5.0|^6.0", - "symfony/mime": "^5.2|^6.0", - "symfony/process": "^5.2|^6.0", - "symfony/var-dumper": "^5.2|^6.0" - }, - "require-dev": { - "dms/phpunit-arraysubset-asserts": "^0.3.0", - "pestphp/pest": "^1.20", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "spatie/phpunit-snapshot-assertions": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.1.x-dev" - } - }, - "autoload": { - "files": [ - "src/helpers.php" - ], - "psr-4": { - "Spatie\\FlareClient\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Send PHP errors to Flare", - "homepage": "https://github.com/spatie/flare-client-php", - "keywords": [ - "exception", - "flare", - "reporting", - "spatie" - ], - "support": { - "issues": "https://github.com/spatie/flare-client-php/issues", - "source": "https://github.com/spatie/flare-client-php/tree/1.3.6" - }, - "funding": [ - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2023-04-12T07:57:12+00:00" - }, - { - "name": "spatie/ignition", - "version": "1.8.1", - "source": { - "type": "git", - "url": "https://github.com/spatie/ignition.git", - "reference": "d8eb8ea1ed27f48a694405cff363746ffd37f13e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/ignition/zipball/d8eb8ea1ed27f48a694405cff363746ffd37f13e", - "reference": "d8eb8ea1ed27f48a694405cff363746ffd37f13e", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-mbstring": "*", - "php": "^8.0", - "spatie/backtrace": "^1.4", - "spatie/flare-client-php": "^1.1", - "symfony/console": "^5.4|^6.0", - "symfony/var-dumper": "^5.4|^6.0" - }, - "require-dev": { - "illuminate/cache": "^9.52", - "mockery/mockery": "^1.4", - "pestphp/pest": "^1.20", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "psr/simple-cache-implementation": "*", - "symfony/cache": "^6.2", - "symfony/process": "^5.4|^6.0", - "vlucas/phpdotenv": "^5.5" - }, - "suggest": { - "openai-php/client": "Require get solutions from OpenAI", - "simple-cache-implementation": "To cache solutions from OpenAI" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.5.x-dev" - } - }, - "autoload": { - "psr-4": { - "Spatie\\Ignition\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Spatie", - "email": "info@spatie.be", - "role": "Developer" - } - ], - "description": "A beautiful error page for PHP applications.", - "homepage": "https://flareapp.io/ignition", - "keywords": [ - "error", - "flare", - "laravel", - "page" - ], - "support": { - "docs": "https://flareapp.io/docs/ignition-for-laravel/introduction", - "forum": "https://twitter.com/flareappio", - "issues": "https://github.com/spatie/ignition/issues", - "source": "https://github.com/spatie/ignition" - }, - "funding": [ - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2023-06-06T14:14:58+00:00" - }, - { - "name": "spatie/laravel-ignition", - "version": "2.1.3", - "source": { - "type": "git", - "url": "https://github.com/spatie/laravel-ignition.git", - "reference": "35711943d4725aa80f8033e4f1cb3a6775530b25" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/35711943d4725aa80f8033e4f1cb3a6775530b25", - "reference": "35711943d4725aa80f8033e4f1cb3a6775530b25", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "illuminate/support": "^10.0", - "php": "^8.1", - "spatie/flare-client-php": "^1.3.5", - "spatie/ignition": "^1.5.0", - "symfony/console": "^6.2.3", - "symfony/var-dumper": "^6.2.3" - }, - "require-dev": { - "livewire/livewire": "^2.11", - "mockery/mockery": "^1.5.1", - "openai-php/client": "^0.3.4", - "orchestra/testbench": "^8.0", - "pestphp/pest": "^1.22.3", - "phpstan/extension-installer": "^1.2", - "phpstan/phpstan-deprecation-rules": "^1.1.1", - "phpstan/phpstan-phpunit": "^1.3.3", - "vlucas/phpdotenv": "^5.5" - }, - "suggest": { - "openai-php/client": "Require get solutions from OpenAI", - "psr/simple-cache-implementation": "Needed to cache solutions from OpenAI" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Spatie\\LaravelIgnition\\IgnitionServiceProvider" - ], - "aliases": { - "Flare": "Spatie\\LaravelIgnition\\Facades\\Flare" - } - } - }, - "autoload": { - "files": [ - "src/helpers.php" - ], - "psr-4": { - "Spatie\\LaravelIgnition\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Spatie", - "email": "info@spatie.be", - "role": "Developer" - } - ], - "description": "A beautiful error page for Laravel applications.", - "homepage": "https://flareapp.io/ignition", - "keywords": [ - "error", - "flare", - "laravel", - "page" - ], - "support": { - "docs": "https://flareapp.io/docs/ignition-for-laravel/introduction", - "forum": "https://twitter.com/flareappio", - "issues": "https://github.com/spatie/laravel-ignition/issues", - "source": "https://github.com/spatie/laravel-ignition" - }, - "funding": [ - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2023-05-25T11:30:27+00:00" - }, { "name": "symfony/yaml", "version": "v6.4.3", diff --git a/config/filament-exceptions.php b/config/filament-exceptions.php new file mode 100644 index 000000000..59f1f2cb6 --- /dev/null +++ b/config/filament-exceptions.php @@ -0,0 +1,61 @@ + Exception::class, + + 'slug' => 'exceptions', + + /** Show or hide in navigation/sidebar */ + 'navigation_enabled' => false, + + /** Sort order, if shown. No effect, if navigation_enabled it set to false. */ + 'navigation_sort' => -1, + + /** Whether to show a navigation badge. No effect, if navigation_enabled it set to false. */ + 'navigation_badge' => true, + + /** Whether to scope exceptions to tenant */ + 'is_scoped_to_tenant' => true, + + /** Icons to use for navigation (if enabled) and pills */ + 'icons' => [ + 'navigation' => 'heroicon-o-cpu-chip', + 'exception' => 'heroicon-o-cpu-chip', + 'headers' => 'heroicon-o-arrows-right-left', + 'cookies' => 'heroicon-o-circle-stack', + 'body' => 'heroicon-s-code-bracket', + 'queries' => 'heroicon-s-circle-stack', + ], + + 'is_globally_searchable' => false, + + /**------------------------------------------------- + * Change the default active tab + * + * Exception => 1 (Default) + * Headers => 2 + * Cookies => 3 + * Body => 4 + * Queries => 5 + */ + 'active_tab' => 5, + + /**------------------------------------------------- + * Here you can define when the exceptions should be pruned + * The default is 7 days (a week) + * The format for providing period should follow carbon's format. i.e. + * 1 day => 'subDay()', + * 3 days => 'subDays(3)', + * 7 days => 'subWeek()', + * 1 month => 'subMonth()', + * 2 months => 'subMonths(2)', + * + */ + + 'period' => now()->subWeek(), +]; diff --git a/database/migrations/2024_08_12_052046_create_filament_exceptions_table.php b/database/migrations/2024_08_12_052046_create_filament_exceptions_table.php new file mode 100644 index 000000000..3cd034e94 --- /dev/null +++ b/database/migrations/2024_08_12_052046_create_filament_exceptions_table.php @@ -0,0 +1,44 @@ +id(); + $table->string('type', 255); + $table->string('code'); + $table->longText('message'); + $table->string('file', 255); + $table->integer('line'); + $table->text('trace'); + $table->string('method'); + $table->string('path', 255); + $table->text('query'); + $table->text('body'); + $table->text('cookies'); + $table->text('headers'); + $table->string('ip'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('filament_exceptions_table'); + } +}; diff --git a/lang/en/filament.php b/lang/en/filament.php index 71f12297e..a7d19eb93 100644 --- a/lang/en/filament.php +++ b/lang/en/filament.php @@ -85,7 +85,7 @@ return [ 'name' => 'Upload Audio', ], 'attach_related_videos' => [ - 'name' => 'Attach Audio to Related Videos', + 'name' => 'Attach to Related Videos', ], ], 'base' => [ @@ -458,10 +458,12 @@ return [ 'dashboards' => [ 'icon' => [ 'admin' => 'heroicon-m-chart-bar', + 'dev' => 'heroicon-m-code-bracket', 'wiki' => 'heroicon-m-chart-bar', ], 'label' => [ 'admin' => 'Admin', + 'dev' => 'Developer', 'wiki' => 'Wiki', ], ], diff --git a/lang/vendor/filament-exceptions/en/filament-exceptions.php b/lang/vendor/filament-exceptions/en/filament-exceptions.php new file mode 100644 index 000000000..5def33530 --- /dev/null +++ b/lang/vendor/filament-exceptions/en/filament-exceptions.php @@ -0,0 +1,33 @@ + [ + 'model' => 'Exception', + 'model_plural' => 'Exceptions', + 'navigation' => 'Exception', + 'navigation_group' => 'Settings', + + 'tabs' => [ + 'exception' => 'Exception', + 'headers' => 'Headers', + 'cookies' => 'Cookies', + 'body' => 'Body', + 'queries' => 'Queries', + ], + ], + + 'empty_list' => 'Horray! just sit back & enjoy 😎', + + 'columns' => [ + 'method' => 'Method', + 'path' => 'Path', + 'type' => 'Type', + 'code' => 'Code', + 'ip' => 'IP', + 'occurred_at' => 'Occurred at', + ], + +]; diff --git a/public/css/bezhansalleh/filament-exceptions/filament-exceptions.css b/public/css/bezhansalleh/filament-exceptions/filament-exceptions.css new file mode 100644 index 000000000..888dae04a --- /dev/null +++ b/public/css/bezhansalleh/filament-exceptions/filament-exceptions.css @@ -0,0 +1 @@ +.ml-2{margin-left:.5rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mt-4{margin-top:1rem}.contents{display:contents}.basis-1\/12{flex-basis:8.333333%}.basis-11\/12{flex-basis:91.666667%}.flex-row{flex-direction:row}.space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse:0;margin-right:calc(.5rem*var(--tw-space-x-reverse));margin-left:calc(.5rem*(1 - var(--tw-space-x-reverse)))}.break-words{overflow-wrap:break-word}.break-all{word-break:break-all}.rounded-sm{border-radius:.125rem}.bg-danger-500\/10{background-color:rgba(var(--danger-500),.1)}.bg-success-500\/10{background-color:rgba(var(--success-500),.1)}.bg-warning-500\/10{background-color:rgba(var(--warning-500),.1)}.pr-2{padding-right:.5rem}.\!text-primary-600{--tw-text-opacity:1!important;color:rgba(var(--primary-600),var(--tw-text-opacity))!important}.text-danger-700{--tw-text-opacity:1;color:rgba(var(--danger-700),var(--tw-text-opacity))}.text-gray-800{--tw-text-opacity:1;color:rgba(var(--gray-800),var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgba(var(--gray-900),var(--tw-text-opacity))}.text-primary-700{--tw-text-opacity:1;color:rgba(var(--primary-700),var(--tw-text-opacity))}.text-success-700{--tw-text-opacity:1;color:rgba(var(--success-700),var(--tw-text-opacity))}.text-warning-700{--tw-text-opacity:1;color:rgba(var(--warning-700),var(--tw-text-opacity))}.shadow-none{--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}code[class*=language-],pre[class*=language-]{color:inherit;background:inherit;text-shadow:none;font-family:Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:1;-o-tab-size:1;tab-size:1;-webkit-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1rem;margin:.5rem 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:inherit;border-radius:8px}:not(pre)>code[class*=language-]{padding:.4rem;border-radius:.4rem;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:inherit}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.line-highlight{position:absolute;left:0;right:0;padding-left:0;padding-bottom:inherit;padding-right:0;padding-top:inherit;margin-top:1rem;background:#77778675;pointer-events:none;line-height:inherit;white-space:pre-wrap}.line-highlight:before,.line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4rem;left:.6rem;min-width:1rem;padding:0 .5rem;background-color:#997a6666;color:#f5f2f0;font:700 65%/1.5 sans-serif;text-align:center;vertical-align:.3rem;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}.line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4rem}pre.line-numbers{padding-left:3.8rem;counter-reset:linenumber}pre.line-numbers,pre.line-numbers>code{position:relative}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-20rem;width:3rem;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;user-select:none}.line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8rem;text-align:right}.even\:bg-white:nth-child(2n){--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.focus\:bg-gray-950\/5:focus,.hover\:bg-gray-950\/5:hover{background-color:rgba(var(--gray-950),.05)}:is([dir=rtl] .rtl\:ml-0){margin-left:0}:is([dir=rtl] .rtl\:mr-auto){margin-right:auto}:is([dir=rtl] .rtl\:rotate-0){--tw-rotate:0deg}:is([dir=rtl] .rtl\:rotate-0),:is([dir=rtl] .rtl\:rotate-180){transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}:is([dir=rtl] .rtl\:rotate-180){--tw-rotate:180deg}:is([dir=rtl] .rtl\:pl-2){padding-left:.5rem}:is(.dark .dark\:rounded-lg){border-radius:.5rem}:is(.dark .dark\:border){border-width:1px}:is(.dark .dark\:border-r){border-right-width:1px}:is(.dark .dark\:border-gray-600){--tw-border-opacity:1;border-color:rgba(var(--gray-600),var(--tw-border-opacity))}:is(.dark .dark\:border-gray-700){--tw-border-opacity:1;border-color:rgba(var(--gray-700),var(--tw-border-opacity))}:is(.dark .dark\:border-gray-800){--tw-border-opacity:1;border-color:rgba(var(--gray-800),var(--tw-border-opacity))}:is(.dark .dark\:border-gray-950){--tw-border-opacity:1;border-color:rgba(var(--gray-950),var(--tw-border-opacity))}:is(.dark .dark\:border-r-gray-200){--tw-border-opacity:1;border-right-color:rgba(var(--gray-200),var(--tw-border-opacity))}:is(.dark .dark\:bg-gray-500\/20){background-color:rgba(var(--gray-500),.2)}:is(.dark .dark\:bg-gray-800){--tw-bg-opacity:1;background-color:rgba(var(--gray-800),var(--tw-bg-opacity))}:is(.dark .dark\:bg-gray-900){--tw-bg-opacity:1;background-color:rgba(var(--gray-900),var(--tw-bg-opacity))}:is(.dark .dark\:bg-white\/5){background-color:#ffffff0d}:is(.dark .dark\:bg-white\/\[0\.03\]){background-color:#ffffff08}:is(.dark .dark\:text-danger-500){--tw-text-opacity:1;color:rgba(var(--danger-500),var(--tw-text-opacity))}:is(.dark .dark\:text-gray-100){--tw-text-opacity:1;color:rgba(var(--gray-100),var(--tw-text-opacity))}:is(.dark .dark\:text-gray-200){--tw-text-opacity:1;color:rgba(var(--gray-200),var(--tw-text-opacity))}:is(.dark .dark\:text-gray-300){--tw-text-opacity:1;color:rgba(var(--gray-300),var(--tw-text-opacity))}:is(.dark .dark\:text-gray-400){--tw-text-opacity:1;color:rgba(var(--gray-400),var(--tw-text-opacity))}:is(.dark .dark\:text-gray-50){--tw-text-opacity:1;color:rgba(var(--gray-50),var(--tw-text-opacity))}:is(.dark .dark\:text-gray-500){--tw-text-opacity:1;color:rgba(var(--gray-500),var(--tw-text-opacity))}:is(.dark .dark\:text-primary-400){--tw-text-opacity:1;color:rgba(var(--primary-400),var(--tw-text-opacity))}:is(.dark .dark\:text-primary-500){--tw-text-opacity:1;color:rgba(var(--primary-500),var(--tw-text-opacity))}:is(.dark .dark\:text-primary-600){--tw-text-opacity:1;color:rgba(var(--primary-600),var(--tw-text-opacity))}:is(.dark .dark\:text-success-500){--tw-text-opacity:1;color:rgba(var(--success-500),var(--tw-text-opacity))}:is(.dark .dark\:text-warning-500){--tw-text-opacity:1;color:rgba(var(--warning-500),var(--tw-text-opacity))}:is(.dark .dark\:even\:bg-gray-600:nth-child(2n)){--tw-bg-opacity:1;background-color:rgba(var(--gray-600),var(--tw-bg-opacity))}:is(.dark .dark\:even\:bg-gray-700:nth-child(2n)){--tw-bg-opacity:1;background-color:rgba(var(--gray-700),var(--tw-bg-opacity))}:is(.dark .dark\:even\:text-gray-50:nth-child(2n)){--tw-text-opacity:1;color:rgba(var(--gray-50),var(--tw-text-opacity))}:is(.dark .dark\:focus\:bg-white\/5:focus),:is(.dark .dark\:hover\:bg-white\/5:hover){background-color:#ffffff0d}@media (min-width:640px){.sm\:mt-0{margin-top:0}.sm\:gap-4{gap:1rem}.sm\:px-6{padding-left:1.5rem;padding-right:1.5rem}} \ No newline at end of file diff --git a/public/js/bezhansalleh/filament-exceptions/filament-exceptions.js b/public/js/bezhansalleh/filament-exceptions/filament-exceptions.js new file mode 100644 index 000000000..f2993f210 --- /dev/null +++ b/public/js/bezhansalleh/filament-exceptions/filament-exceptions.js @@ -0,0 +1,639 @@ +/* http://prismjs.com/download.html?themes=prism&languages=clike+php&plugins=line-highlight+line-numbers */ +var _self = + "undefined" != typeof window + ? window + : "undefined" != typeof WorkerGlobalScope && + self instanceof WorkerGlobalScope + ? self + : {}, + Prism = (function () { + var e = /\blang(?:uage)?-(\w+)\b/i, + t = 0, + n = (_self.Prism = { + util: { + encode: function (e) { + return e instanceof a + ? new a(e.type, n.util.encode(e.content), e.alias) + : "Array" === n.util.type(e) + ? e.map(n.util.encode) + : e + .replace(/&/g, "&") + .replace(/ e.length) break e; + if (!(v instanceof a)) { + u.lastIndex = 0; + var b = u.exec(v), + k = 1; + if (!b && h && m != r.length - 1) { + if ( + ((u.lastIndex = y), + (b = u.exec(e)), + !b) + ) + break; + for ( + var w = + b.index + + (c ? b[1].length : 0), + _ = b.index + b[0].length, + A = m, + P = y, + x = r.length; + x > A && _ > P; + ++A + ) + (P += r[A].length), + w >= P && (++m, (y = P)); + if ( + r[m] instanceof a || + r[A - 1].greedy + ) + continue; + (k = A - m), + (v = e.slice(y, P)), + (b.index -= y); + } + if (b) { + c && (f = b[1].length); + var w = b.index + f, + b = b[0].slice(f), + _ = w + b.length, + O = v.slice(0, w), + S = v.slice(_), + j = [m, k]; + O && j.push(O); + var N = new a( + l, + g ? n.tokenize(b, g) : b, + d, + b, + h + ); + j.push(N), + S && j.push(S), + Array.prototype.splice.apply( + r, + j + ); + } + } + } + } + } + return r; + }, + hooks: { + all: {}, + add: function (e, t) { + var a = n.hooks.all; + (a[e] = a[e] || []), a[e].push(t); + }, + run: function (e, t) { + var a = n.hooks.all[e]; + if (a && a.length) + for (var r, i = 0; (r = a[i++]); ) r(t); + }, + }, + }), + a = (n.Token = function (e, t, n, a, r) { + (this.type = e), + (this.content = t), + (this.alias = n), + (this.length = 0 | (a || "").length), + (this.greedy = !!r); + }); + if ( + ((a.stringify = function (e, t, r) { + if ("string" == typeof e) return e; + if ("Array" === n.util.type(e)) + return e + .map(function (n) { + return a.stringify(n, t, e); + }) + .join(""); + var i = { + type: e.type, + content: a.stringify(e.content, t, r), + tag: "span", + classes: ["token", e.type], + attributes: {}, + language: t, + parent: r, + }; + if ( + ("comment" == i.type && (i.attributes.spellcheck = "true"), + e.alias) + ) { + var l = + "Array" === n.util.type(e.alias) ? e.alias : [e.alias]; + Array.prototype.push.apply(i.classes, l); + } + n.hooks.run("wrap", i); + var o = ""; + for (var s in i.attributes) + o += + (o ? " " : "") + + s + + '="' + + (i.attributes[s] || "") + + '"'; + return ( + "<" + + i.tag + + ' class="' + + i.classes.join(" ") + + '"' + + (o ? " " + o : "") + + ">" + + i.content + + "" + ); + }), + !_self.document) + ) + return _self.addEventListener + ? (_self.addEventListener( + "message", + function (e) { + var t = JSON.parse(e.data), + a = t.language, + r = t.code, + i = t.immediateClose; + _self.postMessage(n.highlight(r, n.languages[a], a)), + i && _self.close(); + }, + !1 + ), + _self.Prism) + : _self.Prism; + var r = + document.currentScript || + [].slice.call(document.getElementsByTagName("script")).pop(); + return ( + r && + ((n.filename = r.src), + document.addEventListener && + !r.hasAttribute("data-manual") && + ("loading" !== document.readyState + ? window.requestAnimationFrame + ? window.requestAnimationFrame(n.highlightAll) + : window.setTimeout(n.highlightAll, 16) + : document.addEventListener( + "DOMContentLoaded", + n.highlightAll + ))), + _self.Prism + ); + })(); +"undefined" != typeof module && module.exports && (module.exports = Prism), + "undefined" != typeof global && (global.Prism = Prism); +Prism.languages.clike = { + comment: [ + { pattern: /(^|[^\\])\/\*[\w\W]*?\*\//, lookbehind: !0 }, + { pattern: /(^|[^\\:])\/\/.*/, lookbehind: !0 }, + ], + string: { + pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, + greedy: !0, + }, + "class-name": { + pattern: + /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i, + lookbehind: !0, + inside: { punctuation: /(\.|\\)/ }, + }, + keyword: + /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/, + boolean: /\b(true|false)\b/, + function: /[a-z0-9_]+(?=\()/i, + number: /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i, + operator: /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/, + punctuation: /[{}[\];(),.:]/, +}; +(Prism.languages.php = Prism.languages.extend("clike", { + keyword: + /\b(and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|private|protected|parent|throw|null|echo|print|trait|namespace|final|yield|goto|instanceof|finally|try|catch)\b/i, + constant: /\b[A-Z0-9_]{2,}\b/, + comment: { + pattern: /(^|[^\\])(?:\/\*[\w\W]*?\*\/|\/\/.*)/, + lookbehind: !0, + greedy: !0, + }, +})), + Prism.languages.insertBefore("php", "class-name", { + "shell-comment": { + pattern: /(^|[^\\])#.*/, + lookbehind: !0, + alias: "comment", + }, + }), + Prism.languages.insertBefore("php", "keyword", { + delimiter: /\?>|<\?(?:php)?/i, + variable: /\$\w+\b/i, + package: { + pattern: /(\\|namespace\s+|use\s+)[\w\\]+/, + lookbehind: !0, + inside: { punctuation: /\\/ }, + }, + }), + Prism.languages.insertBefore("php", "operator", { + property: { pattern: /(->)[\w]+/, lookbehind: !0 }, + }), + Prism.languages.markup && + (Prism.hooks.add("before-highlight", function (e) { + "php" === e.language && + ((e.tokenStack = []), + (e.backupCode = e.code), + (e.code = e.code.replace( + /(?:<\?php|<\?)[\w\W]*?(?:\?>)/gi, + function (a) { + return ( + e.tokenStack.push(a), + "{{{PHP" + e.tokenStack.length + "}}}" + ); + } + ))); + }), + Prism.hooks.add("before-insert", function (e) { + "php" === e.language && + ((e.code = e.backupCode), delete e.backupCode); + }), + Prism.hooks.add("after-highlight", function (e) { + if ("php" === e.language) { + for (var a, n = 0; (a = e.tokenStack[n]); n++) + e.highlightedCode = e.highlightedCode.replace( + "{{{PHP" + (n + 1) + "}}}", + Prism.highlight(a, e.grammar, "php").replace( + /\$/g, + "$$$$" + ) + ); + e.element.innerHTML = e.highlightedCode; + } + }), + Prism.hooks.add("wrap", function (e) { + "php" === e.language && + "markup" === e.type && + (e.content = e.content.replace( + /(\{\{\{PHP[0-9]+\}\}\})/g, + '$1' + )); + }), + Prism.languages.insertBefore("php", "comment", { + markup: { + pattern: /<[^?]\/?(.*?)>/, + inside: Prism.languages.markup, + }, + php: /\{\{\{PHP[0-9]+\}\}\}/, + })); + Prism.languages.sql = { + comment: { + pattern: + /(^|[^\\])(\/\*[\w\W]*?\*\/|((--)|(\/\/)).*?(\r?\n|$))/g, + lookbehind: !0, + }, + string: /("|')(\\?.)*?\1/g, + keyword: + /\b(ACTION|ADD|AFTER|ALGORITHM|ALTER|ANALYZE|APPLY|AS|AS|ASC|AUTHORIZATION|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADE|CASCADED|CASE|CHAIN|CHAR VARYING|CHARACTER VARYING|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLUMN|COLUMNS|COMMENT|COMMIT|COMMITTED|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATA|DATABASE|DATABASES|DATETIME|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DOUBLE PRECISION|DROP|DUMMY|DUMP|DUMPFILE|DUPLICATE KEY|ELSE|ENABLE|ENCLOSED BY|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPE|ESCAPED BY|EXCEPT|EXEC|EXECUTE|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR|FOR EACH ROW|FORCE|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GEOMETRY|GEOMETRYCOLLECTION|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|IDENTITY|IDENTITY_INSERT|IDENTITYCOL|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTO|INVOKER|ISOLATION LEVEL|JOIN|KEY|KEYS|KILL|LANGUAGE SQL|LAST|LEFT|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONGBLOB|LONGTEXT|MATCH|MATCHED|MEDIUMBLOB|MEDIUMINT|MEDIUMTEXT|MERGE|MIDDLEINT|MODIFIES SQL DATA|MODIFY|MULTILINESTRING|MULTIPOINT|MULTIPOLYGON|NATIONAL|NATIONAL CHAR VARYING|NATIONAL CHARACTER|NATIONAL CHARACTER VARYING|NATIONAL VARCHAR|NATURAL|NCHAR|NCHAR VARCHAR|NEXT|NO|NO SQL|NOCHECK|NOCYCLE|NONCLUSTERED|NULLIF|NUMERIC|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPTIMIZE|OPTION|OPTIONALLY|ORDER|OUT|OUTER|OUTFILE|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREV|PRIMARY|PRINT|PRIVILEGES|PROC|PROCEDURE|PUBLIC|PURGE|QUICK|RAISERROR|READ|READS SQL DATA|READTEXT|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEATABLE|REPLICATION|REQUIRE|RESTORE|RESTRICT|RETURN|RETURNS|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROWCOUNT|ROWGUIDCOL|ROWS?|RTREE|RULE|SAVE|SAVEPOINT|SCHEMA|SELECT|SERIAL|SERIALIZABLE|SESSION|SESSION_USER|SET|SETUSER|SHARE MODE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|START|STARTING BY|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLE|TABLES|TABLESPACE|TEMPORARY|TEMPTABLE|TERMINATED BY|TEXT|TEXTSIZE|THEN|TIMESTAMP|TINYBLOB|TINYINT|TINYTEXT|TO|TOP|TRAN|TRANSACTION|TRANSACTIONS|TRIGGER|TRUNCATE|TSEQUAL|TYPE|TYPES|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNPIVOT|UPDATE|UPDATETEXT|USAGE|USE|USER|USING|VALUE|VALUES|VARBINARY|VARCHAR|VARCHARACTER|VARYING|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH|WITH ROLLUP|WITHIN|WORK|WRITE|WRITETEXT)\b/gi, + boolean: /\b(TRUE|FALSE|NULL)\b/gi, + number: /\b-?(0x)?\d*\.?[\da-f]+\b/g, + operator: + /\b(ALL|AND|ANY|BETWEEN|EXISTS|IN|LIKE|NOT|OR|IS|UNIQUE|CHARACTER SET|COLLATE|DIV|OFFSET|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b|[-+]{1}|!|=?<|=?>|={1}|(&){1,2}|\|?\||\?|\*|\//gi, + ignore: /&(lt|gt|amp);/gi, + punctuation: /[;[\]()`,.]/g, + }; +!(function () { + function e(e, t) { + return Array.prototype.slice.call((t || document).querySelectorAll(e)); + } + function t(e, t) { + return ( + (t = " " + t + " "), + (" " + e.className + " ").replace(/[\n\t]/g, " ").indexOf(t) > -1 + ); + } + function n(e, n, i) { + for ( + var o, + a = n.replace(/\s+/g, "").split(","), + l = +e.getAttribute("data-line-offset") || 0, + d = r() ? parseInt : parseFloat, + c = d(getComputedStyle(e).lineHeight), + s = 0; + (o = a[s++]); + + ) { + o = o.split("-"); + var u = +o[0], + m = +o[1] || u, + h = document.createElement("div"); + (h.textContent = Array(m - u + 2).join(" \n")), + h.setAttribute("aria-hidden", "true"), + (h.className = (i || "") + " line-highlight"), + t(e, "line-numbers") || + (h.setAttribute("data-start", u), + m > u && h.setAttribute("data-end", m)), + (h.style.top = (u - l - 1) * c + "px"), + t(e, "line-numbers") + ? e.appendChild(h) + : (e.querySelector("code") || e).appendChild(h); + } + } + function i() { + var t = location.hash.slice(1); + e(".temporary.line-highlight").forEach(function (e) { + e.parentNode.removeChild(e); + }); + var i = (t.match(/\.([\d,-]+)$/) || [, ""])[1]; + if (i && !document.getElementById(t)) { + var r = t.slice(0, t.lastIndexOf(".")), + o = document.getElementById(r); + o && + (o.hasAttribute("data-line") || o.setAttribute("data-line", ""), + n(o, i, "temporary "), + document + .querySelector(".temporary.line-highlight") + .scrollIntoView()); + } + } + if ( + "undefined" != typeof self && + self.Prism && + self.document && + document.querySelector + ) { + var r = (function () { + var e; + return function () { + if ("undefined" == typeof e) { + var t = document.createElement("div"); + (t.style.fontSize = "13px"), + (t.style.lineHeight = "1.5"), + (t.style.padding = 0), + (t.style.border = 0), + (t.innerHTML = " 
 "), + document.body.appendChild(t), + (e = 38 === t.offsetHeight), + document.body.removeChild(t); + } + return e; + }; + })(), + o = 0; + Prism.hooks.add("complete", function (t) { + var r = t.element.parentNode, + a = r && r.getAttribute("data-line"); + r && + a && + /pre/i.test(r.nodeName) && + (clearTimeout(o), + e(".line-highlight", r).forEach(function (e) { + e.parentNode.removeChild(e); + }), + n(r, a), + (o = setTimeout(i, 1))); + }), + window.addEventListener && window.addEventListener("hashchange", i); + } +})(); +!(function () { + "undefined" != typeof self && + self.Prism && + self.document && + Prism.hooks.add("complete", function (e) { + if (e.code) { + var t = e.element.parentNode, + s = /\s*\bline-numbers\b\s*/; + if ( + t && + /pre/i.test(t.nodeName) && + (s.test(t.className) || s.test(e.element.className)) && + !e.element.querySelector(".line-numbers-rows") + ) { + s.test(e.element.className) && + (e.element.className = e.element.className.replace( + s, + "" + )), + s.test(t.className) || (t.className += " line-numbers"); + var n, + a = e.code.match(/\n(?!$)/g), + l = a ? a.length + 1 : 1, + r = new Array(l + 1); + (r = r.join("")), + (n = document.createElement("span")), + n.setAttribute("aria-hidden", "true"), + (n.className = "line-numbers-rows"), + (n.innerHTML = r), + t.hasAttribute("data-start") && + (t.style.counterReset = + "linenumber " + + (parseInt(t.getAttribute("data-start"), 10) - + 1)), + e.element.appendChild(n); + } + } + }); +})(); + + diff --git a/tests/Unit/Enums/Models/Wiki/ResourceSiteTest.php b/tests/Unit/Enums/Models/Wiki/ResourceSiteTest.php index adbbc6ee1..847f7fd45 100644 --- a/tests/Unit/Enums/Models/Wiki/ResourceSiteTest.php +++ b/tests/Unit/Enums/Models/Wiki/ResourceSiteTest.php @@ -9,6 +9,7 @@ use App\Models\Wiki\Anime; use App\Models\Wiki\Studio; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Illuminate\Support\Facades\Http; use Tests\TestCase; @@ -134,35 +135,32 @@ class ResourceSiteTest extends TestCase } /** - * The Resource Site shall fail to parse the ID from Kitsu if the response is not expected. + * The Resource Site shall parse the ID from Kitsu if the link contains an integer. * * @return void */ - public function testFailParseKitsuIdFromAnimeResource(): void + public function testParseKitsuIdForIdFromAnimeResource(): void { - Http::fake([ - 'https://kitsu.io/api/graphql' => Http::response([ - $this->faker->word() => $this->faker->word(), - ]), - ]); + $id = $this->faker->randomDigitNotNull(); - $link = ResourceSite::KITSU->formatResourceLink(Anime::class, - $this->faker->randomDigitNotNull(), - $this->faker->slug() - ); + $link = ResourceSite::KITSU->formatResourceLink(Anime::class, $id); - static::assertEmpty(ResourceSite::parseIdFromLink($link)); - Http::assertSentCount(1); + static::assertEquals($id, ResourceSite::parseIdFromLink($link)); } /** - * The Resource Site shall parse the ID from Kitsu if the response is expected. + * The Resource Site shall parse the ID from Kitsu if the link contains a slug. * * @return void */ - public function testParseKitsuIdFromAnimeResource(): void + public function testParseKitsuIdForSlugFromAnimeResource(): void { $id = $this->faker->randomDigitNotNull(); + $slug = $this->faker->slug(); + + $linkWithSlug = Str::of(ResourceSite::KITSU->formatResourceLink(Anime::class, $id)) + ->replace(strval($id), $slug) + ->__toString(); Http::fake([ 'https://kitsu.io/api/graphql' => Http::response([ @@ -174,9 +172,7 @@ class ResourceSiteTest extends TestCase ]), ]); - $link = ResourceSite::KITSU->formatResourceLink(Anime::class, $id, $this->faker->slug()); - - static::assertEquals(strval($id), ResourceSite::parseIdFromLink($link)); + static::assertEquals(strval($id), ResourceSite::parseIdFromLink($linkWithSlug)); Http::assertSentCount(1); } }