X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/80865b30a5d6a82e86d21e272ae58977d4430a64..refs/pull/110/head:/app/helpers.php diff --git a/app/helpers.php b/app/helpers.php index ead6b3008..fea67a09a 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -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 @@ -39,23 +39,23 @@ if (!function_exists('versioned_asset')) { */ function userCan($permission, \BookStack\Ownable $ownable = null) { - if (!auth()->check()) return false; if ($ownable === null) { return auth()->user() && auth()->user()->can($permission); } // Check permission on ownable item - $permissionBaseName = strtolower($permission) . '-'; - $hasPermission = false; - if (auth()->user()->can($permissionBaseName . 'all')) $hasPermission = true; - if (auth()->user()->can($permissionBaseName . 'own') && $ownable->createdBy && $ownable->createdBy->id === auth()->user()->id) $hasPermission = true; - - if (!$ownable instanceof \BookStack\Entity) return $hasPermission; - - // Check restrictions on the entitiy - $restrictionService = app('BookStack\Services\RestrictionService'); - $explodedPermission = explode('-', $permission); - $action = end($explodedPermission); - $hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action); - return $hasAccess && $hasPermission; -} \ No newline at end of file + $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); +}