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

Fix and add test to deprecated quarantine media admin api #6756

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6756.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new quarantine media admin APIs to quarantine by media ID or by user who uploaded the media.
2 changes: 1 addition & 1 deletion synapse/rest/admin/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QuarantineMediaInRoom(RestServlet):
historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media/quarantine")
+
# This path kept around for legacy reasons
historical_admin_path_patterns("/quarantine_media/(?P<room_id>![^/]+)")
historical_admin_path_patterns("/quarantine_media/(?P<room_id>[^/]+)")
)

def __init__(self, hs):
Expand Down
15 changes: 11 additions & 4 deletions tests/rest/admin/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def test_quarantine_media_by_id(self):
),
)

def test_quarantine_all_media_in_room(self):
def test_quarantine_all_media_in_room(self, override_url_template=None):
self.register_user("room_admin", "pass", admin=True)
admin_user_tok = self.login("room_admin", "pass")

Expand Down Expand Up @@ -555,9 +555,12 @@ def test_quarantine_all_media_in_room(self):
)

# Quarantine all media in the room
url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
room_id
)
if override_url_template:
url = override_url_template % urllib.parse.quote(room_id)
else:
url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
room_id
)
request, channel = self.make_request("POST", url, access_token=admin_user_tok,)
self.render(request)
self.pump(1.0)
Expand Down Expand Up @@ -611,6 +614,10 @@ def test_quarantine_all_media_in_room(self):
),
)

def test_quaraantine_all_media_in_room_deprecated_api_path(self):
# Perform the above test with the deprecated API path
self.test_quarantine_all_media_in_room("/_synapse/admin/v1/quarantine_media/%s")

def test_quarantine_all_media_by_user(self):
self.register_user("user_admin", "pass", admin=True)
admin_user_tok = self.login("user_admin", "pass")
Expand Down