3 namespace BookStack\Auth\Permissions;
5 use BookStack\Auth\Role;
6 use BookStack\Entities\Models\Entity;
8 class PermissionFormData
10 protected Entity $entity;
12 public function __construct(Entity $entity)
14 $this->entity = $entity;
18 * Get the roles with permissions assigned.
20 public function rolesWithPermissions(): array
22 return $this->entity->permissions()
24 ->where('role_id', '!=', 0)
25 ->get(['id', 'role_id'])
27 ->sortBy('display_name')
32 * Get the roles that don't yet have specific permissions for the
33 * entity we're managing permissions for.
35 public function rolesNotAssigned(): array
37 $assigned = $this->entity->permissions()->pluck('role_id');
39 ->where('system_name', '!=', 'admin')
40 ->whereNotIn('id', $assigned)
41 ->orderBy('display_name', 'asc')
47 * Get the "Everyone Else" role entry.
49 public function everyoneElseRole(): Role
51 return (new Role())->forceFill([
53 'display_name' => 'Everyone Else',
54 'description' => 'Set permissions for all roles not specifically overridden.'