X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/919660678bec2b94eaa84ac60d0313f5ef07dfb7..refs/pull/1787/head:/app/Settings/SettingService.php diff --git a/app/Settings/SettingService.php b/app/Settings/SettingService.php index 756640485..dede8fcc4 100644 --- a/app/Settings/SettingService.php +++ b/app/Settings/SettingService.php @@ -1,15 +1,11 @@ localCache[$key])) { return $this->localCache[$key]; } @@ -53,6 +50,19 @@ class SettingService return $formatted; } + /** + * Get a value from the session instead of the main store option. + * @param $key + * @param bool $default + * @return mixed + */ + protected function getFromSession($key, $default = false) + { + $value = session()->get($key, $default); + $formatted = $this->formatValue($value, $default); + return $formatted; + } + /** * Get a user-specific setting from the database or cache. * @param \BookStack\Auth\User $user @@ -62,9 +72,23 @@ class SettingService */ public function getUser($user, $key, $default = false) { + if ($user->isDefault()) { + return $this->getFromSession($key, $default); + } return $this->get($this->userKey($user->id, $key), $default); } + /** + * Get a value for the current logged-in user. + * @param $key + * @param bool $default + * @return bool|string + */ + public function getForCurrentUser($key, $default = false) + { + return $this->getUser(user(), $key, $default); + } + /** * Gets a setting value from the cache or database. * Looks at the system defaults if not cached or in database. @@ -181,6 +205,9 @@ class SettingService */ public function putUser($user, $key, $value) { + if ($user->isDefault()) { + return session()->put($key, $value); + } return $this->put($this->userKey($user->id, $key), $value); }