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 permissions with assigned users.
33 public function permissionsWithUsers(): array
35 return $this->entity->permissions()
37 ->whereNotNull('user_id')
44 * Get the roles that don't yet have specific permissions for the
45 * entity we're managing permissions for.
47 public function rolesNotAssigned(): array
49 $assigned = $this->entity->permissions()->whereNotNull('role_id')->pluck('role_id');
51 ->where('system_name', '!=', 'admin')
52 ->whereNotIn('id', $assigned)
53 ->orderBy('display_name', 'asc')
59 * Get the entity permission for the "Everyone Else" option.
61 public function everyoneElseEntityPermission(): EntityPermission
63 /** @var ?EntityPermission $permission */
64 $permission = $this->entity->permissions()
65 ->whereNull(['role_id', 'user_id'])
67 return $permission ?? (new EntityPermission());
71 * Check if the "Everyone else" option is inheriting default role system permissions.
72 * Is determined by any system entity_permission existing for the current entity.
74 public function everyoneElseInheriting(): bool
76 return !$this->entity->permissions()
77 ->whereNull(['role_id', 'user_id'])