feat(filament): added queries for auth actions (#871)

This commit is contained in:
Kyrch
2025-07-14 03:26:26 -03:00
committed by GitHub
parent b24dfebbf3
commit 7afa555e2a
62 changed files with 270 additions and 218 deletions
+2 -2
View File
@@ -34,7 +34,7 @@ class DiscordMessageAction
*/
public function makeMessage(array $fields): DiscordMessage
{
$message = DiscordMessage::fromArray($fields);
$message = DiscordMessage::from($fields);
if (Arr::has($fields, DiscordMessage::ATTRIBUTE_URL)) {
$url = Arr::get($fields, DiscordMessage::ATTRIBUTE_URL);
@@ -67,7 +67,7 @@ class DiscordMessageAction
->throw()
->json();
return DiscordMessage::fromArray(Arr::get($message, 'message'));
return DiscordMessage::from(Arr::get($message, 'message'));
}
/**
+1 -1
View File
@@ -17,7 +17,7 @@ trait HasTabs
* @param class-string<BaseTab>[] $tabClasses
* @return array
*/
public function toArray(array $tabClasses): array
public function toArray(array $tabClasses = []): array
{
$tabs = [];
+3 -3
View File
@@ -25,9 +25,9 @@ trait ResolvesArguments
{
if (filled($arguments)) {
return Str::of('(')
->append(implode("\n", Arr::flatten($arguments)))
->append(implode(PHP_EOL, Arr::flatten($arguments)))
->append(')')
->toString();
->__toString();
}
return '';
@@ -45,7 +45,7 @@ trait ResolvesArguments
->map(function (Field $field) {
if ($field instanceof FilterableField) {
return collect($field->filterDirectives())
->map(fn (FilterDirective $directive) => $directive->toString())
->map(fn (FilterDirective $directive) => $directive->__toString())
->toArray();
}
})
+4 -3
View File
@@ -4,12 +4,13 @@ declare(strict_types=1);
namespace App\Discord;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
/**
* Class DiscordEmbed.
*/
class DiscordEmbed
class DiscordEmbed implements Arrayable
{
final public const ATTRIBUTE_TYPE = 'type';
final public const ATTRIBUTE_TITLE = 'title';
@@ -33,7 +34,7 @@ class DiscordEmbed
* @param array<string, mixed> $array
* @return DiscordEmbed
*/
public static function fromArray(array $array): DiscordEmbed
public static function from(array $array): DiscordEmbed
{
return new DiscordEmbed()
->setType(Arr::get($array, self::ATTRIBUTE_TYPE) ?? 'rich')
@@ -42,7 +43,7 @@ class DiscordEmbed
->setColor(Arr::get($array, self::ATTRIBUTE_COLOR) ?? 0)
->setThumbnail(Arr::get($array, self::ATTRIBUTE_THUMBNAIL) ?? [])
->setImage(Arr::get($array, self::ATTRIBUTE_IMAGE) ?? [])
->setFields(Arr::map(Arr::get($array, self::ATTRIBUTE_FIELDS) ?? [], fn (array $fields) => DiscordEmbedField::fromArray($fields)));
->setFields(Arr::map(Arr::get($array, self::ATTRIBUTE_FIELDS) ?? [], fn (array $fields) => DiscordEmbedField::from($fields)));
}
/**
+1 -1
View File
@@ -49,7 +49,7 @@ class DiscordEmbedField implements Arrayable, JsonSerializable
* @param array<string, mixed> $array
* @return static
*/
public static function fromArray(array $array): static
public static function from(array $array): static
{
return new static(
Arr::get($array, 'name'),
+4 -3
View File
@@ -4,12 +4,13 @@ declare(strict_types=1);
namespace App\Discord;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
/**
* Class DiscordMessage.
*/
class DiscordMessage
class DiscordMessage implements Arrayable
{
final public const ATTRIBUTE_CHANNEL_ID = 'channelId';
final public const ATTRIBUTE_ID = 'id';
@@ -30,13 +31,13 @@ class DiscordMessage
* @param array<string, mixed> $array
* @return DiscordMessage
*/
public static function fromArray(array $array): DiscordMessage
public static function from(array $array): DiscordMessage
{
return new DiscordMessage()
->setChannelId(Arr::get($array, self::ATTRIBUTE_CHANNEL_ID) ?? '0')
->setId(Arr::get($array, self::ATTRIBUTE_ID) ?? '0')
->setContent(Arr::get($array, self::ATTRIBUTE_CONTENT) ?? '')
->setEmbeds(Arr::map(Arr::get($array, self::ATTRIBUTE_EMBEDS) ?? [], fn (array $embed) => DiscordEmbed::fromArray($embed)))
->setEmbeds(Arr::map(Arr::get($array, self::ATTRIBUTE_EMBEDS) ?? [], fn (array $embed) => DiscordEmbed::from($embed)))
->setImages(Arr::get($array, 'files') ?? Arr::get($array, self::ATTRIBUTE_IMAGES) ?? []);
}
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class GiveRoleAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class GiveRoleAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$roles = Role::all([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
$roles = Role::query()
->whereDoesntHave(Role::RELATION_PERMISSIONS, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
->keyBy(Role::ATTRIBUTE_ID)
->map(fn (Role $role) => $role->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class RevokeRoleAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class RevokeRoleAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$roles = Role::all([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
$roles = Role::query()
->whereHas(Role::RELATION_PERMISSIONS, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
->keyBy(Role::ATTRIBUTE_ID)
->map(fn (Role $role) => $role->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class GivePermissionAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class GivePermissionAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$permissions = Permission::all([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
$permissions = Permission::query()
->whereDoesntHave(Permission::RELATION_ROLES, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
->keyBy(Permission::ATTRIBUTE_ID)
->map(fn (Permission $permission) => $permission->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class RevokePermissionAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class RevokePermissionAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$permissions = Permission::all([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
$permissions = Permission::query()
->whereHas(Permission::RELATION_ROLES, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
->keyBy(Permission::ATTRIBUTE_ID)
->map(fn (Permission $permission) => $permission->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Permission;
use App\Models\Auth\User;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class GivePermissionAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class GivePermissionAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$permissions = Permission::all([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
$permissions = Permission::query()
->whereDoesntHave(Permission::RELATION_USERS, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
->keyBy(Permission::ATTRIBUTE_ID)
->map(fn (Permission $permission) => $permission->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class GiveRoleAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class GiveRoleAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$roles = Role::all([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
$roles = Role::query()
->whereDoesntHave(Role::RELATION_USERS, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
->keyBy(Role::ATTRIBUTE_ID)
->map(fn (Role $role) => $role->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Permission;
use App\Models\Auth\User;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class RevokePermissionAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class RevokePermissionAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$permissions = Permission::all([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
$permissions = Permission::query()
->whereHas(Permission::RELATION_USERS, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Permission::ATTRIBUTE_ID, Permission::ATTRIBUTE_NAME])
->keyBy(Permission::ATTRIBUTE_ID)
->map(fn (Permission $permission) => $permission->name)
->toArray();
@@ -9,6 +9,7 @@ use App\Filament\Components\Fields\Select;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use Filament\Schemas\Schema;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
/**
@@ -57,7 +58,7 @@ class RevokeRoleAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -66,7 +67,9 @@ class RevokeRoleAction extends BaseAction
*/
public function getSchema(Schema $schema): Schema
{
$roles = Role::all([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
$roles = Role::query()
->whereHas(Role::RELATION_USERS, fn (Builder $query) => $query->whereKey($this->getRecord()->getKey()))
->get([Role::ATTRIBUTE_ID, Role::ATTRIBUTE_NAME])
->keyBy(Role::ATTRIBUTE_ID)
->map(fn (Role $role) => $role->name)
->toArray();
@@ -67,7 +67,7 @@ class DiscordEditMessageAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -64,7 +64,7 @@ class DiscordSendMessageAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -111,7 +111,7 @@ class BackfillAnimeAction extends BaseAction implements ShouldQueue
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema|null
@@ -205,29 +205,29 @@ class BackfillAnimeAction extends BaseAction implements ShouldQueue
/**
* Get what should be backfilled.
*
* @param array<string, mixed> $fields
* @param array<string, mixed> $components
* @return array<string, array<int, ResourceSite|ImageFacet>|bool>
*/
protected function getToBackfill(array $fields): array
protected function getToBackfill(array $components): array
{
$toBackfill = [];
$toBackfill[self::RESOURCES] = [];
$toBackfill[self::IMAGES] = [];
foreach ($this->getResourcesMapping() as $field => $sites) {
if (Arr::get($fields, $field) === true) {
foreach ($this->getResourcesMapping() as $component => $sites) {
if (Arr::get($components, $component) === true) {
$toBackfill[self::RESOURCES] = array_merge($toBackfill[self::RESOURCES], $sites);
}
}
foreach ($this->getImagesMapping() as $field => $facets) {
if (Arr::get($fields, $field) === true) {
foreach ($this->getImagesMapping() as $component => $facets) {
if (Arr::get($components, $component) === true) {
$toBackfill[self::IMAGES] = array_merge($toBackfill[self::IMAGES], $facets);
}
}
$toBackfill[self::STUDIOS] = Arr::get($fields, self::BACKFILL_STUDIOS);
$toBackfill[self::SYNONYMS] = Arr::get($fields, self::BACKFILL_SYNONYMS);
$toBackfill[self::STUDIOS] = Arr::get($components, self::BACKFILL_STUDIOS);
$toBackfill[self::SYNONYMS] = Arr::get($components, self::BACKFILL_SYNONYMS);
return $toBackfill;
}
@@ -54,7 +54,7 @@ class DiscordThreadAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -45,14 +45,14 @@ abstract class AttachResourceAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema|null
*/
public function getSchema(Schema $schema): ?Schema
{
$fields = [];
$components = [];
$model = $this->getRecord();
if (! ($model instanceof HasResources)) {
@@ -72,7 +72,7 @@ abstract class AttachResourceAction extends BaseAction
$resourceSiteLower = Str::lower($resourceSite->name);
$fields[] = TextInput::make($resourceSite->name)
$components[] = TextInput::make($resourceSite->name)
->label($resourceSite->localize())
->helperText(__("filament.actions.models.wiki.attach_resource.fields.{$resourceSiteLower}.help"))
->url()
@@ -81,7 +81,7 @@ abstract class AttachResourceAction extends BaseAction
}
return $schema
->components($fields);
->components($components);
}
/**
@@ -78,17 +78,17 @@ class AttachImageAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
*/
public function getSchema(Schema $schema): Schema
{
$fields = [];
$components = [];
foreach ($this->facets as $facet) {
$fields[] = FileUpload::make($facet->name)
$components[] = FileUpload::make($facet->name)
->label($facet->localize())
->helperText(__('filament.actions.models.wiki.attach_image.help'))
->imageCropAspectRatio('2:3')
@@ -99,7 +99,7 @@ class AttachImageAction extends BaseAction
}
return $schema
->components($fields);
->components($components);
}
/**
@@ -76,7 +76,7 @@ class UploadImageAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -98,7 +98,7 @@ class BackfillStudioAction extends BaseAction implements ShouldQueue
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -124,16 +124,16 @@ class BackfillStudioAction extends BaseAction implements ShouldQueue
/**
* Get what should be backfilled.
*
* @param array<string, mixed> $fields
* @param array<string, mixed> $components
* @return array<string, ImageFacet[]>
*/
protected function getToBackfill(array $fields): array
protected function getToBackfill(array $components): array
{
$toBackfill = [];
$toBackfill[self::IMAGES] = [];
foreach ($this->getImagesMapping() as $field => $facets) {
if (Arr::get($fields, $field) === true) {
foreach ($this->getImagesMapping() as $component => $facets) {
if (Arr::get($components, $component) === true) {
$toBackfill[self::IMAGES] = array_merge($toBackfill[self::IMAGES], $facets);
}
}
@@ -91,7 +91,7 @@ class BackfillAudioAction extends BaseAction implements ShouldQueue
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -18,14 +18,14 @@ abstract class ReconcileAction extends BaseAction
/**
* Perform the action on the given models.
*
* @param array $fields
* @param array<string, mixed> $data
* @return void
*
* @throws Exception
*/
public function handle(array $fields): void
public function handle(array $data): void
{
$result = $this->reconcileRepositories($fields);
$result = $this->reconcileRepositories($data);
$result->toLog();
}
@@ -44,7 +44,7 @@ class ReconcileDumpAction extends ReconcileStorageAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -53,7 +53,7 @@ abstract class ReconcileStorageAction extends ReconcileAction implements Interac
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -40,14 +40,14 @@ abstract class DumpAction extends BaseAction
/**
* Perform the action on the given models.
*
* @param array $fields
* @param array<string, mixed> $data
* @return void
*
* @throws Exception
*/
public function handle(array $fields): void
public function handle(array $data): void
{
$action = $this->storageAction($fields);
$action = $this->storageAction($data);
$result = $action->handle();
@@ -55,7 +55,7 @@ abstract class DumpAction extends BaseAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -171,8 +171,8 @@ abstract class DumpAction extends BaseAction
/**
* Get the underlying action.
*
* @param array $fields
* @param array<string, mixed> $data
* @return DumpDatabase
*/
abstract protected function storageAction(array $fields): DumpDatabase;
abstract protected function storageAction(array $data): DumpDatabase;
}
@@ -37,11 +37,11 @@ class DumpDocumentAction extends DumpAction
/**
* Get the underlying action.
*
* @param array $fields
* @param array<string, mixed> $data
* @return DumpDatabase
*/
protected function storageAction(array $fields): DumpDatabase
protected function storageAction(array $data): DumpDatabase
{
return new DumpDocumentDatabase($fields);
return new DumpDocumentDatabase($data);
}
}
@@ -37,11 +37,11 @@ class DumpWikiAction extends DumpAction
/**
* Get the underlying action.
*
* @param array $fields
* @param array<string, mixed> $data
* @return DumpDatabase
*/
protected function storageAction(array $fields): DumpDatabase
protected function storageAction(array $data): DumpDatabase
{
return new DumpWikiDatabase($fields);
return new DumpWikiDatabase($data);
}
}
@@ -43,13 +43,13 @@ class PruneDumpAction extends PruneAction
/**
* Get the underlying storage action.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return PruneDump
*/
protected function storageAction(?Model $model, array $fields): PruneDump
protected function storageAction(?Model $record, array $data): PruneDump
{
$hours = Arr::get($fields, 'hours');
$hours = Arr::get($data, 'hours');
return new PruneDump(intval($hours));
}
@@ -31,9 +31,9 @@ abstract class DeleteAction extends StorageAction
/**
* Get the underlying storage action.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return BaseDeleteAction
*/
abstract protected function storageAction(?Model $model, array $fields): StorageActionContract;
abstract protected function storageAction(?Model $record, array $data): StorageActionContract;
}
@@ -32,7 +32,7 @@ abstract class MoveAction extends StorageAction implements InteractsWithDisk
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -61,11 +61,11 @@ abstract class MoveAction extends StorageAction implements InteractsWithDisk
/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @param Model $record
* @param array<string, mixed> $data
* @return BaseMoveAction
*/
abstract protected function storageAction(?Model $model, array $fields): StorageActionContract;
abstract protected function storageAction(?Model $record, array $data): StorageActionContract;
/**
* Resolve the default value for the path field.
@@ -28,7 +28,7 @@ abstract class PruneAction extends StorageAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -49,9 +49,9 @@ abstract class PruneAction extends StorageAction
/**
* Get the underlying storage action.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return BasePruneAction
*/
abstract protected function storageAction(?Model $model, array $fields): BasePruneAction;
abstract protected function storageAction(?Model $record, array $data): BasePruneAction;
}
@@ -34,7 +34,7 @@ abstract class UploadAction extends StorageAction implements InteractsWithDisk
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -45,34 +45,35 @@ abstract class UploadAction extends StorageAction implements InteractsWithDisk
{
$fs = Storage::disk($this->disk());
return $schema->components([
FileUpload::make('file')
->label(__('filament.actions.storage.upload.fields.file.name'))
->helperText(__('filament.actions.storage.upload.fields.file.help'))
->required()
->live(true)
->rules($this->fileRules())
->preserveFilenames()
->storeFiles(false),
return $schema
->components([
FileUpload::make('file')
->label(__('filament.actions.storage.upload.fields.file.name'))
->helperText(__('filament.actions.storage.upload.fields.file.help'))
->required()
->live(true)
->rules($this->fileRules())
->preserveFilenames()
->storeFiles(false),
TextInput::make('path')
->label(__('filament.actions.storage.upload.fields.path.name'))
->helperText(__('filament.actions.storage.upload.fields.path.help'))
->doesntStartWith('/')
->doesntEndWith('/')
->rule(new StorageDirectoryExistsRule($fs))
->hidden(fn ($livewire) => $livewire instanceof VideoEntryRelationManager || $livewire instanceof ScriptVideoRelationManager),
]);
TextInput::make('path')
->label(__('filament.actions.storage.upload.fields.path.name'))
->helperText(__('filament.actions.storage.upload.fields.path.help'))
->doesntStartWith('/')
->doesntEndWith('/')
->rule(new StorageDirectoryExistsRule($fs))
->hidden(fn ($livewire) => $livewire instanceof VideoEntryRelationManager || $livewire instanceof ScriptVideoRelationManager),
]);
}
/**
* Get the underlying storage action.
*
* @param Model|null $record
* @param array $fields
* @param array<string, mixed> $data
* @return BaseUploadAction
*/
abstract protected function storageAction(?Model $record, array $fields): BaseUploadAction;
abstract protected function storageAction(?Model $record, array $data): BaseUploadAction;
/**
* Get the file validation rules.
@@ -49,13 +49,13 @@ class MoveAllAction extends BaseAction
$this->label(__('filament.actions.base.move_all'));
$this->icon(__('filament-icons.actions.base.move_all'));
$this->visible(Gate::allows('create', [Audio::class, Video::class, VideoScript::class]));
$this->visible(Gate::any('create', [Audio::class, Video::class, VideoScript::class]));
$this->action(fn (array $data) => $this->handle($data));
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -106,14 +106,14 @@ class MoveAllAction extends BaseAction
/**
* Handle the action.
*
* @param array $fields
* @param array<string, mixed> $data
* @return void
*/
public function handle(array $fields): void
public function handle(array $data): void
{
$videoPath = Arr::get($fields, 'video');
$audioPath = Arr::get($fields, 'audio');
$scriptPath = Arr::get($fields, 'script');
$videoPath = Arr::get($data, 'video');
$audioPath = Arr::get($data, 'audio');
$scriptPath = Arr::get($data, 'script');
if (is_string($videoPath)) {
$action = new MoveVideoAction($this->getVideo(), $videoPath);
+16 -16
View File
@@ -30,37 +30,37 @@ abstract class StorageAction extends BaseAction
/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @param Model $record
* @param array<string, mixed> $data
* @return BaseStorageAction
*/
abstract protected function storageAction(Model $model, array $fields): BaseStorageAction;
abstract protected function storageAction(Model $record, array $data): BaseStorageAction;
/**
* Run this after the video is uploaded.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return void
*/
protected function afterUploaded(?Model $model, array $fields): void {}
protected function afterUploaded(?Model $record, array $data): void {}
/**
* Perform the action on the given models.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return void
*/
public function handle(?Model $model, array $fields): void
public function handle(?Model $record, array $data): void
{
$action = $this->storageAction($model, $fields);
$action = $this->storageAction($record, $data);
$storageResults = $action->handle();
$storageResults->toLog();
$model ??= $action->then($storageResults);
$record ??= $action->then($storageResults);
$actionResult = $storageResults->toActionResult();
@@ -70,23 +70,23 @@ abstract class StorageAction extends BaseAction
return;
}
$this->afterUploaded($model, $fields);
$this->afterUploaded($record, $data);
$livewire = $this->getLivewire();
if ($livewire instanceof BaseRelationManager && $model instanceof Model) {
if ($livewire instanceof BaseRelationManager && $record instanceof Model) {
$relation = $livewire->getRelationship();
$pivot = $model;
$pivot = $record;
if ($relation instanceof BelongsToMany) {
$pivotClass = $relation->getPivotClass();
$pivot = $pivotClass::query()
->where($livewire->getOwnerRecord()->getKeyName(), $livewire->getOwnerRecord()->getKey())
->where($model->getKeyName(), $model->getKey())
->where($record->getKeyName(), $record->getKey())
->first();
}
$this->updateLog($model, $pivot);
$this->updateLog($record, $pivot);
}
}
}
@@ -36,17 +36,17 @@ class DeleteAudioAction extends DeleteAction
$this->label(__('filament.actions.audio.delete.name'));
$this->visible(Gate::allows('forcedelete', Audio::class));
$this->visible(Gate::allows('forceDelete', Audio::class));
}
/**
* Get the underlying storage action.
*
* @param Audio $audio
* @param array $fields
* @param array<string, mixed> $data
* @return DeleteAudio
*/
protected function storageAction(?Model $audio, array $fields): DeleteAudio
protected function storageAction(?Model $audio, array $data): DeleteAudio
{
return new DeleteAudio($audio);
}
@@ -46,13 +46,13 @@ class MoveAudioAction extends MoveAction
* Get the underlying storage action.
*
* @param Audio $audio
* @param array $fields
* @param array<string, mixed> $data
* @return MoveAudio
*/
protected function storageAction(?Model $audio, array $fields): MoveAudio
protected function storageAction(?Model $audio, array $data): MoveAudio
{
/** @var string $path */
$path = Arr::get($fields, 'path');
$path = Arr::get($data, 'path');
return new MoveAudio($audio, $path);
}
@@ -61,16 +61,17 @@ class UploadAudioAction extends UploadAction
/**
* Get the underlying storage action.
*
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return UploadAudio
*/
protected function storageAction(?Model $model, array $fields): UploadAudio
protected function storageAction(?Model $record, array $data): UploadAudio
{
/** @var UploadedFile $file */
$file = Arr::get($fields, 'file');
$file = Arr::get($data, 'file');
/** @var string $path */
$path = Arr::get($fields, 'path');
$path = Arr::get($data, 'path');
return new UploadAudio($file, $path);
}
@@ -47,13 +47,13 @@ class MoveImageAction extends MoveAction
* Get the underlying storage action.
*
* @param Image $image
* @param array $fields
* @param array<string, mixed> $data
* @return MoveImage
*/
protected function storageAction(?Model $image, array $fields): MoveImage
protected function storageAction(?Model $image, array $data): MoveImage
{
/** @var string $path */
$path = Arr::get($fields, 'path');
$path = Arr::get($data, 'path');
return new MoveImage($image, $path);
}
@@ -36,17 +36,17 @@ class DeleteVideoAction extends DeleteAction
$this->label(__('filament.actions.video.delete.name'));
$this->visible(Gate::allows('forcedelete', Video::class));
$this->visible(Gate::allows('forceDelete', Video::class));
}
/**
* Get the underlying storage action.
*
* @param Video $video
* @param array $fields
* @param array<string, mixed> $data
* @return DeleteVideo
*/
protected function storageAction(?Model $video, array $fields): DeleteVideo
protected function storageAction(?Model $video, array $data): DeleteVideo
{
return new DeleteVideo($video);
}
@@ -46,13 +46,13 @@ class MoveVideoAction extends MoveAction
* Get the underlying storage action.
*
* @param Video $video
* @param array $fields
* @param array<string, mixed> $data
* @return MoveVideo
*/
protected function storageAction(?Model $video, array $fields): MoveVideo
protected function storageAction(?Model $video, array $data): MoveVideo
{
/** @var string $path */
$path = Arr::get($fields, 'path');
$path = Arr::get($data, 'path');
return new MoveVideo($video, $path);
}
@@ -43,10 +43,10 @@ class DeleteScriptAction extends DeleteAction
* Get the underlying storage action.
*
* @param VideoScript $script
* @param array $fields
* @param array<string, mixed> $data
* @return DeleteScript
*/
protected function storageAction(?Model $script, array $fields): DeleteScript
protected function storageAction(?Model $script, array $data): DeleteScript
{
return new DeleteScript($script);
}
@@ -46,13 +46,13 @@ class MoveScriptAction extends MoveAction
* Get the underlying storage action.
*
* @param VideoScript $script
* @param array $fields
* @param array<string, mixed> $data
* @return MoveScript
*/
protected function storageAction(?Model $script, array $fields): MoveScript
protected function storageAction(?Model $script, array $data): MoveScript
{
/** @var string $path */
$path = Arr::get($fields, 'path');
$path = Arr::get($data, 'path');
return new MoveScript($script, $path);
}
@@ -50,7 +50,7 @@ class UploadScriptAction extends UploadAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -72,17 +72,17 @@ class UploadScriptAction extends UploadAction
/**
* Get the underlying storage action.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return UploadScript
*/
protected function storageAction(?Model $model, array $fields): UploadScript
protected function storageAction(?Model $record, array $data): UploadScript
{
/** @var UploadedFile $file */
$file = Arr::get($fields, 'file');
$file = Arr::get($data, 'file');
/** @var Video|null $video */
$video = Video::query()->find(Arr::get($fields, Video::ATTRIBUTE_ID));
$video = Video::query()->find(Arr::get($data, Video::ATTRIBUTE_ID));
$path = explode($video->filename, $video->path())[0];
@@ -89,7 +89,7 @@ class UploadVideoAction extends UploadAction
}
/**
* Get the fields available on the action.
* Get the schema available on the action.
*
* @param Schema $schema
* @return Schema
@@ -197,26 +197,26 @@ class UploadVideoAction extends UploadAction
/**
* Get the underlying storage action.
*
* @param Model|null $model
* @param array $fields
* @param Model|null $record
* @param array<string, mixed> $data
* @return UploadVideo
*/
protected function storageAction(?Model $model, array $fields): UploadVideo
protected function storageAction(?Model $record, array $data): UploadVideo
{
/** @var string|null $path */
$path = Arr::get($fields, 'path');
$path = Arr::get($data, 'path');
/** @var UploadedFile $file */
$file = Arr::get($fields, 'file');
$file = Arr::get($data, 'file');
/** @var AnimeThemeEntry|null $entry */
$entry = AnimeThemeEntry::query()->find(Arr::get($fields, AnimeThemeEntry::ATTRIBUTE_ID));
$entry = AnimeThemeEntry::query()->find(Arr::get($data, AnimeThemeEntry::ATTRIBUTE_ID));
/** @var UploadedFile|null $script */
$script = Arr::get($fields, 'script');
$script = Arr::get($data, 'script');
/** @var User|null $encoder */
$encoder = User::query()->find(Arr::get($fields, 'encoder'));
$encoder = User::query()->find(Arr::get($data, 'encoder'));
if ($path === null && $entry !== null) {
$anime = $entry->animetheme->anime;
@@ -235,12 +235,12 @@ class UploadVideoAction extends UploadAction
}
$attributes = [
Video::ATTRIBUTE_NC => Arr::get($fields, Video::ATTRIBUTE_NC),
Video::ATTRIBUTE_SUBBED => Arr::get($fields, Video::ATTRIBUTE_SUBBED),
Video::ATTRIBUTE_LYRICS => Arr::get($fields, Video::ATTRIBUTE_LYRICS),
Video::ATTRIBUTE_UNCEN => Arr::get($fields, Video::ATTRIBUTE_UNCEN),
Video::ATTRIBUTE_OVERLAP => Arr::get($fields, Video::ATTRIBUTE_OVERLAP),
Video::ATTRIBUTE_SOURCE => Arr::get($fields, Video::ATTRIBUTE_SOURCE),
Video::ATTRIBUTE_NC => Arr::get($data, Video::ATTRIBUTE_NC),
Video::ATTRIBUTE_SUBBED => Arr::get($data, Video::ATTRIBUTE_SUBBED),
Video::ATTRIBUTE_LYRICS => Arr::get($data, Video::ATTRIBUTE_LYRICS),
Video::ATTRIBUTE_UNCEN => Arr::get($data, Video::ATTRIBUTE_UNCEN),
Video::ATTRIBUTE_OVERLAP => Arr::get($data, Video::ATTRIBUTE_OVERLAP),
Video::ATTRIBUTE_SOURCE => Arr::get($data, Video::ATTRIBUTE_SOURCE),
];
return new UploadVideo($file, $path, $attributes, $entry, $script, $encoder);
+10
View File
@@ -239,6 +239,16 @@ class User extends BaseResource
];
}
/**
* Determine whether the related model can be created.
*
* @return bool
*/
public static function canCreate(): bool
{
return false;
}
/**
* Get the pages available for the resource.
*
@@ -16,12 +16,12 @@ class EqFilterDirective extends FilterDirective
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
return Str::of($this->field->getName())
->append(': ')
->append($this->type->toString())
->append($this->type->__toString())
->append(" @eq(key: \"{$this->field->getColumn()}\")")
->toString();
->__toString();
}
}
@@ -6,11 +6,12 @@ namespace App\GraphQL\Definition\Directives\Filters;
use App\GraphQL\Definition\Fields\Field;
use GraphQL\Type\Definition\Type;
use Stringable;
/**
* Class FilterDirective.
*/
abstract class FilterDirective
abstract class FilterDirective implements Stringable
{
/**
* @param Field $field
@@ -20,11 +21,4 @@ abstract class FilterDirective
protected Field $field,
protected Type $type,
) {}
/**
* Create the argument for the directive.
*
* @return string
*/
abstract public function toString(): string;
}
@@ -16,12 +16,12 @@ class GreaterFilterDirective extends FilterDirective
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
return Str::of($this->field->getName().'_greater')
->append(': ')
->append($this->type->toString())
->append($this->type->__toString())
->append(" @where(operator: \">\", key: \"{$this->field->getColumn()}\")")
->toString();
->__toString();
}
}
@@ -17,12 +17,12 @@ class InFilterDirective extends FilterDirective
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
return Str::of($this->field->getName().'_in')
->append(': ')
->append(Type::listOf($this->type)->toString())
->append(Type::listOf($this->type)->__toString())
->append(" @in(key: \"{$this->field->getColumn()}\")")
->toString();
->__toString();
}
}
@@ -16,12 +16,12 @@ class LesserFilterDirective extends FilterDirective
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
return Str::of($this->field->getName().'_lesser')
->append(': ')
->append($this->type->toString())
->append($this->type->__toString())
->append(" @where(operator: \"<\", key: \"{$this->field->getColumn()}\")")
->toString();
->__toString();
}
}
@@ -16,12 +16,12 @@ class LikeFilterDirective extends FilterDirective
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
return Str::of($this->field->getName().'_like')
->append(': ')
->append($this->type->toString())
->append($this->type->__toString())
->append(" @where(operator: \"like\", key: \"{$this->field->getColumn()}\")")
->toString();
->__toString();
}
}
@@ -17,12 +17,12 @@ class NotInFilterDirective extends FilterDirective
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
return Str::of($this->field->getName().'_not_in')
->append(': ')
->append(Type::listOf($this->type)->toString())
->append(Type::listOf($this->type)->__toString())
->append(" @notIn(key: \"{$this->field->getColumn()}\")")
->toString();
->__toString();
}
}
+4 -3
View File
@@ -10,11 +10,12 @@ use App\Contracts\GraphQL\HasArgumentsField;
use GraphQL\Type\Definition\Type;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Stringable;
/**
* Class Field.
*/
abstract class Field
abstract class Field implements Stringable
{
use ResolvesArguments;
use ResolvesDirectives;
@@ -109,7 +110,7 @@ abstract class Field
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
$string = Str::of($this->getName());
@@ -118,7 +119,7 @@ abstract class Field
}
$string = $string->append(': ')
->append($this->getType()->toString());
->append($this->getType()->__toString());
if ($this->shouldRename()) {
$string = $string->append(" @rename(attribute: {$this->column})");
+1 -1
View File
@@ -42,7 +42,7 @@ abstract class BaseQuery
return "
\"\"\"{$this->description()}\"\"\"
{$this->name}{$arguments}: {$this->getType()->toString()} {$directives}
{$this->name}{$arguments}: {$this->getType()->__toString()} {$directives}
";
}
@@ -8,11 +8,12 @@ use App\Concerns\GraphQL\ResolvesDirectives;
use App\Enums\GraphQL\RelationType;
use GraphQL\Type\Definition\Type;
use Illuminate\Support\Str;
use Stringable;
/**
* Class Relation.
*/
abstract class Relation
abstract class Relation implements Stringable
{
use ResolvesDirectives;
@@ -36,7 +37,7 @@ abstract class Relation
*
* @return string
*/
public function toString(): string
public function __toString(): string
{
$directives = $this->resolveDirectives(
$this->relation()->getDirective([
@@ -47,10 +48,10 @@ abstract class Relation
return Str::of($this->field ?? $this->relationName)
->append(': ')
->append($this->type()->toString())
->append($this->type()->__toString())
->append(' ')
->append($directives)
->toString();
->__toString();
}
/**
+4 -4
View File
@@ -59,21 +59,21 @@ abstract class BaseType extends ObjectType
return Str::of('"')
->append($field->description())
->append('"')
->append("\n")
->append($field->toString())
->newLine()
->append($field->__toString())
->__toString();
});
}
if ($this instanceof HasRelations) {
$fields[] = Arr::map($this->relations(), fn (Relation $relation) => $relation->toString());
$fields[] = Arr::map($this->relations(), fn (Relation $relation) => $relation->__toString());
}
if (blank($fields)) {
throw new RuntimeException("There are no fields for the type {$this->getName()}.");
}
$fieldsString = implode("\n", Arr::flatten($fields));
$fieldsString = implode(PHP_EOL, Arr::flatten($fields));
$directives = '';
if ($this instanceof HasDirectives) {
+1 -1
View File
@@ -38,7 +38,7 @@ abstract class BaseUnion extends UnionType
->append($this->name())
->append(' = ')
->append(implode(' | ', Arr::map($this->types(), fn (BaseType $type) => $type->name())))
->append("\n")
->newLine()
->__toString();
}
+12 -1
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Models\Auth;
use App\Contracts\Models\Nameable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Spatie\Permission\Models\Permission as BasePermission;
@@ -17,7 +18,7 @@ use Spatie\Permission\Models\Permission as BasePermission;
* @property string $name
* @property Carbon $updated_at
*/
class Permission extends BasePermission
class Permission extends BasePermission implements Nameable
{
final public const TABLE = 'permissions';
@@ -29,4 +30,14 @@ class Permission extends BasePermission
final public const RELATION_ROLES = 'roles';
final public const RELATION_USERS = 'users';
/**
* Get name.
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
}
+1 -1
View File
@@ -93,7 +93,7 @@ class Encode extends BaseModel
return Str::of($this->user->getName())
->append(' ')
->append($this->video->getName())
->toString();
->__toString();
}
/**
+8 -1
View File
@@ -40,6 +40,7 @@ use App\Models\Wiki\Song\Performance;
use App\Models\Wiki\Studio;
use App\Models\Wiki\Video;
use App\Models\Wiki\Video\VideoScript;
use Illuminate\Support\Arr;
/**
* Class AdminSeeder.
@@ -110,7 +111,13 @@ class AdminSeeder extends RoleSeeder
$this->configureResource($role, VideoScript::class, $extendedCrudPermissions);
// Special Permissions
$this->configureAbilities($role, array_column(SpecialPermission::cases(), 'value'));
$this->configureAbilities(
$role,
array_column(
Arr::except(SpecialPermission::cases(), [SpecialPermission::BYPASS_AUTHORIZATION]),
'value'
)
);
$role->color = $roleEnum->color();
$role->priority = $roleEnum->priority();