1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-01-03 23:42:28 +03:00

Permissions: Updated use of helpers to use enums

Also added middlware method to Permission enum to allow easier usage
with controller middleware.
This commit is contained in:
Dan Brown
2025-09-09 09:48:19 +01:00
parent 33a0237f87
commit 419dbadcfd
62 changed files with 165 additions and 145 deletions

View File

@@ -63,7 +63,7 @@ class UserAccountController extends Controller
'profile_image' => array_merge(['nullable'], $this->getImageValidationRules()),
]);
$this->userRepo->update($user, $validated, userCan('users-manage'));
$this->userRepo->update($user, $validated, userCan(\BookStack\Permissions\Permission::UsersManage));
// Save profile image if in request
if ($request->hasFile('profile_image')) {
@@ -219,7 +219,7 @@ class UserAccountController extends Controller
$this->preventAccessInDemoMode();
$requestNewOwnerId = intval($request->get('new_owner_id')) ?: null;
$newOwnerId = userCan('users-manage') ? $requestNewOwnerId : null;
$newOwnerId = userCan(\BookStack\Permissions\Permission::UsersManage) ? $requestNewOwnerId : null;
$this->userRepo->destroy(user(), $newOwnerId);

View File

@@ -125,7 +125,7 @@ class UserApiController extends ApiController
{
$data = $this->validate($request, $this->rules($id)['update']);
$user = $this->userRepo->getById($id);
$this->userRepo->update($user, $data, userCan('users-manage'));
$this->userRepo->update($user, $data, userCan(\BookStack\Permissions\Permission::UsersManage));
$this->singleFormatter($user);
return response()->json($user);

View File

@@ -15,9 +15,9 @@ class UserSearchController extends Controller
public function forSelect(Request $request)
{
$hasPermission = !user()->isGuest() && (
userCan('users-manage')
|| userCan('restrictions-manage-own')
|| userCan('restrictions-manage-all')
userCan(\BookStack\Permissions\Permission::UsersManage)
|| userCan(\BookStack\Permissions\Permission::RestrictionsManageOwn)
|| userCan(\BookStack\Permissions\Permission::RestrictionsManageAll)
);
if (!$hasPermission) {