3 if (!function_exists('versioned_asset')) {
5 * Get the path to a versioned file.
10 * @throws \InvalidArgumentException
12 function versioned_asset($file)
14 static $manifest = null;
16 if (is_null($manifest)) {
17 $manifest = json_decode(file_get_contents(public_path('build/manifest.json')), true);
20 if (isset($manifest[$file])) {
21 return '/' . $manifest[$file];
24 if (file_exists(public_path($file))) {
28 throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
33 * Check if the current user has a permission.
34 * If an ownable element is passed in the permissions are checked against
35 * that particular item.
37 * @param \BookStack\Ownable $ownable
40 function userCan($permission, \BookStack\Ownable $ownable = null)
42 if (!auth()->check()) return false;
43 if ($ownable === null) {
44 return auth()->user() && auth()->user()->can($permission);
47 // Check permission on ownable item
48 $restrictionService = app('BookStack\Services\RestrictionService');
49 return $restrictionService->checkEntityUserAccess($ownable, $permission);
53 * Helper to access system settings.
55 * @param bool $default
58 function setting($key, $default = false)
60 $settingService = app('BookStack\Services\SettingService');
61 return $settingService->get($key, $default);