3 namespace BookStack\Permissions;
5 use BookStack\Entities\Models\Entity;
6 use BookStack\Permissions\Models\EntityPermission;
7 use BookStack\Users\Models\Role;
9 class PermissionFormData
11 protected Entity $entity;
13 public function __construct(Entity $entity)
15 $this->entity = $entity;
19 * Get the permissions with assigned roles.
21 public function permissionsWithRoles(): array
23 return $this->entity->permissions()
25 ->where('role_id', '!=', 0)
27 ->sortBy('role.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 entity permission for the "Everyone Else" option.
49 public function everyoneElseEntityPermission(): EntityPermission
51 /** @var ?EntityPermission $permission */
52 $permission = $this->entity->permissions()
53 ->where('role_id', '=', 0)
55 return $permission ?? (new EntityPermission());
59 * Get the "Everyone Else" role entry.
61 public function everyoneElseRole(): Role
63 return (new Role())->forceFill([
65 'display_name' => trans('entities.permissions_role_everyone_else'),
66 'description' => trans('entities.permissions_role_everyone_else_desc'),