Skip to content

Commit

Permalink
Suggested changes to default email recipients feature (#399)
Browse files Browse the repository at this point in the history
* Suggested changes to default email recipients feature

* Fix null emails bug by simplifying email dialog

* Add reply-to header to emails
  • Loading branch information
annehaley authored Mar 24, 2022
1 parent 4cf5191 commit 518384c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 40 deletions.
44 changes: 11 additions & 33 deletions client/src/components/EmailDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ export default defineComponent({
to: [],
cc: [],
bcc: [],
toCandidates: [],
ccCandidates: [],
bccCandidates: [],
showCC: false,
showBCC: false,
subject: '',
Expand Down Expand Up @@ -81,22 +78,15 @@ export default defineComponent({
return;
}
this.selectedScreenshots = [];
this.toCandidates = [];
this.ccCandidates = this.currentProject.settings.default_email_recipients.map(
(emailString) => ({
name: emailString,
}),
);
this.bccCandidates = [];
this.to = this.toCandidates.map((c) => c.name);
this.cc = this.ccCandidates.map((c) => c.name);
this.bcc = this.bccCandidates.map((c) => c.name);
this.to = this.currentProject.settings.default_email_recipients;
this.cc = [];
this.bcc = [];
if (this.user) {
this.bcc.push(this.user.email);
this.cc.push(this.user.email);
}
this.showCC = !!this.cc.length;
this.showBCC = !!this.bcc.length;
this.subject = `Regarding ${this.currentViewData.experimentName}, ${this.currentScan.name}`;
this.subject = `Regarding ${this.currentViewData.projectName}, ${this.currentViewData.experimentName}, ${this.currentScan.name}`;
this.body = `Experiment: ${this.currentViewData.experimentName}\nScan: ${this.currentScan.name}\n`;
if (this.currentViewData.scanDecisions.length > 0) {
this.body += `Decisions:\n ${this.currentViewData.scanDecisions.map(
Expand All @@ -118,23 +108,11 @@ export default defineComponent({
if (!this.$refs.form.validate()) {
return;
}
const toAddresses = this.to.map((recipient) => {
const candidate = this.toCandidates.find((c) => c.name === recipient);
return candidate ? candidate.email : recipient;
});
const ccAddresses = this.cc.map((recipient) => {
const candidate = this.ccCandidates.find((c) => c.name === recipient);
return candidate ? candidate.email : recipient;
});
const bccAddresses = this.bcc.map((recipient) => {
const candidate = this.bccCandidates.find((c) => c.name === recipient);
return candidate ? candidate.email : recipient;
});
this.sending = true;
await djangoRest.sendEmail({
to: toAddresses,
cc: ccAddresses,
bcc: bccAddresses,
to: this.to,
cc: this.cc,
bcc: this.bcc,
subject: this.subject,
body: this.body,
screenshots: this.screenshots.filter(
Expand Down Expand Up @@ -193,7 +171,7 @@ export default defineComponent({
<v-flex>
<EmailRecipientCombobox
v-model="to"
:candidates="toCandidates.map(c => c.name)"
:candidates="to"
:required="true"
label="to"
/>
Expand All @@ -215,7 +193,7 @@ export default defineComponent({
<v-flex>
<EmailRecipientCombobox
v-model="cc"
:candidates="ccCandidates.map(c => c.name)"
:candidates="cc"
:required="false"
label="cc"
/>
Expand All @@ -225,7 +203,7 @@ export default defineComponent({
<v-flex>
<EmailRecipientCombobox
v-model="bcc"
:candidates="bccCandidates.map(c => c.name)"
:candidates="bcc"
:required="false"
label="bcc"
/>
Expand Down
20 changes: 13 additions & 7 deletions client/src/components/ProjectUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ export default {
return JSON.stringify(this.permissions)
!== JSON.stringify(this.selectedPermissionSet);
},
userCanEditProject() {
return this.user.is_superuser || this.user.username === this.currentProject.value.creator;
},
},
watch: {
currentProject(newProj) {
this.selectedPermissionSet = { ...newProj.settings.permissions };
this.emailList = this.currentProject.settings.default_email_recipients;
},
},
mounted() {
Expand Down Expand Up @@ -128,7 +132,7 @@ export default {
<v-col cols="12">
Members
<v-tooltip
v-if="user.is_superuser || user.username == currentProject.creator"
v-if="userCanEditProject"
bottom
style="display: inline; padding-left: 5px"
>
Expand Down Expand Up @@ -169,7 +173,7 @@ export default {
<v-col cols="12">
Collaborators <span class="gray-info">(Read only)</span>
<v-tooltip
v-if="user.is_superuser || user.username == currentProject.creator"
v-if="userCanEditProject"
bottom
style="display: inline; padding-left: 5px"
>
Expand Down Expand Up @@ -207,7 +211,6 @@ export default {
<v-col cols="12">
Default email recipients
<v-tooltip
v-if="user.is_superuser || user.username == currentProject.creator"
bottom
style="display: inline; padding-left: 5px"
>
Expand All @@ -233,6 +236,7 @@ export default {
<v-combobox
v-model="emailList"
:items="emailOptions"
:disabled="!userCanEditProject"
label="Select or type an email"
:rules="[allEmails]"
multiple
Expand All @@ -242,12 +246,14 @@ export default {
style="max-width:500px;"
>
<template #append-outer>
<v-icon
v-if="emailListChanged"
<v-btn
v-if="userCanEditProject"
:disabled="!emailListChanged"
color="primary"
@click="saveEmails"
>
save
</v-icon>
Save
</v-btn>
</template>
</v-combobox>
</v-col>
Expand Down
1 change: 1 addition & 0 deletions miqa/core/rest/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def post(self, request, format=None):
request.data['to'],
bcc=request.data['bcc'],
cc=request.data['cc'],
reply_to=[request.user.email],
)

for index, screenshot in enumerate(request.data['screenshots']):
Expand Down

0 comments on commit 518384c

Please sign in to comment.