Skip to content

Commit

Permalink
make it conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Jul 10, 2024
1 parent c680906 commit 49bbd76
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Traits\Conditionable;
use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository;
use Statamic\API\Middleware\Cache;
use Statamic\Auth\Permission as AuthPermission;
use Statamic\Facades\Blueprint;
use Statamic\Facades\CP\Nav;
use Statamic\Facades\GraphQL;
Expand Down Expand Up @@ -143,18 +144,12 @@ protected function registerPermissions(): self
$permission
->label($this->permissionLabel('view', $resource))
->children([
Permission::make("edit {$resource->handle()}")
->label($this->permissionLabel('edit', $resource))
->children([
Permission::make("create {$resource->handle()}")
->label($this->permissionLabel('create', $resource)),

Permission::make("publish {$resource->handle()}")
->label("Manage {$resource->handle()} Publish State"),

Permission::make("delete {$resource->handle()}")
->label($this->permissionLabel('delete', $resource)),
]),
$this->makePermission("edit {$resource->handle()}", $this->permissionLabel('edit', $resource))
->children(array_filter([
$this->makePermission("create {$resource->handle()}", $this->permissionLabel('create', $resource)),
$resource->hasPublishStates() ? $this->makePermission("publish {$resource->handle()}", "Manage {$resource->name()} Publish State") : null,
$this->makePermission("delete {$resource->handle()}", $this->permissionLabel('delete', $resource)),
])),
]);
});
}
Expand Down Expand Up @@ -303,4 +298,9 @@ protected function shouldDiscoverResources(): bool

return true;
}

private function makePermission(string $permission, string $label): AuthPermission
{
return Permission::make($permission)->label($label);
}
}

0 comments on commit 49bbd76

Please sign in to comment.