Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable14] Added cache override to ensure an always up-to-date accessibility css #12432

Merged
merged 1 commit into from Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/accessibility/js/accessibility.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/accessibility/js/accessibility.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion apps/accessibility/lib/AppInfo/Application.php
Expand Up @@ -54,8 +54,10 @@ public function injectCss() {
$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]);
}
}
Expand Down
3 changes: 3 additions & 0 deletions apps/accessibility/lib/Controller/AccessibilityController.php
Expand Up @@ -181,6 +181,9 @@ public function getCss(): DataDisplayResponse {
$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;
}

Expand Down
24 changes: 18 additions & 6 deletions apps/accessibility/lib/Controller/ConfigController.php
Expand Up @@ -36,6 +36,9 @@ class ConfigController extends OCSController {
/** @var string */
protected $appName;

/** @var string */
protected $userId;

/** @var string */
protected $serverRoot;

Expand Down Expand Up @@ -67,6 +70,7 @@ public function __construct(string $appName,
$this->config = $config;
$this->userSession = $userSession;
$this->accessibilityProvider = $accessibilityProvider;
$this->userId = $userSession->getUser()->getUID();
}

/**
Expand All @@ -79,8 +83,8 @@ public function __construct(string $appName,
*/
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)
]);
}

Expand All @@ -95,20 +99,28 @@ public function getConfig(): DataResponse {
*/
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();
}

Expand Down
2 changes: 1 addition & 1 deletion apps/accessibility/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/accessibility/package.json
@@ -1,7 +1,7 @@
{
"name": "accessibility",
"description": "Provides multiple accessibilities options to ease your use of nextcloud",
"version": "1.0.1",
"version": "1.0.2",
"author": "John Molakvoæ <skjnldsv@protonmail.com>",
"license": "agpl",
"private": true,
Expand Down
31 changes: 23 additions & 8 deletions apps/accessibility/src/App.vue
Expand Up @@ -24,7 +24,7 @@ import preview from './components/itemPreview';
import axios from 'axios';

export default {
name: 'app',
name: 'Accessibility',
components: { preview },
beforeMount() {
// importing server data into the app
Expand Down Expand Up @@ -54,7 +54,7 @@ export default {
};
},
tokenHeaders() {
return { headers: { requesttoken: OC.requestToken } }
return { headers: { requesttoken: OC.requestToken } };
}
},
methods: {
Expand All @@ -73,8 +73,11 @@ export default {
* @param {string} id the data of the change
*/
selectItem(type, id) {
axios
.post(OC.linkToOCS('apps/accessibility/api/v1/config', 2) + type, {value: id}, this.tokenHeaders)
axios.post(
OC.linkToOCS('apps/accessibility/api/v1/config', 2) + type,
{ value: id },
this.tokenHeaders
)
.then(response => {
this.serverData[type] = id;

Expand All @@ -84,11 +87,23 @@ export default {
// insert new css
let link = document.createElement('link');
link.rel = 'stylesheet';
link.href = OC.generateUrl('/apps/accessibility/css/user-style.css');
document.head.appendChild(link)
link.href = OC.generateUrl('/apps/accessibility/css/user-style.css') + '?v=' + new Date().getTime();
document.head.appendChild(link);
} else {
// force update
link.href = link.href.split('?')[0] + '?v=' + new Date().getTime();
// compare arrays
if (
JSON.stringify(Object.values(this.selected)) ===
JSON.stringify([false, false])
) {
// if nothing is selected, blindly remove the css
link.remove();
} else {
// force update
link.href =
link.href.split('?')[0] +
'?v=' +
new Date().getTime();
}
}
})
.catch(err => {
Expand Down