From 46e6c23575911c253fe4e43894e12b95aad03320 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 21 Jun 2021 13:09:20 +0100 Subject: [PATCH] :lock: Checks that the user has permission to write to disk before saving config --- src/components/Configuration/JsonEditor.vue | 27 +++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/Configuration/JsonEditor.vue b/src/components/Configuration/JsonEditor.vue index 26b46ff2..5d42fb32 100644 --- a/src/components/Configuration/JsonEditor.vue +++ b/src/components/Configuration/JsonEditor.vue @@ -11,12 +11,12 @@ Save Location:
+ v-model="saveMode" class="radio-option" :disabled="!allowWriteToDisk" />
+ :disabled="!allowWriteToDisk" />
@@ -80,7 +80,7 @@ export default { jsonParser: JsonToYaml, responseText: '', saveSuccess: undefined, - isAdmin: isUserAdmin(this.config.appConfig.auth), + allowWriteToDisk: this.shouldAllowWriteToDisk(), }; }, computed: { @@ -89,11 +89,15 @@ export default { }, }, mounted() { - if (!this.isAdmin) this.saveMode = 'local'; + if (!this.allowWriteToDisk) this.saveMode = 'local'; }, methods: { + shouldAllowWriteToDisk() { + const { appConfig } = this.config; + return appConfig.allowConfigEdit !== false && isUserAdmin(appConfig.auth); + }, save() { - if (this.saveMode === 'local' || !this.isAdmin) { + if (this.saveMode === 'local' || !this.allowWriteToDisk) { this.saveConfigLocally(); } else if (this.saveMode === 'file') { this.writeConfigToDisk(); @@ -114,11 +118,17 @@ export default { request.then((response) => { this.saveSuccess = response.data.success || false; this.responseText = response.data.message; - if (this.saveSuccess) this.carefullyClearLocalStorage(); + if (this.saveSuccess) { + this.carefullyClearLocalStorage(); + this.showToast('Config file written to disk succesfully', true); + } else { + this.showToast('An error occurred saving config', false); + } }) .catch((error) => { this.saveSuccess = false; this.responseText = error; + this.showToast(error, false); }); }, saveConfigLocally() { @@ -135,7 +145,7 @@ export default { if (data.appConfig.theme) { localStorage.setItem(localStorageKeys.THEME, data.appConfig.theme); } - this.$toasted.show('Changes saved succesfully'); + this.showToast('Changes saved succesfully', true); }, carefullyClearLocalStorage() { localStorage.removeItem(localStorageKeys.PAGE_INFO); @@ -168,6 +178,9 @@ export default { }); this.errorMessages = errorMessages; }, + showToast(message, success) { + this.$toasted.show(message, { className: `toast-${success ? 'success' : 'error'}` }); + }, }, };