Skip to content

Commit

Permalink
🛂 Adds access control checks in editor forms (gchq#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Feb 12, 2022
1 parent 69f7090 commit c8ad80b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/components/InteractiveEditor/EditAppConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
classes="dashy-modal edit-app-config"
@closed="modalClosed"
>
<div class="edit-app-config-inner">
<div class="edit-app-config-inner" v-if="allowViewConfig">
<h3>{{ $t('interactive-editor.menu.edit-app-config-btn') }}</h3>
<!-- Show caution message -->
<div class="app-config-intro">
Expand Down Expand Up @@ -35,6 +35,7 @@
<!-- Save Button, lower -->
<SaveCancelButtons :saveClick="saveToState" :cancelClick="cancelEditing" />
</div>
<AccessError v-else />
</modal>
</template>

Expand All @@ -43,6 +44,7 @@ import FormSchema from '@formschema/native';
import DashySchema from '@/utils/ConfigSchema';
import StoreKeys from '@/utils/StoreMutations';
import { modalNames } from '@/utils/defaults';
import AccessError from '@/components/Configuration/AccessError';
import SaveCancelButtons from '@/components/InteractiveEditor/SaveCancelButtons';
export default {
Expand All @@ -58,6 +60,7 @@ export default {
components: {
FormSchema,
SaveCancelButtons,
AccessError,
},
mounted() {
this.formData = this.appConfig;
Expand All @@ -66,6 +69,9 @@ export default {
appConfig() {
return this.$store.getters.appConfig;
},
allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig;
},
},
methods: {
/* When form submitteed, update VueX store with new appConfig, and close modal */
Expand Down
11 changes: 9 additions & 2 deletions src/components/InteractiveEditor/EditItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
classes="dashy-modal edit-item"
@closed="modalClosed"
>
<div class="edit-item-inner">
<div class="edit-item-inner" v-if="allowViewConfig">
<!-- Title and Item ID -->
<h3 class="title">Edit Item</h3>
<p class="sub-title">Editing {{item.title}} (ID: {{itemId}})</p>
Expand Down Expand Up @@ -67,13 +67,15 @@
<!-- Save to state button -->
<SaveCancelButtons :saveClick="saveItem" :cancelClick="modalClosed" />
</div>
<AccessError v-else />
</modal>
</template>

<script>
import AddIcon from '@/assets/interface-icons/interactive-editor-add.svg';
import BinIcon from '@/assets/interface-icons/interactive-editor-remove.svg';
import SaveCancelButtons from '@/components/InteractiveEditor/SaveCancelButtons';
import AccessError from '@/components/Configuration/AccessError';
import Input from '@/components/FormElements/Input';
import Radio from '@/components/FormElements/Radio';
import Select from '@/components/FormElements/Select';
Expand Down Expand Up @@ -101,13 +103,18 @@ export default {
isNew: Boolean,
parentSectionTitle: String, // If adding new item, which section to add it under
},
computed: {},
computed: {
allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig;
},
},
components: {
Input,
Radio,
Select,
AddIcon,
BinIcon,
AccessError,
SaveCancelButtons,
},
mounted() {
Expand Down
8 changes: 7 additions & 1 deletion src/components/InteractiveEditor/EditPageInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:resizable="true" width="50%" height="80%"
classes="dashy-modal edit-page-info"
>
<div class="edit-page-info-inner">
<div class="edit-page-info-inner" v-if="allowViewConfig">
<h3>{{ $t('interactive-editor.menu.edit-page-info-btn') }}</h3>
<FormSchema
:schema="schema"
Expand All @@ -19,6 +19,7 @@
</Button>
</FormSchema>
</div>
<AccessError v-else />
</modal>
</template>

Expand All @@ -29,6 +30,7 @@ import StoreKeys from '@/utils/StoreMutations';
import { modalNames } from '@/utils/defaults';
import Button from '@/components/FormElements/Button';
import SaveIcon from '@/assets/interface-icons/save-config.svg';
import AccessError from '@/components/Configuration/AccessError';
export default {
name: 'EditPageInfo',
Expand All @@ -43,6 +45,7 @@ export default {
FormSchema,
Button,
SaveIcon,
AccessError,
},
mounted() {
this.formData = this.pageInfo;
Expand All @@ -51,6 +54,9 @@ export default {
pageInfo() {
return this.$store.getters.pageInfo;
},
allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig;
},
},
methods: {
/* When form submitteed, update VueX store with new pageInfo, and close modal */
Expand Down
8 changes: 7 additions & 1 deletion src/components/InteractiveEditor/EditSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:resizable="true" width="50%" height="80%"
classes="dashy-modal edit-section"
>
<div class="edit-section-inner">
<div class="edit-section-inner" v-if="allowViewConfig">
<h3>
{{ $t(`interactive-editor.edit-section.${isAddNew ? 'add' : 'edit'}-section-title`) }}
</h3>
Expand All @@ -19,6 +19,7 @@
:cancelClick="modalClosed"
/>
</div>
<AccessError v-else />
</modal>
</template>

Expand All @@ -28,6 +29,7 @@ import StoreKeys from '@/utils/StoreMutations';
import DashySchema from '@/utils/ConfigSchema';
import { modalNames } from '@/utils/defaults';
import SaveCancelButtons from '@/components/InteractiveEditor/SaveCancelButtons';
import AccessError from '@/components/Configuration/AccessError';
export default {
name: 'EditSection',
Expand All @@ -38,6 +40,7 @@ export default {
components: {
SaveCancelButtons,
FormSchema,
AccessError,
},
data() {
return {
Expand Down Expand Up @@ -71,6 +74,9 @@ export default {
},
};
},
allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig;
},
},
mounted() {
this.sectionData = this.$store.getters.getSectionByIndex(this.sectionIndex);
Expand Down
13 changes: 11 additions & 2 deletions src/components/InteractiveEditor/ExportConfigMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
:resizable="true"
width="50%"
height="80%"
classes="dashy-modal edit-item"
classes="dashy-modal export-modal"
@closed="modalClosed"
>
<div class="export-config-inner">
<div class="export-config-inner" v-if="allowViewConfig">
<!-- Download and Copy to CLipboard Buttons -->
<h3>{{ $t('interactive-editor.export.export-title') }}</h3>
<div class="download-button-container">
Expand All @@ -26,6 +26,7 @@
<h3>{{ $t('interactive-editor.export.view-title') }}</h3>
<tree-view :data="config" class="config-tree-view" />
</div>
<AccessError v-else />
</modal>
</template>

Expand All @@ -34,6 +35,7 @@ import JsYaml from 'js-yaml';
import Button from '@/components/FormElements/Button';
import StoreKeys from '@/utils/StoreMutations';
import { modalNames } from '@/utils/defaults';
import AccessError from '@/components/Configuration/AccessError';
import DownloadConfigIcon from '@/assets/interface-icons/config-download-file.svg';
import CopyConfigIcon from '@/assets/interface-icons/interactive-editor-copy-clipboard.svg';
import { InfoHandler, InfoKeys } from '@/utils/ErrorHandler';
Expand All @@ -42,6 +44,7 @@ export default {
name: 'ExportConfigMenu',
components: {
Button,
AccessError,
CopyConfigIcon,
DownloadConfigIcon,
},
Expand All @@ -55,6 +58,9 @@ export default {
config() {
return this.$store.state.config;
},
allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig;
},
},
methods: {
convertJsonToYaml() {
Expand Down Expand Up @@ -123,5 +129,8 @@ export default {
}
}
}
.export-modal {
background: var(--interactive-editor-background);
}
</style>
8 changes: 7 additions & 1 deletion src/components/InteractiveEditor/MoveItemTo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modal
:name="modalName" @closed="close"
:resizable="true" width="40%" height="40%" classes="dashy-modal">
<div class="move-menu-inner">
<div class="move-menu-inner" v-if="allowViewConfig">
<!-- Title and item ID -->
<h3 class="move-title">Move or Copy Item</h3>
<p class="item-id">Editing {{ itemId }}</p>
Expand Down Expand Up @@ -30,13 +30,15 @@
<!-- Save and cancel buttons -->
<SaveCancelButtons :saveClick="save" :cancelClick="close" />
</div>
<AccessError v-else />
</modal>
</template>

<script>
import Select from '@/components/FormElements/Select';
import Radio from '@/components/FormElements/Radio';
import SaveCancelButtons from '@/components/InteractiveEditor/SaveCancelButtons';
import AccessError from '@/components/Configuration/AccessError';
import StoreKeys from '@/utils/StoreMutations';
import { modalNames } from '@/utils/defaults';
Expand All @@ -45,6 +47,7 @@ export default {
components: {
Select,
Radio,
AccessError,
SaveCancelButtons,
},
props: {
Expand Down Expand Up @@ -83,6 +86,9 @@ export default {
});
return sectionName;
},
allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig;
},
},
mounted() {
this.selectedSection = this.currentSection;
Expand Down

0 comments on commit c8ad80b

Please sign in to comment.