Skip to content

Commit 159b606

Browse files
committed
Providing a notification publisher clone feature
Implemented as per DependencyTrack/dependency-track#1760 (comment) Signed-off-by: Alioune SY <[email protected]>
1 parent 275ce88 commit 159b606

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

src/i18n/locales/en.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,17 @@
533533
"delete_template": "Delete Template",
534534
"template_deleted": "Template deleted",
535535
"template_basedir": "Template base directory",
536+
"template_basedir_tooltip": "This property is used as base directory for notification templates search",
536537
"general_template_configuration": "General template configuration",
538+
"template_override_description": "Switching the template override control on and providing a template base directory allow you to override Dependency Track default notification publisher templates.",
539+
"template_override_file_hierarchy": "Any Pebble templates available in the template base directory with the appropriate directory hierarchy and naming scheme (e.g ${base directory}/templates/notification/publisher/email.peb) will override Dependency Track default one.",
540+
"template_override_security_warning": "You must set appropriate rights to the template base directory to prevent untrusted third party from supplying fraudulent Pebble templates that could lead to potential remote code execution.",
541+
"template_override_restart_needed": "Dependency Track restart is required for the modifications to be taken into account.",
537542
"enable_default_template_override": "Enable default template override",
538543
"restore_default_template": "Restore default templates",
539-
"default_template_restored": "Default templates restored"
544+
"default_template_restored": "Default templates restored",
545+
"clone_template": "Clone Template",
546+
"template_cloned": "Template cloned"
540547
},
541548
"condition": {
542549
"warning": "Warning",

src/views/administration/notifications/CreateTemplateModal.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,24 @@
4444

4545
<script>
4646
import permissionsMixin from "../../../mixins/permissionsMixin";
47+
import EventBus from "../../../shared/eventbus";
4748
4849
export default {
4950
mixins: [permissionsMixin],
51+
mounted() {
52+
EventBus.$on('admin:templates:cloneTemplate', (template) => {
53+
this.name = `${template.name} - clone`;
54+
this.publisherClass = template.publisherClass;
55+
this.description = template.description;
56+
this.mimeType = template.templateMimeType;
57+
this.template = template.template;
58+
});
59+
this.$root.$on('bv::modal::hide', (_, modalId) => {
60+
if(modalId == 'createTemplateModal') {
61+
this.resetValues();
62+
}
63+
});
64+
},
5065
data() {
5166
return {
5267
name: null,
@@ -58,7 +73,6 @@
5873
},
5974
methods: {
6075
createTemplate: function() {
61-
this.$root.$emit('bv::hide::modal', 'createTemplateModal');
6276
let url = `${this.$api.BASE_URL}/${this.$api.URL_NOTIFICATION_PUBLISHER}`;
6377
this.axios.put(url, {
6478
name: this.name,
@@ -73,7 +87,7 @@
7387
}).catch(() => {
7488
this.$toastr.w(this.$t('condition.unsuccessful_action'));
7589
});
76-
this.resetValues();
90+
this.$root.$emit('bv::hide::modal', 'createTemplateModal');
7791
},
7892
resetValues: function () {
7993
this.name = null;

src/views/administration/notifications/GeneralTemplateConfigurationModal.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
2-
<b-modal id="generalTemplateConfigurationModal" size="md" hide-header-close no-stacking :title="$t('admin.general_template_configuration')" @show="loadConfigProperties">
2+
<b-modal id="generalTemplateConfigurationModal" size="lg" hide-header-close no-stacking :title="$t('admin.general_template_configuration')" @show="loadConfigProperties">
3+
<p>{{ $t('admin.template_override_description') }}</p>
4+
<p>{{ $t('admin.template_override_file_hierarchy') }}</p>
5+
<p>{{ $t('admin.template_override_security_warning') }}</p>
6+
<p>{{ $t('admin.template_override_restart_needed') }}</p>
37
<b-form-group>
48
<c-switch id="template_override" color="primary" v-model="enableDefaultTemplatesOverride" label v-bind="labelIcon"/>
59
{{ $t('admin.enable_default_template_override') }}
@@ -11,12 +15,12 @@
1115
rules="required"
1216
type="text"
1317
v-model="templateBasedir"
14-
tooltip="This property is used as base directory for notification templates search."
18+
:tooltip="$t('admin.template_basedir_tooltip')"
1519
/>
1620
<template v-slot:modal-footer="{ cancel }">
1721
<b-button size="md" variant="secondary" @click="cancel()">{{ $t('message.close') }}</b-button>
1822
<b-button size="md" variant="primary" @click="updateConfiguration()">{{ $t('message.update') }}</b-button>
19-
<b-button size="md" variant="primary" @click="restoreDefaultTemplates()">{{ $t('admin.restore_default_template') }}</b-button>
23+
<b-button size="md" variant="warning" @click="restoreDefaultTemplates()">{{ $t('admin.restore_default_template') }}</b-button>
2024
</template>
2125
</b-modal>
2226
</template>

src/views/administration/notifications/Templates.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
EventBus.$on('admin:templates:rowDeleted', () => {
5151
this.refreshTable();
5252
});
53+
EventBus.$on('admin:templates:cloneTemplate', () => {
54+
this.$bvModal.show("createTemplateModal");
55+
});
5356
},
5457
beforeDestroy() {
5558
EventBus.$off('admin:templates:rowUpdate');
@@ -126,6 +129,7 @@
126129
<b-form-textarea v-else id="input-5" v-model="template.template" rows="10" class="form-control" required trim />
127130
</b-form-group>
128131
<div style="text-align:right">
132+
<b-button variant="outline-primary" @click="cloneNotificationPublisher">{{ $t('admin.clone_template') }}</b-button>
129133
<b-button v-if="!template.defaultPublisher" variant="outline-primary" @click="updateNotificationPublisher">{{ $t('message.update') }}</b-button>
130134
<b-button v-if="!template.defaultPublisher" variant="outline-danger" @click="deleteNotificationPublisher">{{ $t('admin.delete_template') }}</b-button>
131135
</div>
@@ -168,6 +172,9 @@
168172
}).catch(() => {
169173
this.$toastr.w(this.$t('condition.unsuccessful_action'));
170174
});
175+
},
176+
cloneNotificationPublisher: function() {
177+
EventBus.$emit('admin:templates:cloneTemplate', this.template);
171178
}
172179
}
173180
})

0 commit comments

Comments
 (0)