]> BookStack Code Mirror - bookstack/blobdiff - app/helpers.php
Updated ldap so extension not required in testing
[bookstack] / app / helpers.php
index db65407c73729a9c85669c7fd7e57fdc2b3eedeb..fea67a09a4c8d047ac52617a1831f5bee0ef33bf 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 
-if (! function_exists('versioned_asset')) {
+if (!function_exists('versioned_asset')) {
     /**
      * Get the path to a versioned file.
      *
-     * @param  string  $file
+     * @param  string $file
      * @return string
      *
      * @throws \InvalidArgumentException
@@ -31,7 +31,7 @@ if (! function_exists('versioned_asset')) {
 
 /**
  * Check if the current user has a permission.
- * If an ownable element is passed in the permissions are checked against
+ * If an ownable element is passed in the jointPermissions are checked against
  * that particular item.
  * @param $permission
  * @param \BookStack\Ownable $ownable
@@ -43,8 +43,19 @@ function userCan($permission, \BookStack\Ownable $ownable = null)
         return auth()->user() && auth()->user()->can($permission);
     }
 
-    $permissionBaseName = strtolower($permission) . '-';
-    if (userCan($permissionBaseName . 'all')) return true;
-    if (userCan($permissionBaseName . 'own') && $ownable->createdBy->id === auth()->user()->id) return true;
-    return false;
-}
\ No newline at end of file
+    // Check permission on ownable item
+    $permissionService = app('BookStack\Services\PermissionService');
+    return $permissionService->checkEntityUserAccess($ownable, $permission);
+}
+
+/**
+ * Helper to access system settings.
+ * @param $key
+ * @param bool $default
+ * @return mixed
+ */
+function setting($key, $default = false)
+{
+    $settingService = app('BookStack\Services\SettingService');
+    return $settingService->get($key, $default);
+}