mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Added interface for adding/removing roles in entity perms.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Auth\Permissions\EntityPermission;
|
||||
use BookStack\Auth\Permissions\PermissionFormData;
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Bookshelf;
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
@@ -148,4 +150,20 @@ class PermissionsController extends Controller
|
||||
|
||||
return redirect($shelf->getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an empty entity permissions form row for the given role.
|
||||
*/
|
||||
public function formRowForRole(string $entityType, string $roleId)
|
||||
{
|
||||
$this->checkPermissionOr('restrictions-manage', fn() => userCan('restrictions-manage-all'));
|
||||
|
||||
$role = Role::query()->findOrFail($roleId);
|
||||
|
||||
return view('form.entity-permissions-row', [
|
||||
'role' => $role,
|
||||
'permission' => new EntityPermission(),
|
||||
'entityType' => $entityType,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user