Only include user conflicts in admin reports once

This commit is contained in:
s3lph 2022-04-23 01:07:56 +02:00
parent f34eecd6ee
commit 5688aba562
4 changed files with 20 additions and 6 deletions

View file

@ -3,13 +3,14 @@
<!-- BEGIN RELEASE v0.1.3 -->
## Version 0.1.3
Bugfix release
Bugfixes and small improvements in reporting
### Changes
<!-- BEGIN CHANGES 0.1.3 -->
- RFC 3156 compliance: Don't base64-encode encrypted reports
- Include conflicts in admin reports
- Fix: user conflict message emails were sent multiple times to chosen email
<!-- END CHANGES 0.1.3 -->
<!-- END RELEASE v0.1.3 -->

View file

@ -172,7 +172,7 @@ class UserConflictMessage(Message):
super().__init__(
schleuder=schleuder,
mail_from=mail_from,
mail_to=chosen.email,
mail_to=subscriber,
content=content,
encrypt_to=[chosen.key.blob]
)
@ -205,8 +205,19 @@ class AdminReport(Message):
if len(subscribed) == 0 and len(unsubscribed) == 0 and len(removed) == 0 \
and len(added) == 0 and len(updated) == 0 and len(conflicts) == 0:
raise ValueError('No changes, not creating admin report')
key_conflicts = [m for m in conflicts if m is not None and isinstance(m, KeyConflictMessage)]
user_conflicts = [m for m in conflicts if m is not None and isinstance(m, UserConflictMessage)]
key_conflicts: List[KeyConflictMessage] =\
[m for m in conflicts if m is not None and isinstance(m, KeyConflictMessage)]
_user_conflicts: Dict[str, UserConflictMessage] = {}
# Make sure the user conflicts are unique
for m in conflicts:
if m is None or not isinstance(m, UserConflictMessage):
continue
assert m._chosen.key is not None
fpr = m._chosen.key.fingerprint
if fpr not in _user_conflicts:
_user_conflicts[fpr] = m
user_conflicts: List[UserConflictMessage] = list(_user_conflicts.values())
# Assemble the content
content = f'''
== Admin Report for MultiSchleuder {schleuder} ==
'''

View file

@ -29,7 +29,8 @@ def one_of_each_kind():
unsubscribed={sub},
updated={},
added={},
removed={})
removed={},
conflicts=[])
msg3 = UserConflictMessage(
schleuder='test@example.org',
subscriber='bar@example.org',

View file

@ -187,7 +187,8 @@ class TestSmtpClient(unittest.TestCase):
unsubscribed={sub},
updated={},
added={},
removed={})
removed={},
conflicts=[])
client.send_messages([msg1, msg2])
ctrl.stop()
self.assertTrue(ctrl.handler.connected)