This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Quarantine media by ID or user ID #6681
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
191005d
Add admin ability to quarantine media by id and user_id
anoadragon453 145b9c2
add tests
anoadragon453 bfc3819
Add documentation
anoadragon453 01501fb
Remove old comment
anoadragon453 f8fb980
Add to docstring
anoadragon453 b760f7b
Add changelog
anoadragon453 7514d9b
Split endpoints into multiple, delete dup'd methods
anoadragon453 cd66f2a
Fix up req/resp documentation
anoadragon453 c410a64
Fix bytes vs str in test
anoadragon453 3056850
Remove dupe
anoadragon453 06ab38a
Update changelog.d/6681.feature
anoadragon453 673f126
Rejig endpoints to be more extensible
anoadragon453 68c2eae
Merge branch 'anoa/quarantine_media_ids' of github.com:matrix-org/syn…
anoadragon453 3c95fe0
Remove unittest.DEBUG statements
anoadragon453 d6f6a72
Update workers.md to point media admin requests at media worker
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,23 +32,85 @@ class QuarantineMediaInRoom(RestServlet): | |
this server. | ||
""" | ||
|
||
PATTERNS = historical_admin_path_patterns("/quarantine_media/(?P<room_id>[^/]+)") | ||
PATTERNS = ( | ||
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>![^/]+)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra |
||
) | ||
|
||
def __init__(self, hs): | ||
self.store = hs.get_datastore() | ||
self.auth = hs.get_auth() | ||
|
||
async def on_POST(self, request, room_id): | ||
async def on_POST(self, request, room_id: str): | ||
requester = await self.auth.get_user_by_req(request) | ||
await assert_user_is_admin(self.auth, requester.user) | ||
|
||
logging.info("Quarantining room: %s", room_id) | ||
|
||
# Quarantine all media in this room | ||
num_quarantined = await self.store.quarantine_media_ids_in_room( | ||
room_id, requester.user.to_string() | ||
) | ||
|
||
return 200, {"num_quarantined": num_quarantined} | ||
|
||
|
||
class QuarantineMediaByUser(RestServlet): | ||
"""Quarantines all local media by a given user so that no one can download it via | ||
this server. | ||
""" | ||
|
||
PATTERNS = historical_admin_path_patterns( | ||
"/user/(?P<user_id>[^/]+)/media/quarantine" | ||
) | ||
|
||
def __init__(self, hs): | ||
self.store = hs.get_datastore() | ||
self.auth = hs.get_auth() | ||
|
||
async def on_POST(self, request, user_id: str): | ||
requester = await self.auth.get_user_by_req(request) | ||
await assert_user_is_admin(self.auth, requester.user) | ||
|
||
logging.info("Quarantining local media by user: %s", user_id) | ||
|
||
# Quarantine all media this user has uploaded | ||
num_quarantined = await self.store.quarantine_media_ids_by_user( | ||
user_id, requester.user.to_string() | ||
) | ||
|
||
return 200, {"num_quarantined": num_quarantined} | ||
|
||
|
||
class QuarantineMediaByID(RestServlet): | ||
"""Quarantines local or remote media by a given ID so that no one can download | ||
it via this server. | ||
""" | ||
|
||
PATTERNS = historical_admin_path_patterns( | ||
"/media/quarantine/(?P<server_name>[^/]+)/(?P<media_id>[^/]+)" | ||
) | ||
|
||
def __init__(self, hs): | ||
self.store = hs.get_datastore() | ||
self.auth = hs.get_auth() | ||
|
||
async def on_POST(self, request, server_name: str, media_id: str): | ||
requester = await self.auth.get_user_by_req(request) | ||
await assert_user_is_admin(self.auth, requester.user) | ||
|
||
logging.info("Quarantining local media by ID: %s/%s", server_name, media_id) | ||
|
||
# Quarantine this media id | ||
await self.store.quarantine_media_by_id( | ||
server_name, media_id, requester.user.to_string() | ||
) | ||
|
||
return 200, {} | ||
|
||
|
||
class ListMediaInRoom(RestServlet): | ||
"""Lists all of the media in a given room. | ||
""" | ||
|
@@ -94,4 +156,6 @@ def register_servlets_for_media_repo(hs, http_server): | |
""" | ||
PurgeMediaCacheRestServlet(hs).register(http_server) | ||
QuarantineMediaInRoom(hs).register(http_server) | ||
QuarantineMediaByID(hs).register(http_server) | ||
QuarantineMediaByUser(hs).register(http_server) | ||
ListMediaInRoom(hs).register(http_server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.