1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Pages: Redirect user to view if they can't edit

For #5568
This commit is contained in:
Dan Brown
2025-05-24 12:05:17 +01:00
parent b29fe5c46d
commit 454b152b95
3 changed files with 17 additions and 6 deletions

View File

@ -49,13 +49,13 @@ abstract class Controller extends BaseController
* On a permission error redirect to home and display.
* the error as a notification.
*
* @return never
* @throws NotifyException
*/
protected function showPermissionError()
protected function showPermissionError(string $redirectLocation = '/'): never
{
$message = request()->wantsJson() ? trans('errors.permissionJson') : trans('errors.permission');
throw new NotifyException($message, '/', 403);
throw new NotifyException($message, $redirectLocation, 403);
}
/**
@ -81,10 +81,10 @@ abstract class Controller extends BaseController
/**
* Check the current user's permissions against an ownable item otherwise throw an exception.
*/
protected function checkOwnablePermission(string $permission, Model $ownable): void
protected function checkOwnablePermission(string $permission, Model $ownable, string $redirectLocation = '/'): void
{
if (!userCan($permission, $ownable)) {
$this->showPermissionError();
$this->showPermissionError($redirectLocation);
}
}