Updated guest settings system to format value as per non-guest

Fixes #1431
This commit is contained in:
Dan Brown 2019-05-07 22:56:48 +01:00
parent a981dc41cb
commit d62d2384cb
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View File

@ -4,10 +4,8 @@ use Illuminate\Contracts\Cache\Repository as Cache;
/**
* Class SettingService
*
* The settings are a simple key-value database store.
*
* @package BookStack\Services
* For non-authenticated users, user settings are stored via the session instead.
*/
class SettingService
{
@ -52,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,7 +73,7 @@ class SettingService
public function getUser($user, $key, $default = false)
{
if ($user->isDefault()) {
return session()->get($key, $default);
return $this->getFromSession($key, $default);
}
return $this->get($this->userKey($user->id, $key), $default);
}