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

This commit is contained in:
Andrew Morgan 2020-01-22 11:05:50 +00:00 committed by GitHub
parent 5e52d8563b
commit aa9b00fb2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

1
changelog.d/6756.feature Normal file
View File

@ -0,0 +1 @@
Add new quarantine media admin APIs to quarantine by media ID or by user who uploaded the media.

View File

@ -36,7 +36,7 @@ class QuarantineMediaInRoom(RestServlet):
historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media/quarantine") historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media/quarantine")
+ +
# This path kept around for legacy reasons # 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): def __init__(self, hs):

View File

@ -516,7 +516,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
), ),
) )
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) self.register_user("room_admin", "pass", admin=True)
admin_user_tok = self.login("room_admin", "pass") admin_user_tok = self.login("room_admin", "pass")
@ -555,6 +555,9 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
) )
# Quarantine all media in the room # Quarantine all media in the room
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( url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
room_id room_id
) )
@ -611,6 +614,10 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
), ),
) )
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): def test_quarantine_all_media_by_user(self):
self.register_user("user_admin", "pass", admin=True) self.register_user("user_admin", "pass", admin=True)
admin_user_tok = self.login("user_admin", "pass") admin_user_tok = self.login("user_admin", "pass")