summaryrefslogtreecommitdiffstats
path: root/apps/accessibility/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-10-24 15:04:29 +0200
committerGitHub <noreply@github.com>2018-10-24 15:04:29 +0200
commit2ec5d2a6ded8096431978638013df4ae5d711cb3 (patch)
treef0591a3b4d9c185267b30cbc4f17dae402120a72 /apps/accessibility/lib
parentdf6e9109c8d2f4d461073a0e6f69d6fd7b67d0e3 (diff)
parentcf06e313ee7c38231099d94e6239249c2b7903b8 (diff)
downloadnextcloud-server-2ec5d2a6ded8096431978638013df4ae5d711cb3.tar.gz
nextcloud-server-2ec5d2a6ded8096431978638013df4ae5d711cb3.zip
Merge pull request #11533 from nextcloud/accessibility-cache-fixes
Added cache override to ensure an always up-to-date accessibility css
Diffstat (limited to 'apps/accessibility/lib')
-rw-r--r--apps/accessibility/lib/AppInfo/Application.php4
-rw-r--r--apps/accessibility/lib/Controller/AccessibilityController.php3
-rw-r--r--apps/accessibility/lib/Controller/ConfigController.php24
3 files changed, 24 insertions, 7 deletions
diff --git a/apps/accessibility/lib/AppInfo/Application.php b/apps/accessibility/lib/AppInfo/Application.php
index 6e3dc789d97..e87341b6c1c 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 a8fba556acb..d679e37ed99 100644
--- a/apps/accessibility/lib/Controller/AccessibilityController.php
+++ b/apps/accessibility/lib/Controller/AccessibilityController.php
@@ -182,6 +182,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();
}