Skip to content

Commit 5e1cc0b

Browse files
Julian Roelandsvenvandescheur
Julian Roeland
authored andcommitted
🎨 - refactor: translations and improvementent of audit log text
1 parent ab92872 commit 5e1cc0b

17 files changed

+2815
-387
lines changed

backend/src/openarchiefbeheer/conf/locale/en/LC_MESSAGES/django.po

+1,777
Large diffs are not rendered by default.

backend/src/openarchiefbeheer/conf/locale/nl/LC_MESSAGES/django.po

+950-338
Large diffs are not rendered by default.

backend/src/openarchiefbeheer/destruction/tests/endpoints/test_abort_destruction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def test_abort_list_destruction(self):
127127
self.assertEqual(
128128
message,
129129
_(
130-
'The destruction of destruction list "%(list_name)s" was aborted by record '
131-
'manager %(record_manager)s with reason: "%(comment)s".'
130+
'User "%(record_manager)s" with the role of "" has aborted the destruction of destruction list "%(list_name)s" '
131+
'with reason: "%(comment)s".'
132132
)
133133
% {
134134
"list_name": "A test list",

backend/src/openarchiefbeheer/destruction/tests/endpoints/test_co_reviewers.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ def test_fully_update_co_reviewers(self):
130130
message = logs[0].get_message()
131131
self.assertIn(
132132
_(
133-
'User "%(user)s" has replaced all the co-reviewers of the list '
133+
'User "%(user)s" with the role of "%(role)s" has replaced all the co-reviewers of the list '
134134
'"%(list_name)s" with: %(added_co_reviewers)s.'
135135
)
136136
% {
137+
"role": "",
137138
"user": main_reviewer.user,
138139
"list_name": "A beautiful list",
139140
"added_co_reviewers": ", ".join(
@@ -245,10 +246,11 @@ def test_partially_update_co_reviewers(self):
245246
message = logs[0].get_message()
246247
self.assertIn(
247248
_(
248-
'User "%(user)s" has added these users as co-reviewers to the list '
249+
'User "%(user)s" with the role of "%(role)s" has added these users as co-reviewers to the list '
249250
'"%(list_name)s": %(added_co_reviewers)s.'
250251
)
251252
% {
253+
"role": "",
252254
"user": main_reviewer.user,
253255
"list_name": "A beautiful list",
254256
"added_co_reviewers": ", ".join(

backend/src/openarchiefbeheer/destruction/tests/endpoints/test_reviewresponse.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ def test_audit_log(self):
237237
)
238238
self.assertEqual(
239239
data[0]["message"],
240-
_('Destruction list "%(list_name)s" was reassigned.')
241-
% {"list_name": "Test audittrail"},
240+
_(
241+
'User "%(user)s" with the role of "" has reassigned destruction list "%(list_name)s".'
242+
)
243+
% {"list_name": "Test audittrail", "user": record_manager},
242244
)
243245
self.assertEqual(
244246
data[0]["extra_data"]["assignee"]["user"],

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,11 @@ def test_mark_as_final(self):
567567
self.assertEqual(
568568
message.strip("\n"),
569569
_(
570-
'Destruction list "%(list_name)s" was made final by the record manager '
571-
"%(record_manager)s who assigned it to the archivist %(archivist)s."
570+
'User "%(user)s" with the role of "" has made destruction list "%(list_name)s" final and '
571+
"assigned it to the archivist %(archivist)s."
572572
)
573573
% {
574+
"user": record_manager,
574575
"list_name": "A test list",
575576
"record_manager": "record_manager",
576577
"archivist": "archivist",

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ def test_create_destruction_list(self):
111111

112112
self.assertEqual(
113113
message,
114-
_('Destruction list "%(list_name)s" created by user %(author)s.')
114+
_(
115+
'User "%(author)s" with the role of "" has created destruction list "%(list_name)s".'
116+
)
115117
% {"list_name": "A test list", "author": "Jeffrey Jones (record_manager)"},
116118
)
117119

@@ -264,8 +266,10 @@ def test_full_list_update(self):
264266

265267
self.assertEqual(
266268
message,
267-
_('Destruction list "%(list_name)s" was updated.')
268-
% {"list_name": "An updated test list"},
269+
_(
270+
'User "%(user)s" with the role of "" has updated destruction list "%(list_name)s".'
271+
)
272+
% {"list_name": "An updated test list", "user": record_manager},
269273
)
270274

271275
def test_partial_list_update(self):
@@ -1044,7 +1048,7 @@ def test_create_review_rejected(self):
10441048
self.assertFalse(logs[0].extra_data["approved"])
10451049
self.assertEqual(
10461050
logs[0].get_message(),
1047-
'User "Jeffrey Jones (reviewer)" has reviewed the list "Test list". The destruction list was rejected.',
1051+
'User "Jeffrey Jones (reviewer)" with the role of "" has reviewed the list "Test list". The destruction list was rejected.',
10481052
)
10491053

10501054
def test_reviewing_cases_not_in_destruction_list(self):

backend/src/openarchiefbeheer/logging/logevent.py

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import traceback
22

3-
from django.db.models import Model
4-
53
from timeline_logger.models import TimelineLog
64

5+
from openarchiefbeheer.accounts.api.serializers import UserSerializer
76
from openarchiefbeheer.accounts.models import User
87
from openarchiefbeheer.destruction.models import (
98
DestructionList,
@@ -13,22 +12,34 @@
1312
)
1413

1514

16-
def _create_log(
17-
model: Model, event: str, extra_data: dict | None = None, user: User | None = None
15+
def _create_log_destruction_list(
16+
destruction_list: DestructionList,
17+
event: str,
18+
extra_data: dict | None = None,
19+
user: User | None = None,
1820
) -> TimelineLog:
21+
serialized_user = UserSerializer(user).data if user else {}
22+
user_groups = [group.name for group in user.groups.all()] if user else []
23+
24+
combined_extra_data = {
25+
**(extra_data or {}),
26+
"user": serialized_user,
27+
"groups": user_groups,
28+
}
29+
1930
return TimelineLog.objects.create(
20-
content_object=model,
31+
content_object=destruction_list,
2132
template=f"logging/{event}.txt",
22-
extra_data=extra_data,
33+
extra_data=combined_extra_data,
2334
user=user,
2435
)
2536

2637

2738
def destruction_list_created(
2839
destruction_list: DestructionList, author: User, reviewer: User
2940
) -> None:
30-
_create_log(
31-
model=destruction_list,
41+
_create_log_destruction_list(
42+
destruction_list=destruction_list,
3243
event="destruction_list_created",
3344
user=author,
3445
extra_data={
@@ -44,7 +55,9 @@ def destruction_list_created(
4455

4556

4657
def destruction_list_updated(destruction_list: DestructionList, user: User) -> None:
47-
_create_log(model=destruction_list, event="destruction_list_updated", user=user)
58+
_create_log_destruction_list(
59+
destruction_list=destruction_list, event="destruction_list_updated", user=user
60+
)
4861

4962

5063
def destruction_list_reassigned(
@@ -53,8 +66,8 @@ def destruction_list_reassigned(
5366
comment: str,
5467
user: User,
5568
) -> None:
56-
_create_log(
57-
model=destruction_list,
69+
_create_log_destruction_list(
70+
destruction_list=destruction_list,
5871
event="destruction_list_reassigned",
5972
user=user,
6073
extra_data={
@@ -78,8 +91,8 @@ def destruction_list_co_reviewers_added(
7891
comment: str,
7992
user: User,
8093
):
81-
_create_log(
82-
model=destruction_list,
94+
_create_log_destruction_list(
95+
destruction_list=destruction_list,
8396
event="destruction_list_co_reviewers_added",
8497
user=user,
8598
extra_data={
@@ -100,8 +113,8 @@ def destruction_list_co_reviewers_added(
100113
def destruction_list_reviewed(
101114
destruction_list: DestructionList, review: DestructionListReview, user: User
102115
) -> None:
103-
_create_log(
104-
model=destruction_list,
116+
_create_log_destruction_list(
117+
destruction_list=destruction_list,
105118
event="destruction_list_reviewed",
106119
user=user,
107120
extra_data={"approved": review.decision == ReviewDecisionChoices.accepted},
@@ -114,8 +127,8 @@ def destruction_list_finalized(
114127
archivist: User,
115128
record_manager: User,
116129
) -> None:
117-
_create_log(
118-
model=destruction_list,
130+
_create_log_destruction_list(
131+
destruction_list=destruction_list,
119132
event="destruction_list_finalized",
120133
user=record_manager,
121134
extra_data={
@@ -136,8 +149,8 @@ def destruction_list_aborted(
136149
comment: str,
137150
record_manager: User,
138151
):
139-
_create_log(
140-
model=destruction_list,
152+
_create_log_destruction_list(
153+
destruction_list=destruction_list,
141154
event="destruction_list_aborted",
142155
user=record_manager,
143156
extra_data={
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name record_manager=log.user comment=log.extra_data.comment %}
2-
The destruction of destruction list "{{ list_name }}" was aborted by record manager {{ record_manager }} with reason: "{{ comment }}".
1+
{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name role=log.extra_data.groups.0 record_manager=log.user comment=log.extra_data.comment %}
2+
User "{{ record_manager }}" with the role of "{{ role }}" has aborted the destruction of destruction list "{{ list_name }}" with reason: "{{ comment }}".
33
{% endblocktranslate %}

backend/src/openarchiefbeheer/logging/templates/logging/destruction_list_co_reviewers_added.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{% load i18n %}{% with added_co_reviewers=log.extra_data.added_co_reviewers|join:", " %}{% with removed_co_reviewers=log.extra_data.removed_co_reviewers|join:", " %}
22
{% if log.extra_data.partial %}
3-
{% blocktranslate trimmed with list_name=log.content_object.name user=log.user added_co_reviewers=added_co_reviewers %}
4-
User "{{ user }}" has added these users as co-reviewers to the list "{{ list_name }}": {{ added_co_reviewers }}.
3+
{% blocktranslate trimmed with role=log.extra_data.groups.0 list_name=log.content_object.name user=log.user added_co_reviewers=added_co_reviewers %}
4+
User "{{ user }}" with the role of "{{ role }}" has added these users as co-reviewers to the list "{{ list_name }}": {{ added_co_reviewers }}.
55
{% endblocktranslate %}
66
{% if removed_co_reviewers %}
77
{% blocktranslate trimmed with removed_co_reviewers=removed_co_reviewers %}
88
They also removed these co-reviewers: {{ removed_co_reviewers }}.
99
{% endblocktranslate %}
1010
{% endif %}
1111
{% else %}
12-
{% blocktranslate trimmed with list_name=log.content_object.name user=log.user added_co_reviewers=added_co_reviewers %}
13-
User "{{ user }}" has replaced all the co-reviewers of the list "{{ list_name }}" with: {{ added_co_reviewers }}.
12+
{% blocktranslate trimmed with list_name=log.content_object.name role=log.extra_data.groups.0 user=log.user added_co_reviewers=added_co_reviewers %}
13+
User "{{ user }}" with the role of "{{ role }}" has replaced all the co-reviewers of the list "{{ list_name }}" with: {{ added_co_reviewers }}.
1414
{% endblocktranslate %}
1515
{% endif %}
1616

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name author=log.user %}
2-
Destruction list "{{ list_name }}" created by user {{ author }}.
1+
{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name role=log.extra_data.groups.0 author=log.user %}
2+
User "{{ author }}" with the role of "{{ role }}" has created destruction list "{{ list_name }}".
33
{% endblocktranslate %}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{% load i18n %}
2-
{% blocktranslate trimmed with list_name=log.content_object.name record_manager=log.user.username archivist=log.extra_data.archivist.username %}
3-
Destruction list "{{ list_name }}" was made final by the record manager {{ record_manager }} who assigned it to the archivist {{ archivist }}.
2+
{% blocktranslate trimmed with list_name=log.content_object.name role=log.extra_data.groups.0 user=log.user record_manager=log.user.username archivist=log.extra_data.archivist.username %}
3+
User "{{ user }}" with the role of "{{ role }}" has made destruction list "{{ list_name }}" final and assigned it to the archivist {{ archivist }}.
44
{% endblocktranslate %}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{% load i18n %}{% blocktranslate trimmed with timestamp=log.timestamp|date:"c" list_name=log.content_object.name %}
2-
Destruction list "{{ list_name }}" was reassigned.
1+
{% load i18n %}{% blocktranslate trimmed with timestamp=log.timestamp|date:"c" list_name=log.content_object.name role=log.extra_data.groups.0 user=log.user %}
2+
User "{{ user }}" with the role of "{{ role }}" has reassigned destruction list "{{ list_name }}".
33
{% endblocktranslate %}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{% load i18n %}{% blocktranslate trimmed with timestamp=log.timestamp|date:"c" list_name=log.content_object.name user=log.user %}
2-
User "{{ user }}" has reviewed the list "{{ list_name }}". {% endblocktranslate %}{% if log.extra_data.approved %}{% translate " The destruction list was approved." %}{% else %}{% translate " The destruction list was rejected." %}{% endif %}
1+
{% load i18n %}{% blocktranslate trimmed with timestamp=log.timestamp|date:"c" list_name=log.content_object.name role=log.extra_data.groups.0 user=log.user %}
2+
User "{{ user }}" with the role of "{{ role }}" has reviewed the list "{{ list_name }}". {% endblocktranslate %}{% if log.extra_data.approved %}{% translate " The destruction list was approved." %}{% else %}{% translate " The destruction list was rejected." %}{% endif %}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name %}
2-
Destruction list "{{ list_name }}" was updated.
1+
{% load i18n %}{% blocktranslate trimmed with list_name=log.content_object.name role=log.extra_data.groups.0 user=log.user %}
2+
User "{{ user }}" with the role of "{{ role }}" has updated destruction list "{{ list_name }}".
33
{% endblocktranslate %}

frontend/src/components/DestructionListAuditLog/DestructionListAuditLog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DataGrid } from "@maykin-ui/admin-ui";
22

33
import { useAuditLog } from "../../hooks";
44
import { DestructionList } from "../../lib/api/destructionLists";
5-
import { formatDate } from "../../lib/format/date";
5+
import { formatDateAndTime } from "../../lib/format/date";
66
import { formatUser } from "../../lib/format/user";
77

88
/**
@@ -16,7 +16,7 @@ export function DestructionListAuditLog({
1616
const logItems = useAuditLog(destructionList);
1717

1818
const objectList = logItems.map((logItem) => ({
19-
Datum: formatDate(logItem.timestamp),
19+
Datum: formatDateAndTime(logItem.timestamp),
2020
"Gewijzigd door": formatUser(logItem.user),
2121
Wijziging: logItem.message,
2222
}));

frontend/src/lib/format/date.ts

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ export function formatDate(date: Date | string, format: "nl" | "iso" = "nl") {
1414
return _format(_date, "dd/MM/yyyy");
1515
}
1616

17+
/**
18+
* Formats date and time.
19+
* @param date
20+
* @param format
21+
* @returns Formatted date and time.
22+
*/
23+
export function formatDateAndTime(
24+
date: Date | string,
25+
format: "nl" | "iso" = "nl",
26+
) {
27+
const _date = new Date(date);
28+
if (format === "iso") {
29+
return formatISO(date, { representation: "date" });
30+
}
31+
return _format(_date, "dd/MM/yyyy HH:mm");
32+
}
33+
1734
/**
1835
* Options for customizing the output of the timeAgo function.
1936
*/

0 commit comments

Comments
 (0)