X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/257a5a23ecaf7ce779969d575ff8a0b976181d13..refs/pull/1504/head:/app/Http/Controllers/Controller.php diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 80f567eaa..5bc62c601 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -123,6 +123,20 @@ abstract class Controller extends BaseController return true; } + /** + * Check if the current user has a permission or bypass if the provided user + * id matches the current user. + * @param string $permissionName + * @param int $userId + * @return bool + */ + protected function checkPermissionOrCurrentUser(string $permissionName, int $userId) + { + return $this->checkPermissionOr($permissionName, function () use ($userId) { + return $userId === $this->currentUser->id; + }); + } + /** * Send back a json error message. * @param string $messageText