Skip to content

Commit

Permalink
Merge pull request #329 from Jacobtims/feat/only-create-seeder-for-pe…
Browse files Browse the repository at this point in the history
…rmissions

Add option to shield:seeder command to only generate direct permissions
  • Loading branch information
bezhanSalleh committed Feb 14, 2024
2 parents efef2ba + b31eaf6 commit 631bbd7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Commands/MakeShieldSeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MakeShieldSeederCommand extends Command
*/
public $signature = 'shield:seeder
{--generate : Generates permissions for all entities as configured }
{--option= : Generate only permissions via roles or direct permissions (<fg=green;options=bold>permissions_via_roles,direct_permissions</>)}
{--F|force : Override if the seeder already exists }
';

Expand Down Expand Up @@ -52,7 +53,9 @@ public function handle(): int
$permissionsViaRoles = collect();
$directPermissions = collect();

if (Utils::getRoleModel()::exists()) {
$option = $this->option('option');

if ((Utils::getRoleModel()::exists() && is_null($option)) || $option === 'permissions_via_roles') {
$permissionsViaRoles = collect(Utils::getRoleModel()::with('permissions')->get())
->map(function ($role) use ($directPermissionNames) {
$rolePermissions = $role->permissions
Expand All @@ -69,7 +72,7 @@ public function handle(): int
});
}

if (Utils::getPermissionModel()::exists()) {
if ((Utils::getPermissionModel()::exists() && is_null($option)) || $option === 'direct_permissions') {
$directPermissions = collect(Utils::getPermissionModel()::get())
->filter(fn ($permission) => ! in_array($permission->name, $directPermissionNames->unique()->flatten()->all()))
->map(fn ($permission) => [
Expand Down

0 comments on commit 631bbd7

Please sign in to comment.