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 * Class SettingService
*
* The settings are a simple key-value database store. * The settings are a simple key-value database store.
* * For non-authenticated users, user settings are stored via the session instead.
* @package BookStack\Services
*/ */
class SettingService class SettingService
{ {
@ -52,6 +50,19 @@ class SettingService
return $formatted; 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. * Get a user-specific setting from the database or cache.
* @param \BookStack\Auth\User $user * @param \BookStack\Auth\User $user
@ -62,7 +73,7 @@ class SettingService
public function getUser($user, $key, $default = false) public function getUser($user, $key, $default = false)
{ {
if ($user->isDefault()) { if ($user->isDefault()) {
return session()->get($key, $default); return $this->getFromSession($key, $default);
} }
return $this->get($this->userKey($user->id, $key), $default); return $this->get($this->userKey($user->id, $key), $default);
} }