66use BookStack \App \Model ;
77use BookStack \Exceptions \NotifyException ;
88use BookStack \Facades \Activity ;
9+ use BookStack \Permissions \Permission ;
910use Illuminate \Foundation \Bus \DispatchesJobs ;
1011use Illuminate \Foundation \Validation \ValidatesRequests ;
1112use Illuminate \Http \JsonResponse ;
@@ -27,10 +28,9 @@ protected function isSignedIn(): bool
2728 }
2829
2930 /**
30- * Stops the application and shows a permission error if
31- * the application is in demo mode.
31+ * Stops the application and shows a permission error if the application is in demo mode.
3232 */
33- protected function preventAccessInDemoMode ()
33+ protected function preventAccessInDemoMode (): void
3434 {
3535 if (config ('app.env ' ) === 'demo ' ) {
3636 $ this ->showPermissionError ();
@@ -40,14 +40,13 @@ protected function preventAccessInDemoMode()
4040 /**
4141 * Adds the page title into the view.
4242 */
43- public function setPageTitle (string $ title )
43+ public function setPageTitle (string $ title ): void
4444 {
4545 view ()->share ('pageTitle ' , $ title );
4646 }
4747
4848 /**
49- * On a permission error redirect to home and display.
50- * the error as a notification.
49+ * On a permission error redirect to home and display the error as a notification.
5150 *
5251 * @throws NotifyException
5352 */
@@ -61,7 +60,7 @@ protected function showPermissionError(string $redirectLocation = '/'): never
6160 /**
6261 * Checks that the current user has the given permission otherwise throw an exception.
6362 */
64- protected function checkPermission (string $ permission ): void
63+ protected function checkPermission (string | Permission $ permission ): void
6564 {
6665 if (!user () || !user ()->can ($ permission )) {
6766 $ this ->showPermissionError ();
@@ -81,7 +80,7 @@ protected function preventGuestAccess(): void
8180 /**
8281 * Check the current user's permissions against an ownable item otherwise throw an exception.
8382 */
84- protected function checkOwnablePermission (string $ permission , Model $ ownable , string $ redirectLocation = '/ ' ): void
83+ protected function checkOwnablePermission (string | Permission $ permission , Model $ ownable , string $ redirectLocation = '/ ' ): void
8584 {
8685 if (!userCan ($ permission , $ ownable )) {
8786 $ this ->showPermissionError ($ redirectLocation );
@@ -92,7 +91,7 @@ protected function checkOwnablePermission(string $permission, Model $ownable, st
9291 * Check if a user has a permission or bypass the permission
9392 * check if the given callback resolves true.
9493 */
95- protected function checkPermissionOr (string $ permission , callable $ callback ): void
94+ protected function checkPermissionOr (string | Permission $ permission , callable $ callback ): void
9695 {
9796 if ($ callback () !== true ) {
9897 $ this ->checkPermission ($ permission );
@@ -103,15 +102,15 @@ protected function checkPermissionOr(string $permission, callable $callback): vo
103102 * Check if the current user has a permission or bypass if the provided user
104103 * id matches the current user.
105104 */
106- protected function checkPermissionOrCurrentUser (string $ permission , int $ userId ): void
105+ protected function checkPermissionOrCurrentUser (string | Permission $ permission , int $ userId ): void
107106 {
108107 $ this ->checkPermissionOr ($ permission , function () use ($ userId ) {
109108 return $ userId === user ()->id ;
110109 });
111110 }
112111
113112 /**
114- * Send back a json error message.
113+ * Send back a JSON error message.
115114 */
116115 protected function jsonError (string $ messageText = '' , int $ statusCode = 500 ): JsonResponse
117116 {
@@ -127,23 +126,23 @@ protected function download(): DownloadResponseFactory
127126 }
128127
129128 /**
130- * Show a positive, successful notification to the user on next view load.
129+ * Show a positive, successful notification to the user on the next view load.
131130 */
132131 protected function showSuccessNotification (string $ message ): void
133132 {
134133 session ()->flash ('success ' , $ message );
135134 }
136135
137136 /**
138- * Show a warning notification to the user on next view load.
137+ * Show a warning notification to the user on the next view load.
139138 */
140139 protected function showWarningNotification (string $ message ): void
141140 {
142141 session ()->flash ('warning ' , $ message );
143142 }
144143
145144 /**
146- * Show an error notification to the user on next view load.
145+ * Show an error notification to the user on the next view load.
147146 */
148147 protected function showErrorNotification (string $ message ): void
149148 {
0 commit comments