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
Admin API to delete media for a specific user #10558
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8997a25
Admin API to delete media for a specific user
dklimpel dc54e7a
newsfile
dklimpel ffcc70e
Merge branch 'matrix-org:develop' into delete_user_media
dklimpel a890a9f
Apply suggestions from code review - Part 1
dklimpel c38c13b
update doc and error msg
dklimpel dec168f
Update 10558.feature
richvdh 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 @@ | ||
| Admin API to delete several media for a specific user. |
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 |
|---|---|---|
|
|
@@ -443,8 +443,9 @@ The following fields are returned in the JSON response body: | |
| - `joined_rooms` - An array of `room_id`. | ||
| - `total` - Number of rooms. | ||
|
|
||
| ## User media | ||
|
|
||
| ## List media of a user | ||
| ### List media of a user | ||
|
||
| Gets a list of all local media that a specific `user_id` has created. | ||
| By default, the response is ordered by descending creation date and ascending media ID. | ||
| The newest media is on top. You can change the order with parameters | ||
|
|
@@ -543,21 +544,64 @@ The following fields are returned in the JSON response body: | |
|
|
||
| - `media` - An array of objects, each containing information about a media. | ||
| Media objects contain the following fields: | ||
|
|
||
| - `created_ts` - integer - Timestamp when the content was uploaded in ms. | ||
| - `last_access_ts` - integer - Timestamp when the content was last accessed in ms. | ||
| - `media_id` - string - The id used to refer to the media. | ||
| - `media_length` - integer - Length of the media in bytes. | ||
| - `media_type` - string - The MIME-type of the media. | ||
| - `quarantined_by` - string - The user ID that initiated the quarantine request | ||
| for this media. | ||
|
|
||
| - `safe_from_quarantine` - bool - Status if this media is safe from quarantining. | ||
| - `upload_name` - string - The name the media was uploaded with. | ||
|
|
||
| - `next_token`: integer - Indication for pagination. See above. | ||
| - `total` - integer - Total number of media. | ||
|
|
||
| ### Delete media of a user | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This API deletes the *local* media from the disk of your own server | ||
| that a specific `user_id` has created. This includes any local thumbnails. | ||
|
|
||
| This API will not affect media that has been uploaded to external | ||
| media repositories (e.g https://github.com/turt2live/matrix-media-repo/). | ||
|
|
||
| By default, the API delete ordered by descending creation date and ascending media ID. | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The newest media is on top. You can change the order with parameters | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| `order_by` and `dir`. If no `limit` is set the API delete `100` files per request. | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The API is: | ||
|
|
||
| ``` | ||
| DELETE /_synapse/admin/v1/users/<user_id>/media | ||
| ``` | ||
|
|
||
| To use it, you will need to authenticate by providing an `access_token` for a | ||
| server admin: [Admin API](../usage/administration/admin_api) | ||
|
|
||
| A response body like the following is returned: | ||
|
|
||
| ```json | ||
| { | ||
| "deleted_media": [ | ||
| "abcdefghijklmnopqrstuvwx" | ||
| ], | ||
| "total": 1 | ||
| } | ||
| ``` | ||
|
|
||
| The following fields are returned in the JSON response body: | ||
|
|
||
| * `deleted_media`: an array of strings - List of deleted `media_id` | ||
| * `total`: integer - Total number of deleted `media_id` | ||
|
|
||
| **Note**: There is no `next_token`. This is not useful for deleting media, because | ||
| after deleting media the remaining media have a new order. | ||
|
|
||
| **Parameters** | ||
|
|
||
| This API has the same parameters like [List media of a user](#list-media-of-a-user). | ||
dklimpel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| With the parameters you can for example limit the number of files to delete at once or | ||
| delete largest/smallest or newest/oldest files first. | ||
|
|
||
| ## Login as a user | ||
|
|
||
| Get an access token that can be used to authenticate as that user. Useful for | ||
|
|
||
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -811,10 +811,10 @@ async def on_GET( | |||||
| class UserMediaRestServlet(RestServlet): | ||||||
| """ | ||||||
| Gets information about all uploaded local media for a specific `user_id`. | ||||||
| With DELETE request you can delete all this media. | ||||||
|
|
||||||
| Example: | ||||||
| http://localhost:8008/_synapse/admin/v1/users/ | ||||||
| @user:server/media | ||||||
| http://localhost:8008/_synapse/admin/v1/users/@user:server/media | ||||||
|
|
||||||
| Args: | ||||||
| The parameters `from` and `limit` are required for pagination. | ||||||
|
|
@@ -830,6 +830,7 @@ def __init__(self, hs: "HomeServer"): | |||||
| self.is_mine = hs.is_mine | ||||||
| self.auth = hs.get_auth() | ||||||
| self.store = hs.get_datastore() | ||||||
| self.media_repository = hs.get_media_repository() | ||||||
|
|
||||||
| async def on_GET( | ||||||
| self, request: SynapseRequest, user_id: str | ||||||
|
|
@@ -898,6 +899,73 @@ async def on_GET( | |||||
|
|
||||||
| return 200, ret | ||||||
|
|
||||||
| async def on_DELETE( | ||||||
| self, request: SynapseRequest, user_id: str | ||||||
| ) -> Tuple[int, JsonDict]: | ||||||
| # This will always be set by the time Twisted calls us. | ||||||
| assert request.args is not None | ||||||
|
|
||||||
| await assert_requester_is_admin(self.auth, request) | ||||||
|
|
||||||
| if not self.is_mine(UserID.from_string(user_id)): | ||||||
| raise SynapseError(400, "Can only lookup local users") | ||||||
|
||||||
| raise SynapseError(400, "Can only lookup local users") | |
| raise SynapseError(400, "Can only look up local users") |
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.