]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/PermissionsController.php
Added method for using enity ownership in relation queries
[bookstack] / app / Http / Controllers / PermissionsController.php
index 7d908733bc1f439f36036e960a0546222f2a7248..453a230af9a466fc897ae88b8e8e9b749185fa01 100644 (file)
@@ -5,6 +5,7 @@ namespace BookStack\Http\Controllers;
 use BookStack\Auth\Permissions\EntityPermission;
 use BookStack\Auth\Permissions\PermissionFormData;
 use BookStack\Auth\Role;
+use BookStack\Auth\User;
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Bookshelf;
 use BookStack\Entities\Models\Chapter;
@@ -162,10 +163,35 @@ class PermissionsController extends Controller
     {
         $this->checkPermissionOr('restrictions-manage-all', fn() => userCan('restrictions-manage-own'));
 
+        /** @var Role $role */
         $role = Role::query()->findOrFail($roleId);
 
         return view('form.entity-permissions-row', [
-            'role' => $role,
+            'modelType' => 'role',
+            'modelId' => $role->id,
+            'modelName' => $role->display_name,
+            'modelDescription' => $role->description,
+            'permission' => new EntityPermission(),
+            'entityType' => $entityType,
+            'inheriting' => false,
+        ]);
+    }
+
+    /**
+     * Get an empty entity permissions form row for the given user.
+     */
+    public function formRowForUser(string $entityType, string $userId)
+    {
+        $this->checkPermissionOr('restrictions-manage-all', fn() => userCan('restrictions-manage-own'));
+
+        /** @var User $user */
+        $user  = User::query()->findOrFail($userId);
+
+        return view('form.entity-permissions-row', [
+            'modelType' => 'user',
+            'modelId' => $user->id,
+            'modelName' => $user->name,
+            'modelDescription' => '',
             'permission' => new EntityPermission(),
             'entityType' => $entityType,
             'inheriting' => false,