diff --git a/composer.json b/composer.json index 2b40657..55fbedd 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,8 @@ "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/pest --no-coverage", "test-coverage": "vendor/bin/pest --coverage", - "format": "vendor/bin/pint" + "format": "vendor/bin/pint", + "finalize": "composer format && composer analyse && composer test" }, "config": { "sort-packages": true, diff --git a/config/filament-shield.php b/config/filament-shield.php index 5e1ce76..f03d8d7 100644 --- a/config/filament-shield.php +++ b/config/filament-shield.php @@ -83,7 +83,7 @@ ], 'register_role_policy' => [ - 'enabled' => false, + 'enabled' => true, ], ]; diff --git a/resources/ckb/filament-shield.php b/resources/lang/ckb/filament-shield.php similarity index 100% rename from resources/ckb/filament-shield.php rename to resources/lang/ckb/filament-shield.php diff --git a/resources/lang/filament-shield_pt_PT.php b/resources/lang/filament-shield_pt_PT.php deleted file mode 100644 index 3a8f9d8..0000000 --- a/resources/lang/filament-shield_pt_PT.php +++ /dev/null @@ -1,79 +0,0 @@ - 'Nome', - 'column.guard_name' => 'Guard', - 'column.roles' => 'Funções', - 'column.permissions' => 'Permissões', - 'column.updated_at' => 'Alterado em', - - /* - |-------------------------------------------------------------------------- - | Form Fields - |-------------------------------------------------------------------------- - */ - - 'field.name' => 'Nome', - 'field.guard_name' => 'Guard', - 'field.permissions' => 'Permissões', - 'field.select_all.name' => 'Selecionar todos', - 'field.select_all.message' => 'Ativar todas as permissões para essa função', - - /* - |-------------------------------------------------------------------------- - | Navigation & Resource - |-------------------------------------------------------------------------- - */ - - 'nav.group' => 'Administração', - 'nav.role.label' => 'Roles/Funções', - 'nav.role.icon' => 'heroicon-o-shield-check', - 'resource.label.role' => 'Role/Função', - 'resource.label.roles' => 'Roles/Funções', - - /* - |-------------------------------------------------------------------------- - | Section & Tabs - |-------------------------------------------------------------------------- - */ - 'section' => 'Entidades', - 'resources' => 'Recursos', - 'widgets' => 'Widgets', - 'pages' => 'Páginas', - 'custom' => 'Permissões personalizadas', - - /* - |-------------------------------------------------------------------------- - | Messages - |-------------------------------------------------------------------------- - */ - - 'forbidden' => 'Não tem permissão para aceder', - - /* - |-------------------------------------------------------------------------- - | Resource Permissions' Labels - |-------------------------------------------------------------------------- - */ - - 'resource_permission_prefixes_labels' => [ - 'view' => 'Ler', - 'view_any' => 'Ler Todas', - 'create' => 'Criar', - 'update' => 'Atualizar', - 'delete' => 'Eliminar', - 'delete_any' => 'Apagar Todas', - 'force_delete' => 'Forçar Apagar', - 'force_delete_any' => 'Forçar Apagar Todas', - 'restore' => 'Restaurar', - 'reorder' => 'Reordenar', - 'restore_any' => 'Restaurar Todas', - 'replicate' => 'Replicar', - ], -]; diff --git a/resources/ku/filament-shield.php b/resources/lang/ku/filament-shield.php similarity index 100% rename from resources/ku/filament-shield.php rename to resources/lang/ku/filament-shield.php diff --git a/src/Commands/Concerns/CanGeneratePolicy.php b/src/Commands/Concerns/CanGeneratePolicy.php index ac44f89..3c0c318 100644 --- a/src/Commands/Concerns/CanGeneratePolicy.php +++ b/src/Commands/Concerns/CanGeneratePolicy.php @@ -22,13 +22,10 @@ protected function generatePolicyPath(array $entity): string { $path = (new \ReflectionClass($entity['fqcn']::getModel()))->getFileName(); - $policyPath = Str::of(config('filament-shield.generator.policy_directory', 'Policies')) - ->replace('\\', DIRECTORY_SEPARATOR); - if (Str::of($path)->contains(['vendor', 'src'])) { $basePolicyPath = app_path( (string) Str::of($entity['model']) - ->prepend($policyPath->append('\\')) + ->prepend(str(Utils::getPolicyPath())->append('\\')) ->replace('\\', DIRECTORY_SEPARATOR), ); @@ -37,7 +34,7 @@ protected function generatePolicyPath(array $entity): string /** @phpstan-ignore-next-line */ $basePath = Str::of($path) - ->replace('Models', $policyPath) + ->replace('Models', Utils::getPolicyPath()) ->replaceLast('.php', 'Policy.php') ->replace('\\', DIRECTORY_SEPARATOR); diff --git a/src/Support/Utils.php b/src/Support/Utils.php index 0282e63..8a805e9 100644 --- a/src/Support/Utils.php +++ b/src/Support/Utils.php @@ -191,7 +191,7 @@ public static function getExcludedWidgets(): array public static function isRolePolicyRegistered(): bool { - return (bool) config('filament-shield.register_role_policy.enabled', true); + return static::isRolePolicyGenerated() && config('filament-shield.register_role_policy.enabled', false); } public static function doesResourceHaveCustomPermissions(string $resourceClass): bool @@ -242,4 +242,18 @@ public static function discoverAllPages(): bool { return config('filament-shield.discovery.discover_all_pages', false); } + + public static function getPolicyPath(): string + { + return Str::of(config('filament-shield.generator.policy_directory', 'Policies')) + ->replace('\\', DIRECTORY_SEPARATOR) + ->toString(); + } + + protected static function isRolePolicyGenerated(): bool + { + $filesystem = new Filesystem; + + return (bool) $filesystem->exists(app_path(static::getPolicyPath() . DIRECTORY_SEPARATOR . 'RolePolicy.php')); + } }