feat(filament): added developer dashboard (#722)

This commit is contained in:
Kyrch
2024-08-12 20:14:05 -03:00
committed by GitHub
parent fdd767f49c
commit 14c378bd80
52 changed files with 1834 additions and 2579 deletions
@@ -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\JikanAnimeApiAction;
use App\Actions\Models\Wiki\Anime\ApiAction\LivechartAnimeApiAction; use App\Actions\Models\Wiki\Anime\ApiAction\LivechartAnimeApiAction;
use App\Actions\Models\Wiki\Anime\ApiAction\MalAnimeApiAction; use App\Actions\Models\Wiki\Anime\ApiAction\MalAnimeApiAction;
use App\Concerns\Models\CanCreateAnimeSynonym;
use App\Concerns\Models\CanCreateStudio; use App\Concerns\Models\CanCreateStudio;
use App\Enums\Actions\ActionStatus; use App\Enums\Actions\ActionStatus;
use App\Enums\Models\Wiki\AnimeSynonymType;
use App\Models\Wiki\Anime; use App\Models\Wiki\Anime;
use App\Models\Wiki\Anime\AnimeSynonym;
use Exception; use Exception;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -25,6 +24,7 @@ use Illuminate\Support\Facades\Log;
*/ */
class BackfillAnimeAction extends BackfillWikiAction class BackfillAnimeAction extends BackfillWikiAction
{ {
use CanCreateAnimeSynonym;
use CanCreateStudio; use CanCreateStudio;
final public const STUDIOS = 'studios'; 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()}"); Log::info("Attaching Studio of name '$name' to Anime {$this->getModel()->getName()}");
$this->getModel()->studios()->attach($studio); $this->getModel()->studios()->attach($studio);
$this->toBackfill[self::STUDIOS] = false;
$this->ensureStudioHasResource($studio, $response->getSite(), $id); $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; if (!$this->toBackfill[self::SYNONYMS]) return;
foreach ($api->getSynonyms() as $type => $text) { foreach ($api->getSynonyms() as $type => $text) {
if ( $this->createAnimeSynonym($text, $type, $this->getModel());
$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->toBackfill[self::SYNONYMS] = false;
} }
/** /**
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Concerns\Models;
use App\Enums\Models\Wiki\AnimeSynonymType;
use App\Models\Wiki\Anime;
use App\Models\Wiki\Anime\AnimeSynonym;
use Illuminate\Support\Facades\Log;
/**
* Trait CanCreateAnimeSynonym.
*/
trait CanCreateAnimeSynonym
{
/**
* Create Anime Synonym for the Anime.
*
* @param string|null $text
* @param int $type
* @param Anime $anime
* @return void
*/
public function createAnimeSynonym(?string $text, int $type, Anime $anime): void
{
if (
$text === null
|| empty($text)
|| ($type === AnimeSynonymType::OTHER->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(),
]);
}
}
+7
View File
@@ -8,6 +8,7 @@ use App\Console\Commands\Storage\Admin\DocumentDumpCommand;
use App\Console\Commands\Storage\Admin\DumpPruneCommand; use App\Console\Commands\Storage\Admin\DumpPruneCommand;
use App\Console\Commands\Storage\Admin\WikiDumpCommand; use App\Console\Commands\Storage\Admin\WikiDumpCommand;
use App\Models\BaseModel; use App\Models\BaseModel;
use BezhanSalleh\FilamentExceptions\Models\Exception;
use Illuminate\Auth\Console\ClearResetsCommand; use Illuminate\Auth\Console\ClearResetsCommand;
use Illuminate\Cache\Console\PruneStaleTagsCommand; use Illuminate\Cache\Console\PruneStaleTagsCommand;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
@@ -97,6 +98,12 @@ class Kernel extends ConsoleKernel
->storeOutput() ->storeOutput()
->daily(); ->daily();
$schedule->command(PruneModelsCommand::class, ['--model' => [Exception::class]]) // Filament Exception Viewer Plugin
->withoutOverlapping()
->runInBackground()
->storeOutput()
->daily();
$schedule->command(PruneStaleTagsCommand::class) $schedule->command(PruneStaleTagsCommand::class)
->withoutOverlapping() ->withoutOverlapping()
->runInBackground() ->runInBackground()
+17
View File
@@ -4,7 +4,10 @@ declare(strict_types=1);
namespace App\Exceptions; namespace App\Exceptions;
use BezhanSalleh\FilamentExceptions\FilamentExceptions;
use Filament\Facades\Filament;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
/** /**
* Class Handler. * Class Handler.
@@ -21,4 +24,18 @@ class Handler extends ExceptionHandler
'password', 'password',
'password_confirmation', '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);
}
});
}
} }
+2 -2
View File
@@ -10,7 +10,7 @@ use App\Filament\Widgets\List\ExternalProfileChart;
use App\Filament\Widgets\List\PlaylistChart; use App\Filament\Widgets\List\PlaylistChart;
use App\Filament\Widgets\List\PlaylistTrackChart; use App\Filament\Widgets\List\PlaylistTrackChart;
use App\Models\Auth\User; use App\Models\Auth\User;
use Illuminate\Support\Facades\Auth; use Filament\Facades\Filament;
/** /**
* Class AdminDashboard. * Class AdminDashboard.
@@ -34,7 +34,7 @@ class AdminDashboard extends BaseDashboard
*/ */
public static function canAccess(): bool public static function canAccess(): bool
{ {
return User::find(Auth::id())->hasRole(RoleEnum::ADMIN->value); return User::find(Filament::auth()->id())->hasRole(RoleEnum::ADMIN->value);
} }
/** /**
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace App\Filament\Dashboards;
use App\Enums\Auth\Role as RoleEnum;
use App\Filament\Widgets\Admin\ExceptionsTableWidget;
use App\Models\Auth\User;
use Filament\Facades\Filament;
/**
* Class DeveloperDashboard.
*/
class DeveloperDashboard extends BaseDashboard
{
/**
* Get the slug used to the dashboard route path.
*
* @return string
*/
public static function getSlug(): string
{
return 'dev';
}
/**
* Determine if the user can access the dashboard.
*
* @return bool
*/
public static function canAccess(): bool
{
return User::find(Filament::auth()->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,
];
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Admin;
use App\Enums\Auth\Role;
use App\Filament\Actions\Base\ViewAction;
use App\Filament\Components\Columns\TextColumn;
use App\Filament\Resources\Admin\Exception\Pages\ListExceptions;
use App\Filament\Resources\Admin\Exception\Pages\ViewException;
use App\Models\Auth\User;
use BezhanSalleh\FilamentExceptions\Models\Exception as ExceptionModel;
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource;
use Filament\Facades\Filament;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Table;
/**
* Class Exception.
*/
class Exception extends ExceptionResource
{
/**
* The logical group associated with the resource.
*
* @return string
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getNavigationGroup(): string
{
return __('filament.resources.group.admin');
}
/**
* The index page of the resource.
*
* @param Table $table
* @return Table
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function table(Table $table): Table
{
return $table
->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}')
];
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Admin\Exception\Pages;
use App\Filament\Resources\Admin\Exception;
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource\Pages\ListExceptions as BaseListExceptions;
/**
* Class ListExceptions.
*/
class ListExceptions extends BaseListExceptions
{
protected static string $resource = Exception::class;
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace App\Filament\Resources\Admin\Exception\Pages;
use App\Filament\Resources\Admin\Exception;
use BezhanSalleh\FilamentExceptions\Resources\ExceptionResource\Pages\ViewException as BaseViewException;
/**
* Class ViewException.
*/
class ViewException extends BaseViewException
{
protected static string $resource = Exception::class;
}
@@ -168,13 +168,13 @@ class DiscordThread extends BaseResource
->label(__('filament.fields.discord_thread.name.name')) ->label(__('filament.fields.discord_thread.name.name'))
->sortable() ->sortable()
->copyableWithMessage() ->copyableWithMessage()
->searchable()
->toggleable(), ->toggleable(),
BelongsToColumn::make(DiscordThreadModel::RELATION_ANIME.'.'.Anime::ATTRIBUTE_NAME) BelongsToColumn::make(DiscordThreadModel::RELATION_ANIME.'.'.Anime::ATTRIBUTE_NAME)
->resource(AnimeResource::class) ->resource(AnimeResource::class)
->toggleable(), ->toggleable(),
]) ])
->searchable()
->defaultSort(BaseModel::CREATED_AT, 'desc'); ->defaultSort(BaseModel::CREATED_AT, 'desc');
} }
+4 -1
View File
@@ -434,7 +434,10 @@ class Theme extends BaseResource
if ($slug->isNotEmpty()) { if ($slug->isNotEmpty()) {
$group = $get(ThemeModel::ATTRIBUTE_GROUP); $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()); $set(ThemeModel::ATTRIBUTE_SLUG, $slug->__toString());
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace App\Filament\Widgets\Admin;
use App\Filament\Resources\Admin\Exception;
use App\Filament\Widgets\BaseTableWidget;
use Filament\Tables\Table;
/**
* Class ExceptionsTableWidget.
*/
class ExceptionsTableWidget extends BaseTableWidget
{
/**
* The index page of the resource.
*
* @param Table $table
* @return Table
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function table(Table $table): Table
{
return Exception::table($table)
->heading(__('filament-exceptions::filament-exceptions.labels.model_plural'));
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace App\Filament\Widgets;
use Filament\Widgets\TableWidget;
/**
* Class BaseTableWidget.
*/
abstract class BaseTableWidget extends TableWidget
{
protected int|string|array $columnSpan = 'full';
}
+12 -12
View File
@@ -162,13 +162,13 @@ class ActionLog extends Model implements Nameable, HasSubtitle
} }
/** /**
* Get the user for the action log. * Get the user id for the action log.
* *
* @return User * @return int
*/ */
public static function getUser(): User public static function getUserId(): int
{ {
return Filament::auth()->user(); return Filament::auth()->id();
} }
/** /**
@@ -180,8 +180,8 @@ class ActionLog extends Model implements Nameable, HasSubtitle
public static function modelCreated(Model $model): ActionLog public static function modelCreated(Model $model): ActionLog
{ {
return ActionLog::query()->create([ return ActionLog::query()->create([
ActionLog::ATTRIBUTE_BATCH_ID => (string) Str::orderedUuid(), ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(),
ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(),
ActionLog::ATTRIBUTE_NAME => 'Create', ActionLog::ATTRIBUTE_NAME => 'Create',
ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(),
ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(),
@@ -203,8 +203,8 @@ class ActionLog extends Model implements Nameable, HasSubtitle
public static function modelUpdated(Model $model): ActionLog public static function modelUpdated(Model $model): ActionLog
{ {
return ActionLog::query()->create([ return ActionLog::query()->create([
ActionLog::ATTRIBUTE_BATCH_ID => (string) Str::orderedUuid(), ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(),
ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(),
ActionLog::ATTRIBUTE_NAME => 'Update', ActionLog::ATTRIBUTE_NAME => 'Update',
ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(),
ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(),
@@ -250,7 +250,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle
{ {
return ActionLog::query()->create([ return ActionLog::query()->create([
ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(),
ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(),
ActionLog::ATTRIBUTE_NAME => $actionName, ActionLog::ATTRIBUTE_NAME => $actionName,
ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(),
ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(),
@@ -276,7 +276,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle
{ {
return ActionLog::query()->create([ return ActionLog::query()->create([
ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(),
ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(),
ActionLog::ATTRIBUTE_NAME => $action, ActionLog::ATTRIBUTE_NAME => $action,
ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $related->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $related->getMorphClass(),
ActionLog::ATTRIBUTE_ACTIONABLE_ID => $related->getKey(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $related->getKey(),
@@ -301,7 +301,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle
{ {
return ActionLog::query()->create([ return ActionLog::query()->create([
ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(), ActionLog::ATTRIBUTE_BATCH_ID => Str::orderedUuid()->__toString(),
ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(),
ActionLog::ATTRIBUTE_NAME => $action, ActionLog::ATTRIBUTE_NAME => $action,
ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $related->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $related->getMorphClass(),
ActionLog::ATTRIBUTE_ACTIONABLE_ID => $related->getKey(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $related->getKey(),
@@ -326,7 +326,7 @@ class ActionLog extends Model implements Nameable, HasSubtitle
{ {
return ActionLog::query()->create([ return ActionLog::query()->create([
ActionLog::ATTRIBUTE_BATCH_ID => $batchId, ActionLog::ATTRIBUTE_BATCH_ID => $batchId,
ActionLog::ATTRIBUTE_USER => ActionLog::getUser()->getKey(), ActionLog::ATTRIBUTE_USER => ActionLog::getUserId(),
ActionLog::ATTRIBUTE_NAME => $action->getLabel(), ActionLog::ATTRIBUTE_NAME => $action->getLabel(),
ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(), ActionLog::ATTRIBUTE_ACTIONABLE_TYPE => $model->getMorphClass(),
ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(), ActionLog::ATTRIBUTE_ACTIONABLE_ID => $model->getKey(),
+2 -107
View File
@@ -4,116 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Admin; namespace App\Policies\Admin;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Admin\Announcement;
use App\Models\Auth\User;
use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class AnnouncementPolicy. * 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));
}
} }
+2 -107
View File
@@ -4,116 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Admin; namespace App\Policies\Admin;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Admin\Dump;
use App\Models\Auth\User;
use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class DumpPolicy. * 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));
}
} }
+4 -53
View File
@@ -7,31 +7,15 @@ namespace App\Policies\Admin;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Models\Admin\Feature; use App\Models\Admin\Feature;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Policies\BasePolicy;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Database\Eloquent\Model;
/** /**
* Class FeaturePolicy. * 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. * Determine whether the user can view the model.
* *
@@ -39,7 +23,7 @@ class FeaturePolicy
* @param Feature $feature * @param Feature $feature
* @return bool * @return bool
*/ */
public function view(?User $user, Feature $feature): bool public function view(?User $user, Model $feature): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class)); return $user !== null && $user->can(CrudPermission::VIEW->format(Feature::class));
@@ -47,37 +31,4 @@ class FeaturePolicy
return $feature->isNullScope(); 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));
}
} }
+5 -90
View File
@@ -5,35 +5,19 @@ declare(strict_types=1);
namespace App\Policies\Admin; namespace App\Policies\Admin;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Admin\FeaturedTheme; use App\Models\Admin\FeaturedTheme;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\BaseModel;
use App\Policies\BasePolicy;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\Date;
/** /**
* Class FeaturedThemePolicy. * 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. * Determine whether the user can view the model.
* *
@@ -41,7 +25,7 @@ class FeaturedThemePolicy
* @param FeaturedTheme $featuredtheme * @param FeaturedTheme $featuredtheme
* @return bool * @return bool
*/ */
public function view(?User $user, FeaturedTheme $featuredtheme): bool public function view(?User $user, BaseModel|Model $featuredtheme): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->can(CrudPermission::VIEW->format(FeaturedTheme::class)); return $user !== null && $user->can(CrudPermission::VIEW->format(FeaturedTheme::class));
@@ -49,73 +33,4 @@ class FeaturedThemePolicy
return $featuredtheme->start_at->isBefore(Date::now()); 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));
}
} }
+23 -45
View File
@@ -8,55 +8,49 @@ use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\Permission; use App\Models\Auth\Permission;
use App\Models\Auth\User; 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 class PermissionPolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
* @param User $user * @param User|null $user
* @return bool * @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. * Determine whether the user can view the model.
* *
* @param User $user * @param User|null $user
* @param Permission $permission
* @return bool * @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 * @noinspection PhpUnusedParameterInspection
* @return bool
*/ */
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. * Determine whether the user can update the model.
* *
* @param User $user * @param User $user
* @param Permission $permission
* @return bool * @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)); return $user->can(CrudPermission::UPDATE->format(Permission::class));
} }
@@ -65,9 +59,12 @@ class PermissionPolicy
* Determine whether the user can delete the model. * Determine whether the user can delete the model.
* *
* @param User $user * @param User $user
* @param Permission $permission
* @return bool * @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)); return $user->can(CrudPermission::DELETE->format(Permission::class));
} }
@@ -76,35 +73,16 @@ class PermissionPolicy
* Determine whether the user can restore the model. * Determine whether the user can restore the model.
* *
* @param User $user * @param User $user
* @param Permission $permission
* @return bool * @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)); 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. * Determine whether the user can attach any role to the permission.
* *
+20 -44
View File
@@ -8,22 +8,21 @@ use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\Role; use App\Models\Auth\Role;
use App\Models\Auth\User; 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 class RolePolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
* @param User $user * @param User|null $user
* @return bool * @return bool
*/ */
public function viewAny(User $user): bool public function viewAny(?User $user): bool
{ {
return $user->can(CrudPermission::VIEW->format(Role::class)); return $user->can(CrudPermission::VIEW->format(Role::class));
} }
@@ -31,32 +30,25 @@ class RolePolicy
/** /**
* Determine whether the user can view the model. * Determine whether the user can view the model.
* *
* @param User $user * @param User|null $user
* @param Role $role
* @return bool * @return bool
*/ */
public function view(User $user): bool public function view(?User $user, Model $role): bool
{ {
return $user->can(CrudPermission::VIEW->format(Role::class)); 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. * Determine whether the user can update the model.
* *
* @param User $user * @param User $user
* @param Role $role
* @return bool * @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)); return $user->can(CrudPermission::UPDATE->format(Role::class));
} }
@@ -65,9 +57,12 @@ class RolePolicy
* Determine whether the user can delete the model. * Determine whether the user can delete the model.
* *
* @param User $user * @param User $user
* @param Role $role
* @return bool * @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)); return $user->can(CrudPermission::DELETE->format(Role::class));
} }
@@ -76,35 +71,16 @@ class RolePolicy
* Determine whether the user can restore the model. * Determine whether the user can restore the model.
* *
* @param User $user * @param User $user
* @param Role $role
* @return bool * @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)); 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. * Determine whether the user can attach any permission to the role.
* *
+24 -35
View File
@@ -8,55 +8,49 @@ use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Auth\Role as RoleEnum; use App\Enums\Auth\Role as RoleEnum;
use App\Models\Auth\User; 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 class UserPolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
* @param User $user * @param User|null $user
* @return bool * @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. * Determine whether the user can view the model.
* *
* @param User $user * @param User|null $user
* @param User $userModel
* @return bool * @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)); return $user !== null && $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));
} }
/** /**
* Determine whether the user can update the model. * Determine whether the user can update the model.
* *
* @param User $user * @param User $user
* @param User $userModel
* @return bool * @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)); return $user->can(CrudPermission::UPDATE->format(User::class));
} }
@@ -65,9 +59,12 @@ class UserPolicy
* Determine whether the user can delete the model. * Determine whether the user can delete the model.
* *
* @param User $user * @param User $user
* @param User $userModel
* @return bool * @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)); return $user->can(CrudPermission::DELETE->format(User::class));
} }
@@ -76,24 +73,16 @@ class UserPolicy
* Determine whether the user can restore the model. * Determine whether the user can restore the model.
* *
* @param User $user * @param User $user
* @param User $userModel
* @return bool * @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)); 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. * Determine whether the user can attach any role to the user.
* *
+146
View File
@@ -0,0 +1,146 @@
<?php
declare(strict_types=1);
namespace App\Policies;
use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User;
use App\Models\BaseModel;
use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* Class BasePolicy.
*/
abstract class BasePolicy
{
use HandlesAuthorization;
/**
* Get the model class of the policy.
*
* @return class-string
*/
protected static function getModel(): string
{
return Str::of(get_called_class())
->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()));
}
}
+2 -89
View File
@@ -4,98 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Discord; namespace App\Policies\Discord;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
use App\Models\Auth\User;
use App\Models\Discord\DiscordThread;
use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class DiscordThreadPolicy. * 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));
}
} }
+2 -107
View File
@@ -4,116 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Document; namespace App\Policies\Document;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User;
use App\Models\Document\Page;
use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class PagePolicy. * 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));
}
} }
+8 -19
View File
@@ -8,18 +8,18 @@ use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Models\List\ExternalProfileVisibility; use App\Enums\Models\List\ExternalProfileVisibility;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\BaseModel;
use App\Models\List\ExternalProfile; use App\Models\List\ExternalProfile;
use App\Models\List\External\ExternalEntry; use App\Models\List\External\ExternalEntry;
use App\Policies\BasePolicy;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Database\Eloquent\Model;
/** /**
* Class ExternalEntryPolicy. * Class ExternalEntryPolicy.
*/ */
class ExternalEntryPolicy class ExternalEntryPolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
@@ -49,7 +49,7 @@ class ExternalEntryPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function view(?User $user, ExternalEntry $entry): bool public function view(?User $user, BaseModel|Model $entry): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); return $user !== null && $user->hasRole('Admin');
@@ -90,7 +90,7 @@ class ExternalEntryPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function update(User $user, ExternalEntry $entry): bool public function update(User $user, BaseModel|Model $entry): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); return $user !== null && $user->hasRole('Admin');
@@ -111,7 +111,7 @@ class ExternalEntryPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function delete(User $user, ExternalEntry $entry): bool public function delete(User $user, BaseModel|Model $entry): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); return $user !== null && $user->hasRole('Admin');
@@ -132,7 +132,7 @@ class ExternalEntryPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function restore(User $user, ExternalEntry $entry): bool public function restore(User $user, BaseModel|Model $entry): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); 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)); 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));
}
} }
+8 -19
View File
@@ -8,17 +8,17 @@ use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Models\List\ExternalProfileVisibility; use App\Enums\Models\List\ExternalProfileVisibility;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\BaseModel;
use App\Models\List\ExternalProfile; use App\Models\List\ExternalProfile;
use App\Policies\BasePolicy;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Database\Eloquent\Model;
/** /**
* Class ExternalProfilePolicy. * Class ExternalProfilePolicy.
*/ */
class ExternalProfilePolicy class ExternalProfilePolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
@@ -41,7 +41,7 @@ class ExternalProfilePolicy
* @param ExternalProfile $profile * @param ExternalProfile $profile
* @return bool * @return bool
*/ */
public function view(?User $user, ExternalProfile $profile): bool public function view(?User $user, BaseModel|Model $profile): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); return $user !== null && $user->hasRole('Admin');
@@ -74,7 +74,7 @@ class ExternalProfilePolicy
* @param ExternalProfile $profile * @param ExternalProfile $profile
* @return bool * @return bool
*/ */
public function update(User $user, ExternalProfile $profile): bool public function update(User $user, BaseModel|Model $profile): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); return $user !== null && $user->hasRole('Admin');
@@ -90,7 +90,7 @@ class ExternalProfilePolicy
* @param ExternalProfile $profile * @param ExternalProfile $profile
* @return bool * @return bool
*/ */
public function delete(User $user, ExternalProfile $profile): bool public function delete(User $user, BaseModel|Model $profile): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); return $user !== null && $user->hasRole('Admin');
@@ -106,7 +106,7 @@ class ExternalProfilePolicy
* @param ExternalProfile $profile * @param ExternalProfile $profile
* @return bool * @return bool
*/ */
public function restore(User $user, ExternalProfile $profile): bool public function restore(User $user, BaseModel|Model $profile): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole('Admin'); 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)); 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. * Determine whether the user can add a entry to the profile.
* *
@@ -9,18 +9,18 @@ use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Auth\Role as RoleEnum; use App\Enums\Auth\Role as RoleEnum;
use App\Enums\Models\List\PlaylistVisibility; use App\Enums\Models\List\PlaylistVisibility;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\BaseModel;
use App\Models\List\Playlist; use App\Models\List\Playlist;
use App\Models\List\Playlist\PlaylistTrack; use App\Models\List\Playlist\PlaylistTrack;
use App\Policies\BasePolicy;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Database\Eloquent\Model;
/** /**
* Class TrackPolicy. * Class TrackPolicy.
*/ */
class PlaylistTrackPolicy class PlaylistTrackPolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
@@ -50,7 +50,7 @@ class PlaylistTrackPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function view(?User $user, PlaylistTrack $track): bool public function view(?User $user, BaseModel|Model $track): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); return $user !== null && $user->hasRole(RoleEnum::ADMIN->value);
@@ -91,7 +91,7 @@ class PlaylistTrackPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function update(User $user, PlaylistTrack $track): bool public function update(User $user, BaseModel|Model $track): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); return $user !== null && $user->hasRole(RoleEnum::ADMIN->value);
@@ -112,7 +112,7 @@ class PlaylistTrackPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function delete(User $user, PlaylistTrack $track): bool public function delete(User $user, BaseModel|Model $track): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); return $user !== null && $user->hasRole(RoleEnum::ADMIN->value);
@@ -133,7 +133,7 @@ class PlaylistTrackPolicy
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
*/ */
public function restore(User $user, PlaylistTrack $track): bool public function restore(User $user, BaseModel|Model $track): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); 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)); 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));
}
} }
+8 -19
View File
@@ -9,19 +9,19 @@ use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Auth\Role as RoleEnum; use App\Enums\Auth\Role as RoleEnum;
use App\Enums\Models\List\PlaylistVisibility; use App\Enums\Models\List\PlaylistVisibility;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\BaseModel;
use App\Models\List\Playlist; use App\Models\List\Playlist;
use App\Models\Wiki\Image; use App\Models\Wiki\Image;
use App\Pivots\List\PlaylistImage; use App\Pivots\List\PlaylistImage;
use App\Policies\BasePolicy;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Illuminate\Auth\Access\HandlesAuthorization; use Illuminate\Database\Eloquent\Model;
/** /**
* Class PlaylistPolicy. * Class PlaylistPolicy.
*/ */
class PlaylistPolicy class PlaylistPolicy extends BasePolicy
{ {
use HandlesAuthorization;
/** /**
* Determine whether the user can view any models. * Determine whether the user can view any models.
* *
@@ -44,7 +44,7 @@ class PlaylistPolicy
* @param Playlist $playlist * @param Playlist $playlist
* @return bool * @return bool
*/ */
public function view(?User $user, Playlist $playlist): bool public function view(?User $user, BaseModel|Model $playlist): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user !== null && $user->hasRole(RoleEnum::ADMIN->value); return $user !== null && $user->hasRole(RoleEnum::ADMIN->value);
@@ -77,7 +77,7 @@ class PlaylistPolicy
* @param Playlist $playlist * @param Playlist $playlist
* @return bool * @return bool
*/ */
public function update(User $user, Playlist $playlist): bool public function update(User $user, BaseModel|Model $playlist): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user->hasRole(RoleEnum::ADMIN->value); return $user->hasRole(RoleEnum::ADMIN->value);
@@ -93,7 +93,7 @@ class PlaylistPolicy
* @param Playlist $playlist * @param Playlist $playlist
* @return bool * @return bool
*/ */
public function delete(User $user, Playlist $playlist): bool public function delete(User $user, BaseModel|Model $playlist): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user->hasRole(RoleEnum::ADMIN->value); return $user->hasRole(RoleEnum::ADMIN->value);
@@ -109,7 +109,7 @@ class PlaylistPolicy
* @param Playlist $playlist * @param Playlist $playlist
* @return bool * @return bool
*/ */
public function restore(User $user, Playlist $playlist): bool public function restore(User $user, BaseModel|Model $playlist): bool
{ {
if (Filament::isServing()) { if (Filament::isServing()) {
return $user->hasRole(RoleEnum::ADMIN->value); 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)); 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. * Determine whether the user can add a track to the playlist.
* *
+2 -107
View File
@@ -4,116 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Wiki\Anime; namespace App\Policies\Wiki\Anime;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
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;
/** /**
* Class AnimeSynonymPolicy. * 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));
}
} }
+2 -107
View File
@@ -4,116 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Wiki\Anime; namespace App\Policies\Wiki\Anime;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
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;
/** /**
* Class AnimeThemePolicy. * 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));
}
} }
@@ -5,120 +5,17 @@ declare(strict_types=1);
namespace App\Policies\Wiki\Anime\Theme; namespace App\Policies\Wiki\Anime\Theme;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Anime\Theme\AnimeThemeEntry; use App\Models\Wiki\Anime\Theme\AnimeThemeEntry;
use App\Models\Wiki\Video; use App\Models\Wiki\Video;
use App\Pivots\Wiki\AnimeThemeEntryVideo; use App\Pivots\Wiki\AnimeThemeEntryVideo;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class AnimeThemeEntryPolicy. * 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. * Determine whether the user can attach any video to the entry.
* *
+2 -105
View File
@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Anime; use App\Models\Wiki\Anime;
use App\Models\Wiki\Image; use App\Models\Wiki\Image;
@@ -14,115 +13,13 @@ use App\Models\Wiki\Studio;
use App\Pivots\Wiki\AnimeImage; use App\Pivots\Wiki\AnimeImage;
use App\Pivots\Wiki\AnimeSeries; use App\Pivots\Wiki\AnimeSeries;
use App\Pivots\Wiki\AnimeStudio; use App\Pivots\Wiki\AnimeStudio;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class AnimePolicy. * 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. * Determine whether the user can attach any series to the anime.
* *
+2 -105
View File
@@ -5,120 +5,17 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Artist; use App\Models\Wiki\Artist;
use App\Models\Wiki\Image; use App\Models\Wiki\Image;
use App\Pivots\Wiki\ArtistImage; use App\Pivots\Wiki\ArtistImage;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class ArtistPolicy. * 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. * Determine whether the user can attach any resource to the artist.
* *
+2 -105
View File
@@ -5,118 +5,15 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Audio; use App\Models\Wiki\Audio;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class AudioPolicy. * 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. * Determine whether the user can add a video to the audio.
* *
+2 -105
View File
@@ -5,118 +5,15 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\ExternalResource; use App\Models\Wiki\ExternalResource;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class ExternalResourcePolicy. * 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. * Determine whether the user can attach any artist to the resource.
* *
+2 -94
View File
@@ -5,107 +5,15 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Group; use App\Models\Wiki\Group;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class GroupPolicy. * 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. * Determine whether the user can add a theme to the group.
* *
+2 -105
View File
@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Auth\Role as RoleEnum; use App\Enums\Auth\Role as RoleEnum;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\List\Playlist; use App\Models\List\Playlist;
@@ -17,115 +16,13 @@ use App\Pivots\List\PlaylistImage;
use App\Pivots\Wiki\AnimeImage; use App\Pivots\Wiki\AnimeImage;
use App\Pivots\Wiki\ArtistImage; use App\Pivots\Wiki\ArtistImage;
use App\Pivots\Wiki\StudioImage; use App\Pivots\Wiki\StudioImage;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class ImagePolicy. * 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. * Determine whether the user can attach any artist to the image.
* *
+2 -105
View File
@@ -5,120 +5,17 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Anime; use App\Models\Wiki\Anime;
use App\Models\Wiki\Series; use App\Models\Wiki\Series;
use App\Pivots\Wiki\AnimeSeries; use App\Pivots\Wiki\AnimeSeries;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class SeriesPolicy. * 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. * Determine whether the user can attach any anime to the series.
* *
+2 -105
View File
@@ -5,118 +5,15 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Song; use App\Models\Wiki\Song;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class SongPolicy. * 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. * Determine whether the user can add a theme to the song.
* *
+2 -105
View File
@@ -5,122 +5,19 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Anime; use App\Models\Wiki\Anime;
use App\Models\Wiki\Image; use App\Models\Wiki\Image;
use App\Models\Wiki\Studio; use App\Models\Wiki\Studio;
use App\Pivots\Wiki\AnimeStudio; use App\Pivots\Wiki\AnimeStudio;
use App\Pivots\Wiki\StudioImage; use App\Pivots\Wiki\StudioImage;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class StudioPolicy. * 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. * Determine whether the user can attach any anime to the studio.
* *
+2 -107
View File
@@ -4,116 +4,11 @@ declare(strict_types=1);
namespace App\Policies\Wiki\Video; namespace App\Policies\Wiki\Video;
use App\Enums\Auth\CrudPermission; use App\Policies\BasePolicy;
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;
/** /**
* Class VideoScriptPolicy. * 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));
}
} }
+2 -105
View File
@@ -5,119 +5,16 @@ declare(strict_types=1);
namespace App\Policies\Wiki; namespace App\Policies\Wiki;
use App\Enums\Auth\CrudPermission; use App\Enums\Auth\CrudPermission;
use App\Enums\Auth\ExtendedCrudPermission;
use App\Enums\Auth\Role as RoleEnum; use App\Enums\Auth\Role as RoleEnum;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Wiki\Video; use App\Models\Wiki\Video;
use Filament\Facades\Filament; use App\Policies\BasePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
/** /**
* Class VideoPolicy. * 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. * Determine whether the user can attach any entry to a video.
* *
+3
View File
@@ -22,6 +22,9 @@ use Illuminate\Support\Facades\Config;
use Illuminate\View\Middleware\ShareErrorsFromSession; use Illuminate\View\Middleware\ShareErrorsFromSession;
use Leandrocfe\FilamentApexCharts\FilamentApexChartsPlugin; use Leandrocfe\FilamentApexCharts\FilamentApexChartsPlugin;
/**
* Class FilamentPanelProvider.
*/
class FilamentPanelProvider extends PanelProvider class FilamentPanelProvider extends PanelProvider
{ {
public function panel(Panel $panel): Panel public function panel(Panel $panel): Panel
+1
View File
@@ -27,6 +27,7 @@
"babenkoivan/elastic-migrations": "^3.3", "babenkoivan/elastic-migrations": "^3.3",
"babenkoivan/elastic-scout-driver-plus": "^4.3", "babenkoivan/elastic-scout-driver-plus": "^4.3",
"bepsvpt/secure-headers": "^7.4", "bepsvpt/secure-headers": "^7.4",
"bezhansalleh/filament-exceptions": "^2.1",
"cyrildewit/eloquent-viewable": "^7.0", "cyrildewit/eloquent-viewable": "^7.0",
"fakerphp/faker": "^1.21", "fakerphp/faker": "^1.21",
"filament/filament": "3.2", "filament/filament": "3.2",
Generated
+384 -307
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c7d34b5fdbb2830f142160c61242e4c7", "content-hash": "afa45066fd7c02b838003727586a268f",
"packages": [ "packages": [
{ {
"name": "anourvalar/eloquent-serialize", "name": "anourvalar/eloquent-serialize",
@@ -715,6 +715,83 @@
], ],
"time": "2023-02-06T13:24:48+00:00" "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", "name": "blade-ui-kit/blade-heroicons",
"version": "2.3.0", "version": "2.3.0",
@@ -7255,6 +7332,68 @@
], ],
"time": "2023-02-14T16:54:54+00:00" "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", "name": "spatie/color",
"version": "1.5.3", "version": "1.5.3",
@@ -7377,6 +7516,158 @@
], ],
"time": "2023-05-02T11:05:31+00:00" "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", "name": "spatie/invade",
"version": "2.0.0", "version": "2.0.0",
@@ -7436,6 +7727,98 @@
], ],
"time": "2023-07-19T18:55:36+00:00" "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", "name": "spatie/laravel-package-tools",
"version": "1.16.4", "version": "1.16.4",
@@ -13163,312 +13546,6 @@
], ],
"time": "2023-02-07T11:34:05+00:00" "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", "name": "symfony/yaml",
"version": "v6.4.3", "version": "v6.4.3",
+61
View File
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
use BezhanSalleh\FilamentExceptions\Models\Exception;
return [
'exception_model' => 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(),
];
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('filament_exceptions_table')) {
Schema::create('filament_exceptions_table', function (Blueprint $table) {
$table->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');
}
};
+3 -1
View File
@@ -85,7 +85,7 @@ return [
'name' => 'Upload Audio', 'name' => 'Upload Audio',
], ],
'attach_related_videos' => [ 'attach_related_videos' => [
'name' => 'Attach Audio to Related Videos', 'name' => 'Attach to Related Videos',
], ],
], ],
'base' => [ 'base' => [
@@ -458,10 +458,12 @@ return [
'dashboards' => [ 'dashboards' => [
'icon' => [ 'icon' => [
'admin' => 'heroicon-m-chart-bar', 'admin' => 'heroicon-m-chart-bar',
'dev' => 'heroicon-m-code-bracket',
'wiki' => 'heroicon-m-chart-bar', 'wiki' => 'heroicon-m-chart-bar',
], ],
'label' => [ 'label' => [
'admin' => 'Admin', 'admin' => 'Admin',
'dev' => 'Developer',
'wiki' => 'Wiki', 'wiki' => 'Wiki',
], ],
], ],
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
return [
'labels' => [
'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',
],
];
File diff suppressed because one or more lines are too long
@@ -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, "&amp;")
.replace(/</g, "&lt;")
.replace(/\u00a0/g, " ");
},
type: function (e) {
return Object.prototype.toString
.call(e)
.match(/\[object (\w+)\]/)[1];
},
objId: function (e) {
return (
e.__id ||
Object.defineProperty(e, "__id", {
value: ++t,
}),
e.__id
);
},
clone: function (e) {
var t = n.util.type(e);
switch (t) {
case "Object":
var a = {};
for (var r in e)
e.hasOwnProperty(r) &&
(a[r] = n.util.clone(e[r]));
return a;
case "Array":
return (
e.map &&
e.map(function (e) {
return n.util.clone(e);
})
);
}
return e;
},
},
languages: {
extend: function (e, t) {
var a = n.util.clone(n.languages[e]);
for (var r in t) a[r] = t[r];
return a;
},
insertBefore: function (e, t, a, r) {
r = r || n.languages;
var i = r[e];
if (2 == arguments.length) {
a = arguments[1];
for (var l in a)
a.hasOwnProperty(l) && (i[l] = a[l]);
return i;
}
var o = {};
for (var s in i)
if (i.hasOwnProperty(s)) {
if (s == t)
for (var l in a)
a.hasOwnProperty(l) && (o[l] = a[l]);
o[s] = i[s];
}
return (
n.languages.DFS(n.languages, function (t, n) {
n === r[e] && t != e && (this[t] = o);
}),
(r[e] = o)
);
},
DFS: function (e, t, a, r) {
r = r || {};
for (var i in e)
e.hasOwnProperty(i) &&
(t.call(e, i, e[i], a || i),
"Object" !== n.util.type(e[i]) ||
r[n.util.objId(e[i])]
? "Array" !== n.util.type(e[i]) ||
r[n.util.objId(e[i])] ||
((r[n.util.objId(e[i])] = !0),
n.languages.DFS(e[i], t, i, r))
: ((r[n.util.objId(e[i])] = !0),
n.languages.DFS(e[i], t, null, r)));
},
},
plugins: {},
highlightAll: function (e, t) {
var a = {
callback: t,
selector:
'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code',
};
n.hooks.run("before-highlightall", a);
for (
var r,
i =
a.elements ||
document.querySelectorAll(a.selector),
l = 0;
(r = i[l++]);
)
n.highlightElement(r, e === !0, a.callback);
},
highlightElement: function (t, a, r) {
for (var i, l, o = t; o && !e.test(o.className); )
o = o.parentNode;
o &&
((i = (o.className.match(e) || [
,
"",
])[1].toLowerCase()),
(l = n.languages[i])),
(t.className =
t.className.replace(e, "").replace(/\s+/g, " ") +
" language-" +
i),
(o = t.parentNode),
/pre/i.test(o.nodeName) &&
(o.className =
o.className
.replace(e, "")
.replace(/\s+/g, " ") +
" language-" +
i);
var s = t.textContent,
u = { element: t, language: i, grammar: l, code: s };
if (
(n.hooks.run("before-sanity-check", u),
!u.code || !u.grammar)
)
return n.hooks.run("complete", u), void 0;
if (
(n.hooks.run("before-highlight", u), a && _self.Worker)
) {
var g = new Worker(n.filename);
(g.onmessage = function (e) {
(u.highlightedCode = e.data),
n.hooks.run("before-insert", u),
(u.element.innerHTML = u.highlightedCode),
r && r.call(u.element),
n.hooks.run("after-highlight", u),
n.hooks.run("complete", u);
}),
g.postMessage(
JSON.stringify({
language: u.language,
code: u.code,
immediateClose: !0,
})
);
} else
(u.highlightedCode = n.highlight(
u.code,
u.grammar,
u.language
)),
n.hooks.run("before-insert", u),
(u.element.innerHTML = u.highlightedCode),
r && r.call(t),
n.hooks.run("after-highlight", u),
n.hooks.run("complete", u);
},
highlight: function (e, t, r) {
var i = n.tokenize(e, t);
return a.stringify(n.util.encode(i), r);
},
tokenize: function (e, t) {
var a = n.Token,
r = [e],
i = t.rest;
if (i) {
for (var l in i) t[l] = i[l];
delete t.rest;
}
e: for (var l in t)
if (t.hasOwnProperty(l) && t[l]) {
var o = t[l];
o = "Array" === n.util.type(o) ? o : [o];
for (var s = 0; s < o.length; ++s) {
var u = o[s],
g = u.inside,
c = !!u.lookbehind,
h = !!u.greedy,
f = 0,
d = u.alias;
if (h && !u.pattern.global) {
var p = u.pattern
.toString()
.match(/[imuy]*$/)[0];
u.pattern = RegExp(
u.pattern.source,
p + "g"
);
}
u = u.pattern || u;
for (
var m = 0, y = 0;
m < r.length;
y += r[m].length, ++m
) {
var v = r[m];
if (r.length > 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 +
"</" +
i.tag +
">"
);
}),
!_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,
'<span class="token php">$1</span>'
));
}),
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}|!|=?&lt;|=?&gt;|={1}|(&amp;){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 = "&nbsp;<br />&nbsp;"),
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("<span></span>")),
(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);
}
}
});
})();
@@ -9,6 +9,7 @@ use App\Models\Wiki\Anime;
use App\Models\Wiki\Studio; use App\Models\Wiki\Studio;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Tests\TestCase; 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 * @return void
*/ */
public function testFailParseKitsuIdFromAnimeResource(): void public function testParseKitsuIdForIdFromAnimeResource(): void
{ {
Http::fake([ $id = $this->faker->randomDigitNotNull();
'https://kitsu.io/api/graphql' => Http::response([
$this->faker->word() => $this->faker->word(),
]),
]);
$link = ResourceSite::KITSU->formatResourceLink(Anime::class, $link = ResourceSite::KITSU->formatResourceLink(Anime::class, $id);
$this->faker->randomDigitNotNull(),
$this->faker->slug()
);
static::assertEmpty(ResourceSite::parseIdFromLink($link)); static::assertEquals($id, ResourceSite::parseIdFromLink($link));
Http::assertSentCount(1);
} }
/** /**
* 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 * @return void
*/ */
public function testParseKitsuIdFromAnimeResource(): void public function testParseKitsuIdForSlugFromAnimeResource(): void
{ {
$id = $this->faker->randomDigitNotNull(); $id = $this->faker->randomDigitNotNull();
$slug = $this->faker->slug();
$linkWithSlug = Str::of(ResourceSite::KITSU->formatResourceLink(Anime::class, $id))
->replace(strval($id), $slug)
->__toString();
Http::fake([ Http::fake([
'https://kitsu.io/api/graphql' => Http::response([ '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($linkWithSlug));
static::assertEquals(strval($id), ResourceSite::parseIdFromLink($link));
Http::assertSentCount(1); Http::assertSentCount(1);
} }
} }