From 76e5a1b77b587a3e2d36969a0ebd8b61843b2a48 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 11 Feb 2022 09:59:53 +0000 Subject: [PATCH] :zap: Adds option to prevent saving changes to disk (#485) --- src/components/Configuration/JsonEditor.vue | 2 +- src/components/Configuration/RebuildApp.vue | 11 ++++++++++- src/components/InteractiveEditor/EditModeSaveMenu.vue | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/Configuration/JsonEditor.vue b/src/components/Configuration/JsonEditor.vue index 966288e1..62d0a279 100644 --- a/src/components/Configuration/JsonEditor.vue +++ b/src/components/Configuration/JsonEditor.vue @@ -99,7 +99,7 @@ export default { }, allowWriteToDisk() { const { appConfig } = this.config; - return appConfig.allowConfigEdit !== false && isUserAdmin(); + return !appConfig.preventWriteToDisk && appConfig.allowConfigEdit !== false && isUserAdmin(); }, initialSaveMode() { return this.allowWriteToDisk ? 'file' : 'local'; diff --git a/src/components/Configuration/RebuildApp.vue b/src/components/Configuration/RebuildApp.vue index 7bde1fa8..e77eef53 100644 --- a/src/components/Configuration/RebuildApp.vue +++ b/src/components/Configuration/RebuildApp.vue @@ -51,7 +51,9 @@ import Button from '@/components/FormElements/Button'; import RebuildIcon from '@/assets/interface-icons/application-rebuild.svg'; import ReloadIcon from '@/assets/interface-icons/application-reload.svg'; import LoadingAnimation from '@/assets/interface-icons/loader.svg'; +import ErrorHandler from '@/utils/ErrorHandler'; import { modalNames, serviceEndpoints } from '@/utils/defaults'; +import { isUserAdmin } from '@/utils/Auth'; export default { name: 'RebuildApp', @@ -79,6 +81,10 @@ export default { methods: { /* Calls to the rebuild endpoint, to kickoff the app build */ startBuild() { + if (!this.allowRebuild) { // Double check user is allowed + ErrorHandler('Unable to trigger rebuild, insufficient permission'); + return; + } const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin; const endpoint = `${baseUrl}${serviceEndpoints.rebuild}`; this.loading = true; @@ -116,7 +122,10 @@ export default { }, }, mounted() { - if (this.appConfig.allowConfigEdit === false) { + // Disable rebuild functionality if user not allowed + if (this.appConfig.allowConfigEdit === false + || this.appConfig.preventWriteToDisk + || !isUserAdmin()) { this.allowRebuild = false; } }, diff --git a/src/components/InteractiveEditor/EditModeSaveMenu.vue b/src/components/InteractiveEditor/EditModeSaveMenu.vue index 2cf570f4..7cbdbcbc 100644 --- a/src/components/InteractiveEditor/EditModeSaveMenu.vue +++ b/src/components/InteractiveEditor/EditModeSaveMenu.vue @@ -110,7 +110,10 @@ export default { }, allowWriteToDisk() { const { appConfig } = this.config; - return appConfig.allowConfigEdit !== false && isUserAdmin(); + if (appConfig.preventWriteToDisk) return false; + if (appConfig.allowConfigEdit === false) return false; + if (!isUserAdmin()) return false; // If auth configured, but user NOT admin + return true; }, }, data() { @@ -161,6 +164,10 @@ export default { this.$store.commit(StoreKeys.SET_EDIT_MODE, false); }, writeToDisk() { + if (this.config.appConfig.preventWriteToDisk) { + ErrorHandler('Unable to write changed to disk, as this functionality is disabled'); + return; + } // 1. Convert JSON into YAML const yamlOptions = {}; const yaml = jsYaml.dump(this.config, yamlOptions);