From fc2ddcd24ee86c1c5700582b0e14cd5ad62b476d Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 22 Oct 2022 10:41:34 -0700 Subject: [PATCH] Add readonly mode --- lib/Controller/ApiController.php | 5 +++++ src/components/Settings.vue | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index b4f1cd44..85a3f6cf 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -603,6 +603,11 @@ class ApiController extends Controller return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); } + // Make sure not running in read-only mode + if ($this->config->getSystemValue('memories_readonly', false)) { + return new JSONResponse(["message" => "Cannot change settings in readonly mode"], Http::STATUS_FORBIDDEN); + } + $userId = $user->getUid(); $this->config->setUserValue($userId, Application::APPNAME, $key, $value); diff --git a/src/components/Settings.vue b/src/components/Settings.vue index 3042b765..ff0f34b8 100644 --- a/src/components/Settings.vue +++ b/src/components/Settings.vue @@ -77,12 +77,15 @@ export default class Settings extends Mixins(UserConfig, GlobalMixin) { const settings = ['showHidden', 'timelinePath', 'foldersPath']; // Update all - const p = await Promise.all(settings.map(async (setting) => this.updateSetting(setting))); - - if (p.some((r) => !r || r.status !== 200)) { - showError(this.t('memories', 'Error updating settings')); - } else { - window.location.reload(); + try { + const p = await Promise.all(settings.map(async (setting) => this.updateSetting(setting))); + if (p.some((r) => !r || r.status !== 200)) { + showError(this.t('memories', 'Error updating settings')); + } else { + window.location.reload(); + } + } catch (e) { + showError(e?.response?.data?.message || this.t('memories', 'Error updating settings')); } } }