Skip to content

Commit

Permalink
resolves #407
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Sep 2, 2024
1 parent d9f7929 commit b074108
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 88 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/filament-shield.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
],

'register_role_policy' => [
'enabled' => false,
'enabled' => true,
],

];
File renamed without changes.
79 changes: 0 additions & 79 deletions resources/lang/filament-shield_pt_PT.php

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion resources/lang/sk/filament-shield.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

return [
/*
Expand Down
7 changes: 2 additions & 5 deletions src/Commands/Concerns/CanGeneratePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);

Expand All @@ -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);

Expand Down
16 changes: 15 additions & 1 deletion src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit b074108

Please sign in to comment.