Skip to content

Commit

Permalink
⚡ Adds option to prevent saving changes to disk (gchq#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Feb 11, 2022
1 parent 61bbfcb commit 76e5a1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Configuration/JsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 10 additions & 1 deletion src/components/Configuration/RebuildApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
},
Expand Down
9 changes: 8 additions & 1 deletion src/components/InteractiveEditor/EditModeSaveMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 76e5a1b

Please sign in to comment.