Skip to content

Commit 0e39706

Browse files
authored
Merge pull request #223 from maykinmedia/feature/85-notify-all-assignees
[#85] Notify all assignees of deletion
2 parents 8b872e0 + 25f006e commit 0e39706

File tree

8 files changed

+111
-2
lines changed

8 files changed

+111
-2
lines changed

backend/src/openarchiefbeheer/accounts/tests/factories.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class UserFactory(DjangoModelFactory):
2121
last_name = factory.Faker("last_name")
2222
password = factory.PostGenerationMethodCall("set_password", "password")
2323
role = factory.SubFactory(RoleFactory)
24+
email = factory.Faker("email")
2425

2526
class Meta:
2627
model = User

backend/src/openarchiefbeheer/destruction/tasks.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .constants import InternalStatus, ListItemStatus, ListStatus
1010
from .models import DestructionList, DestructionListItem, ReviewResponse
1111
from .signals import deletion_failure
12+
from .utils import notify_assignees_successful_deletion
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -104,4 +105,4 @@ def complete_and_notify(pk: int) -> None:
104105

105106
destruction_list.set_status(ListStatus.deleted)
106107

107-
# TODO notify
108+
notify_assignees_successful_deletion(destruction_list)

backend/src/openarchiefbeheer/destruction/tests/test_tasks.py

+33
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ListStatus,
2222
)
2323
from ..tasks import (
24+
complete_and_notify,
2425
delete_destruction_list,
2526
delete_destruction_list_item,
2627
process_review_response,
@@ -335,3 +336,35 @@ def test_processing_list_with_failed_item(self):
335336
item.internal_results,
336337
{"deleted_resources": {}, "resources_to_delete": {}, "traceback": ""},
337338
)
339+
340+
def test_complete_and_notify(self):
341+
list = DestructionListFactory.create(
342+
processing_status=InternalStatus.processing,
343+
status=ListStatus.ready_to_delete,
344+
)
345+
assignees = DestructionListAssigneeFactory.create_batch(
346+
3, destruction_list=list
347+
)
348+
349+
with (
350+
patch(
351+
"openarchiefbeheer.destruction.utils.EmailConfig.get_solo",
352+
return_value=EmailConfig(
353+
subject_successful_deletion="DELETED!",
354+
body_successful_deletion="Wohoo deleted list",
355+
),
356+
),
357+
):
358+
complete_and_notify(list.pk)
359+
360+
self.assertEqual(len(mail.outbox), 1)
361+
self.assertEqual(
362+
sorted(mail.outbox[0].to),
363+
sorted([assignee.user.email for assignee in assignees]),
364+
)
365+
self.assertEqual(mail.outbox[0].subject, "DELETED!")
366+
367+
list.refresh_from_db()
368+
369+
self.assertEqual(list.status, ListStatus.deleted)
370+
self.assertEqual(list.processing_status, InternalStatus.succeeded)

backend/src/openarchiefbeheer/destruction/utils.py

+14
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ def notify_author_last_review(
9999
)
100100

101101

102+
def notify_assignees_successful_deletion(destruction_list: DestructionList) -> None:
103+
config = EmailConfig.get_solo()
104+
recipients = destruction_list.assignees.all().values_list("user__email", flat=True)
105+
106+
notify(
107+
subject=config.subject_successful_deletion,
108+
body=config.body_successful_deletion,
109+
context={
110+
"list": destruction_list,
111+
},
112+
recipients=list(recipients),
113+
)
114+
115+
102116
class ObjectWithStatus(Protocol):
103117
def set_processing_status(self, status: InternalStatus) -> None: ...
104118

backend/src/openarchiefbeheer/emails/admin.py

+9
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,13 @@ class EmailConfigAdmin(SingletonModelAdmin):
4747
]
4848
},
4949
),
50+
(
51+
_("Templates successful deletion"),
52+
{
53+
"fields": [
54+
"subject_successful_deletion",
55+
"body_successful_deletion",
56+
]
57+
},
58+
),
5059
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 4.2.14 on 2024-07-26 14:01
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("emails", "0003_emailconfig_body_error_during_deletion_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="emailconfig",
15+
name="body_successful_deletion",
16+
field=models.TextField(
17+
blank=True,
18+
help_text="Body of the email that will be sent to all the assignees when a list is successfully deleted.",
19+
verbose_name="body successful deletion",
20+
),
21+
),
22+
migrations.AddField(
23+
model_name="emailconfig",
24+
name="subject_successful_deletion",
25+
field=models.CharField(
26+
blank=True,
27+
help_text="Subject of the email that will be sent to all the assignees when a list is successfully deleted.",
28+
max_length=250,
29+
verbose_name="subject successful deletion",
30+
),
31+
),
32+
]

backend/src/openarchiefbeheer/emails/models.py

+17
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ class EmailConfig(SingletonModel):
101101
),
102102
blank=True,
103103
)
104+
subject_successful_deletion = models.CharField(
105+
max_length=250,
106+
verbose_name=_("subject successful deletion"),
107+
help_text=_(
108+
"Subject of the email that will be sent to all the assignees "
109+
"when a list is successfully deleted."
110+
),
111+
blank=True,
112+
)
113+
body_successful_deletion = models.TextField(
114+
verbose_name=_("body successful deletion"),
115+
help_text=_(
116+
"Body of the email that will be sent to all the assignees "
117+
"when a list is successfully deleted."
118+
),
119+
blank=True,
120+
)
104121

105122
class Meta:
106123
verbose_name = _("email configuration")

backend/src/openarchiefbeheer/fixtures/default_emails.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"subject_changes_requested": "Voorstel voor wijziging van uw vernietigingslijst",
1515
"body_changes_requested": "Beste {{ user }},\r\n\r\nEr is een voorstel tot aanpassing van uw vernietigingslijst {{ list }}. U kunt de lijst en de voorgestelde wijziging in de Open-Archiefbeheer web app bekijken en af te handelen.",
1616
"subject_error_during_deletion": "Fout tijdens vernietiging",
17-
"body_error_during_deletion": "Beste {{ user }},\r\n\r\nEr is een fout opgetreden tijdens het vernietigen van vernietigingslijst {{ list }}. Probeer het opnieuw of neem contact op met de IT afdeling."
17+
"body_error_during_deletion": "Beste {{ user }},\r\n\r\nEr is een fout opgetreden tijdens het vernietigen van vernietigingslijst {{ list }}. Probeer het opnieuw of neem contact op met de IT afdeling.",
18+
"subject_successful_deletion": "Lijst succesvol verwerkt",
19+
"body_successful_deletion": "Beste,\r\n\r\nLijst {{ list }} is succesvol verwerkt. Alle zaken en gerelateerde objecten zijn vernietigd."
1820
}
1921
}
2022
]

0 commit comments

Comments
 (0)