Adds option to prevent saving changes to disk (#485)

This commit is contained in:
Alicia Sykes 2022-02-11 09:59:53 +00:00
parent 61bbfcb885
commit 76e5a1b77b
3 changed files with 19 additions and 3 deletions

View File

@ -99,7 +99,7 @@ export default {
}, },
allowWriteToDisk() { allowWriteToDisk() {
const { appConfig } = this.config; const { appConfig } = this.config;
return appConfig.allowConfigEdit !== false && isUserAdmin(); return !appConfig.preventWriteToDisk && appConfig.allowConfigEdit !== false && isUserAdmin();
}, },
initialSaveMode() { initialSaveMode() {
return this.allowWriteToDisk ? 'file' : 'local'; return this.allowWriteToDisk ? 'file' : 'local';

View File

@ -51,7 +51,9 @@ import Button from '@/components/FormElements/Button';
import RebuildIcon from '@/assets/interface-icons/application-rebuild.svg'; import RebuildIcon from '@/assets/interface-icons/application-rebuild.svg';
import ReloadIcon from '@/assets/interface-icons/application-reload.svg'; import ReloadIcon from '@/assets/interface-icons/application-reload.svg';
import LoadingAnimation from '@/assets/interface-icons/loader.svg'; import LoadingAnimation from '@/assets/interface-icons/loader.svg';
import ErrorHandler from '@/utils/ErrorHandler';
import { modalNames, serviceEndpoints } from '@/utils/defaults'; import { modalNames, serviceEndpoints } from '@/utils/defaults';
import { isUserAdmin } from '@/utils/Auth';
export default { export default {
name: 'RebuildApp', name: 'RebuildApp',
@ -79,6 +81,10 @@ export default {
methods: { methods: {
/* Calls to the rebuild endpoint, to kickoff the app build */ /* Calls to the rebuild endpoint, to kickoff the app build */
startBuild() { 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 baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin;
const endpoint = `${baseUrl}${serviceEndpoints.rebuild}`; const endpoint = `${baseUrl}${serviceEndpoints.rebuild}`;
this.loading = true; this.loading = true;
@ -116,7 +122,10 @@ export default {
}, },
}, },
mounted() { 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; this.allowRebuild = false;
} }
}, },

View File

@ -110,7 +110,10 @@ export default {
}, },
allowWriteToDisk() { allowWriteToDisk() {
const { appConfig } = this.config; 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() { data() {
@ -161,6 +164,10 @@ export default {
this.$store.commit(StoreKeys.SET_EDIT_MODE, false); this.$store.commit(StoreKeys.SET_EDIT_MODE, false);
}, },
writeToDisk() { writeToDisk() {
if (this.config.appConfig.preventWriteToDisk) {
ErrorHandler('Unable to write changed to disk, as this functionality is disabled');
return;
}
// 1. Convert JSON into YAML // 1. Convert JSON into YAML
const yamlOptions = {}; const yamlOptions = {};
const yaml = jsYaml.dump(this.config, yamlOptions); const yaml = jsYaml.dump(this.config, yamlOptions);