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; } /** * 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); }