Skip to content

Commit 64ec5cd

Browse files
committed
feat(moderation): handle actor_id and note in user block callback
1 parent f0ce5b6 commit 64ec5cd

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • invenio_communities/requests/user_moderation

invenio_communities/requests/user_moderation/actions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,26 @@ def on_block(user_id, uow=None, **kwargs):
6868
of an HTTP request!
6969
"""
7070
user_id = str(user_id)
71-
tombstone_data = {"note": _("User was blocked")}
71+
# Resolve the lazy translation now; Celery can't serialize LazyString.
72+
tombstone_data = {"note": kwargs.get("note") or str(_("User was blocked"))}
7273

73-
# set the removal reason if the vocabulary item exists
74+
# Set the removal reason if the vocabulary item exists
7475
try:
75-
removal_reason_id = kwargs.get("removal_reason_id", "misconduct")
76+
removal_reason_id = kwargs.get("removal_reason_id") or "misconduct"
7677
vocab = vocab_service.read(
7778
identity=system_identity, id_=("removalreasons", removal_reason_id)
7879
)
7980
tombstone_data["removal_reason"] = {"id": vocab.id}
8081
except PIDDoesNotExistError:
8182
pass
8283

83-
# soft-delete all the communities of that user (only if they are the only owner)
84+
# Use the actor who triggered the block on the tombstone; without
85+
# this tombstones would attribute the removal to the system (identity).
86+
actor_id = kwargs.get("actor_id")
87+
if actor_id is not None:
88+
tombstone_data["removed_by"] = {"user": str(actor_id)}
89+
90+
# Soft-delete all the communities of that user (only if they are the only owner)
8491
for comm in _get_communities_for_user(user_id):
8592
delete_community.delay(comm.pid.pid_value, tombstone_data)
8693

0 commit comments

Comments
 (0)