]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Controller.php
Update common.php
[bookstack] / app / Http / Controllers / Controller.php
index 80f567eaa80279e8f49599f9703f5ab29e6276c3..5bc62c601a73bcf63913a2bac3bd63c25dbab2e1 100644 (file)
@@ -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