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 permissions with assigned roles.
20 public function permissionsWithRoles(): array
22 return $this->entity->permissions()
24 ->whereNotNull('role_id')
26 ->sortBy('role.display_name')
31 * Get the roles that don't yet have specific permissions for the
32 * entity we're managing permissions for.
34 public function rolesNotAssigned(): array
36 $assigned = $this->entity->permissions()->whereNotNull('role_id')->pluck('role_id');
38 ->where('system_name', '!=', 'admin')
39 ->whereNotIn('id', $assigned)
40 ->orderBy('display_name', 'asc')
46 * Get the entity permission for the "Everyone Else" option.
48 public function everyoneElseEntityPermission(): EntityPermission
50 /** @var ?EntityPermission $permission */
51 $permission = $this->entity->permissions()
52 ->whereNull(['role_id', 'user_id'])
54 return $permission ?? (new EntityPermission());
58 * Check if the "Everyone else" option is inheriting default role system permissions.
59 * Is determined by any system entity_permission existing for the current entity.
61 public function everyoneElseInheriting(): bool
63 return !$this->entity->permissions()
64 ->whereNull(['role_id', 'user_id'])