Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit aa9b00f

Browse files
Fix and add test to deprecated quarantine media admin api (#6756)
1 parent 5e52d85 commit aa9b00f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

changelog.d/6756.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new quarantine media admin APIs to quarantine by media ID or by user who uploaded the media.

synapse/rest/admin/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QuarantineMediaInRoom(RestServlet):
3636
historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media/quarantine")
3737
+
3838
# This path kept around for legacy reasons
39-
historical_admin_path_patterns("/quarantine_media/(?P<room_id>![^/]+)")
39+
historical_admin_path_patterns("/quarantine_media/(?P<room_id>[^/]+)")
4040
)
4141

4242
def __init__(self, hs):

tests/rest/admin/test_admin.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def test_quarantine_media_by_id(self):
516516
),
517517
)
518518

519-
def test_quarantine_all_media_in_room(self):
519+
def test_quarantine_all_media_in_room(self, override_url_template=None):
520520
self.register_user("room_admin", "pass", admin=True)
521521
admin_user_tok = self.login("room_admin", "pass")
522522

@@ -555,9 +555,12 @@ def test_quarantine_all_media_in_room(self):
555555
)
556556

557557
# Quarantine all media in the room
558-
url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
559-
room_id
560-
)
558+
if override_url_template:
559+
url = override_url_template % urllib.parse.quote(room_id)
560+
else:
561+
url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
562+
room_id
563+
)
561564
request, channel = self.make_request("POST", url, access_token=admin_user_tok,)
562565
self.render(request)
563566
self.pump(1.0)
@@ -611,6 +614,10 @@ def test_quarantine_all_media_in_room(self):
611614
),
612615
)
613616

617+
def test_quaraantine_all_media_in_room_deprecated_api_path(self):
618+
# Perform the above test with the deprecated API path
619+
self.test_quarantine_all_media_in_room("/_synapse/admin/v1/quarantine_media/%s")
620+
614621
def test_quarantine_all_media_by_user(self):
615622
self.register_user("user_admin", "pass", admin=True)
616623
admin_user_tok = self.login("user_admin", "pass")

0 commit comments

Comments
 (0)