<?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
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
-}
\ No newline at end of file
+}
+
+/**
+ * Check if the current user has a permission.
+ * If an ownable element is passed in the jointPermissions are checked against
+ * that particular item.
+ * @param $permission
+ * @param \BookStack\Ownable $ownable
+ * @return mixed
+ */
+function userCan($permission, \BookStack\Ownable $ownable = null)
+{
+ if ($ownable === null) {
+ return auth()->user() && auth()->user()->can($permission);
+ }
+
+ // 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);
+}