Skip to content

Commit

Permalink
Add option to normalize export ckl profile name (#5852)
Browse files Browse the repository at this point in the history
* added option to normalize export ckl profile name

Signed-off-by: George M Dias <GDIAS@MITRE.ORG>

* linter fixes

Signed-off-by: George M Dias <GDIAS@MITRE.ORG>

* code quality fixes

Signed-off-by: George M Dias <GDIAS@MITRE.ORG>

* code quality fixes

Signed-off-by: George M Dias <GDIAS@MITRE.ORG>

* Update ExportCKLModal.vue

Review updates

* review updates

Signed-off-by: George M Dias <GDIAS@MITRE.ORG>

---------

Signed-off-by: George M Dias <GDIAS@MITRE.ORG>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
georgedias and mergify[bot] committed May 29, 2024
1 parent a9824f7 commit e932e6d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
82 changes: 79 additions & 3 deletions apps/frontend/src/components/global/ExportCKLModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@
<template #activator="{on}">
<LinkItem
key="export_ckl"
text="Export as Checklist"
text="Export as DISA Checklist"
icon="mdi-check-all"
@click="showModal"
v-on="on"
/>
</template>
<v-card>
<v-card-title class="headline"> Export as Checklist </v-card-title>
<v-row no-gutters>
<v-col cols="10">
<v-card-title class="headline">
Export as DISA Checklist
</v-card-title>
</v-col>
<v-col cols="2">
<v-checkbox
v-model="formatProfileTitle"
v-b-tooltip.hover
title="Attempts to format the profile title into a proper CKL title name"
class="mx-2"
label="Format Profile Title"
/>
</v-col>
</v-row>

<v-card-text>
<v-row>
<v-col v-for="(file, index) in files" :key="index" cols="12">
Expand Down Expand Up @@ -143,8 +159,20 @@
>
<v-row>
<v-text-field
v-model="profile.title"
v-if="formatProfileTitle"
label="Name"
:value="
setProperName(profile.title, index, profileIndex)
"
:placeholder="profile.titleplaceholder"
class="pr-2"
/>
<v-text-field
v-else
label="Name"
:value="
resetProfileName(profile.title, index, profileIndex)
"
:placeholder="profile.titleplaceholder"
class="pr-2"
/>
Expand Down Expand Up @@ -284,6 +312,8 @@ export default class ExportCKLModal extends Vue {
@Prop({type: Object, required: true}) readonly filter!: Filter;
showingModal = false;
formatProfileTitle = false;
originalProfileTitle = new Map<number, string>();
roles = Object.values(Role);
types = Object.values(Assettype);
techareas = Object.values(Techarea);
Expand Down Expand Up @@ -526,6 +556,52 @@ export default class ExportCKLModal extends Vue {
return macPattern.test(value) || 'Invalid MAC Address Format';
}
setProperName(name: string, fileIndex: number, profileIndex: number): string {
let newName = name;
// Find if we need to format the name
let index = 0;
// Only format for UCs where the name ends with values contained in the baselineArray
const baselineArray = ['stig-baseline', 'cis-baseline', 'srg-baseline'];
for (const baseline of baselineArray) {
if (name.indexOf(baseline) > 0) {
index = name.indexOf(baseline);
break;
}
}
// We need to format the name
if (index > 0) {
const originalTitleIndex = fileIndex + profileIndex;
// Preserve the old name
if (!this.originalProfileTitle.has(originalTitleIndex)) {
this.originalProfileTitle.set(originalTitleIndex, name);
}
// Get the name value up to the index, replace dashes with spaces
newName = name.substring(0, index).split('-').join(' ');
// Convert the first letter of each word into uppercase
newName = newName.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word) {
return word.toUpperCase();
});
newName = newName + 'Security Technical Implementation Guide';
}
// Update the file title for the profile being processed
this.files[fileIndex].profiles[profileIndex].title = newName;
return newName;
}
resetProfileName(name: string, fileIndex: number, profileIndex: number) {
let newName = name;
const index = fileIndex + profileIndex;
if (this.originalProfileTitle.has(index)) {
newName = this.originalProfileTitle.get(index)!;
this.files[fileIndex].profiles[profileIndex].title = newName;
}
return newName;
}
toggleSelectFile(file: ExtendedEvaluationFile) {
if (this.selected.includes(file)) {
const selectedIndex = this.selected.indexOf(file);
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/components/global/ExportJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<template #activator="{on}">
<IconLinkItem
key="export_json"
text="Export as JSON"
text="Export as OHDF JSON"
icon="mdi-code-json"
@click="export_json()"
v-on="on"
Expand Down

0 comments on commit e932e6d

Please sign in to comment.