]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Permissions/PermissionFormData.php
Guest create page: name field autofocus
[bookstack] / app / Auth / Permissions / PermissionFormData.php
index 07c95c5344924a44b07b88dc59afb3d705190ccf..8044a3c5675847de5467e163ed7dea50c195d29f 100644 (file)
@@ -15,16 +15,15 @@ class PermissionFormData
     }
 
     /**
-     * Get the roles with permissions assigned.
+     * Get the permissions with assigned roles.
      */
-    public function rolesWithPermissions(): array
+    public function permissionsWithRoles(): array
     {
         return $this->entity->permissions()
             ->with('role')
             ->where('role_id', '!=', 0)
-            ->get(['id', 'role_id'])
-            ->pluck('role')
-            ->sortBy('display_name')
+            ->get()
+            ->sortBy('role.display_name')
             ->all();
     }
 
@@ -43,6 +42,18 @@ class PermissionFormData
             ->all();
     }
 
+    /**
+     * Get the entity permission for the "Everyone Else" option.
+     */
+    public function everyoneElseEntityPermission(): EntityPermission
+    {
+        /** @var ?EntityPermission $permission */
+        $permission = $this->entity->permissions()
+            ->where('role_id', '=', 0)
+            ->first();
+        return $permission ?? (new EntityPermission());
+    }
+
     /**
      * Get the "Everyone Else" role entry.
      */
@@ -50,8 +61,8 @@ class PermissionFormData
     {
         return (new Role())->forceFill([
             'id' => 0,
-            'display_name' => 'Everyone Else',
-            'description' => 'Set permissions for all roles not specifically overridden.'
+            'display_name' => trans('entities.permissions_role_everyone_else'),
+            'description' => trans('entities.permissions_role_everyone_else_desc'),
         ]);
     }
 }