diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-10-02 09:46:05 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-10-02 09:46:05 +0200 |
commit | cf06e313ee7c38231099d94e6239249c2b7903b8 (patch) | |
tree | 8ef6a984600d5ccd3947c4b270ab3565a1414ce5 /apps/accessibility/lib | |
parent | 77c6e4106359776bc7283801fa36008596981444 (diff) | |
download | nextcloud-server-cf06e313ee7c38231099d94e6239249c2b7903b8.tar.gz nextcloud-server-cf06e313ee7c38231099d94e6239249c2b7903b8.zip |
Added cache override to ensure an always up-to-date accessibility css
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/accessibility/lib')
-rw-r--r-- | apps/accessibility/lib/AppInfo/Application.php | 4 | ||||
-rw-r--r-- | apps/accessibility/lib/Controller/AccessibilityController.php | 3 | ||||
-rw-r--r-- | apps/accessibility/lib/Controller/ConfigController.php | 24 |
3 files changed, 24 insertions, 7 deletions
diff --git a/apps/accessibility/lib/AppInfo/Application.php b/apps/accessibility/lib/AppInfo/Application.php index 068fcc27b7a..203c0d088bc 100644 --- a/apps/accessibility/lib/AppInfo/Application.php +++ b/apps/accessibility/lib/AppInfo/Application.php @@ -54,8 +54,10 @@ class Application extends App { $loggedUser = $this->userSession->getUser(); if (!is_null($loggedUser)) { $userValues = $this->config->getUserKeys($loggedUser->getUID(), $this->appName); + // we want to check if any theme or font is enabled. if (count($userValues) > 0) { - $linkToCSS = $this->urlGenerator->linkToRoute($this->appName . '.accessibility.getCss', ['md5' => md5(implode('-', $userValues))]); + $hash = $this->config->getUserValue($loggedUser->getUID(), $this->appName, 'icons-css', md5(implode('-', $userValues))); + $linkToCSS = $this->urlGenerator->linkToRoute($this->appName . '.accessibility.getCss', ['md5' => $hash]); \OCP\Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS]); } } diff --git a/apps/accessibility/lib/Controller/AccessibilityController.php b/apps/accessibility/lib/Controller/AccessibilityController.php index 8f1ffa452af..4d88db1435d 100644 --- a/apps/accessibility/lib/Controller/AccessibilityController.php +++ b/apps/accessibility/lib/Controller/AccessibilityController.php @@ -181,6 +181,9 @@ class AccessibilityController extends Controller { $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); $response->addHeader('Pragma', 'cache'); + // store current cache hash + $this->config->setUserValue($this->userSession->getUser()->getUID(), $this->appName, 'icons-css', md5($css)); + return $response; } diff --git a/apps/accessibility/lib/Controller/ConfigController.php b/apps/accessibility/lib/Controller/ConfigController.php index ba11faafa20..1fe2c4fbc13 100644 --- a/apps/accessibility/lib/Controller/ConfigController.php +++ b/apps/accessibility/lib/Controller/ConfigController.php @@ -37,6 +37,9 @@ class ConfigController extends OCSController { protected $appName; /** @var string */ + protected $userId; + + /** @var string */ protected $serverRoot; /** @var IConfig */ @@ -67,6 +70,7 @@ class ConfigController extends OCSController { $this->config = $config; $this->userSession = $userSession; $this->accessibilityProvider = $accessibilityProvider; + $this->userId = $userSession->getUser()->getUID(); } /** @@ -79,8 +83,8 @@ class ConfigController extends OCSController { */ public function getConfig(): DataResponse { return new DataResponse([ - 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), - 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) + 'theme' => $this->config->getUserValue($this->userId, $this->appName, 'theme', false), + 'font' => $this->config->getUserValue($this->userId, $this->appName, 'font', false) ]); } @@ -95,20 +99,28 @@ class ConfigController extends OCSController { */ public function setConfig(string $key, $value): DataResponse { if ($key === 'theme' || $key === 'font') { - $themes = $this->accessibilityProvider->getThemes(); - $fonts = $this->accessibilityProvider->getFonts(); if ($value === false) { - $this->config->deleteUserValue($this->userSession->getUser()->getUID(), $this->appName, $key); + $this->config->deleteUserValue($this->userId, $this->appName, $key); + $userValues = $this->config->getUserKeys($this->userId, $this->appName); + + // remove hash if no settings selected + if (count($userValues) === 1 && $userValues[0] === 'icons-css') { + $this->config->deleteUserValue($this->userId, $this->appName, 'icons-css'); + } + return new DataResponse(); } + $themes = $this->accessibilityProvider->getThemes(); + $fonts = $this->accessibilityProvider->getFonts(); + $availableOptions = array_map(function($option) { return $option['id']; }, array_merge($themes, $fonts)); if (in_array($value, $availableOptions)) { - $this->config->setUserValue($this->userSession->getUser()->getUID(), $this->appName, $key, $value); + $this->config->setUserValue($this->userId, $this->appName, $key, $value); return new DataResponse(); } |