Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to shield:seeder command to only generate direct permissions #329

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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