Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Admin API endpoint to redact all a user's events #17506

Merged
merged 15 commits into from
Sep 18, 2024
2 changes: 1 addition & 1 deletion docs/admin_api/user_admin_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1440,4 +1440,4 @@ The following fields are returned in the JSON response body:
- failed_redactions: a dict where the keys are event ids the process was unable to redact, if any, and the values are
the corresponding error that caused the redaction to fail

_Added in Synapse 1.115.0._
_Added in Synapse 1.116.0._
2 changes: 1 addition & 1 deletion synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ async def _redact_all_events(
if event.type == "m.room.member":
content = event.content
if content:
if content.get("membership") == "Membership.JOIN":
if content.get("membership") == "join":
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
pass
else:
continue
Expand Down
20 changes: 13 additions & 7 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5117,7 +5117,8 @@ def test_redact_messages_all_rooms(self) -> None:
"""
Test that request to redact events in all rooms user is member of is successful
"""
# create rooms, some with updated redaction rules
# create rooms - room versions 11+ store the `redacts` key in content while
# earlier ones don't so we use a mix of room versions
rm1 = self.helper.create_room_as(
self.admin, tok=self.admin_tok, room_version="7"
)
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -5129,7 +5130,8 @@ def test_redact_messages_all_rooms(self) -> None:
# join rooms, send some messages
originals = []
for rm in [rm1, rm2, rm3]:
self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
join = self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
originals.append(join["event_id"])
for i in range(15):
event = {"body": f"hello{i}", "msgtype": "m.text"}
res = self.helper.send_event(
Expand Down Expand Up @@ -5179,7 +5181,8 @@ def test_redact_messages_specific_rooms(self) -> None:

originals = []
for rm in [rm1, rm2, rm3]:
self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
join = self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
originals.append(join["event_id"])
for i in range(15):
event = {"body": f"hello{i}", "msgtype": "m.text"}
res = self.helper.send_event(
Expand Down Expand Up @@ -5214,8 +5217,8 @@ def test_redact_messages_specific_rooms(self) -> None:
and event["redacts"] == event_id
):
matches.append((event_id, event))
# we redacted 15 messages
self.assertEqual(len(matches), 15)
# we redacted 16 messages
self.assertEqual(len(matches), 16)

channel = self.make_request(
"GET", f"rooms/{rm2}/messages?limit=50", access_token=self.admin_tok
Expand All @@ -5238,7 +5241,9 @@ def test_redact_status(self) -> None:

originals = []
for rm in [rm1, rm2, rm3]:
self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
join = self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
if rm == rm2:
originals.append(join["event_id"])
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
for i in range(5):
event = {"body": f"hello{i}", "msgtype": "m.text"}
res = self.helper.send_event(
Expand Down Expand Up @@ -5307,7 +5312,8 @@ def test_admin_redact_works_if_user_kicked_or_banned(self) -> None:

originals = []
for rm in [rm1, rm2, rm3]:
self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
join = self.helper.join(rm, self.bad_user, tok=self.bad_user_tok)
originals.append(join["event_id"])
for i in range(5):
event = {"body": f"hello{i}", "msgtype": "m.text"}
res = self.helper.send_event(
Expand Down
Loading