This repository has been 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
Remove user's avatar URL and displayname when deactivate an user with Admin API #8932
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
46373ae
Remove user's avatar URL when deactivate an user with Admin API
dklimpel 9298d3b
switch to use handler instead of store
dklimpel a2b1baa
Add removing displayname and move both to `erase` flag
dklimpel 3981a8d
Merge remote-tracking branch 'synapse/develop' into remove_avatar
dklimpel 8e404a1
fix tests
dklimpel 07df279
Apply suggestions from code review - Part 1
dklimpel ae9f36c
Apply suggestions from code review - Part 2
dklimpel fa5386e
Apply suggestions from code review
dklimpel 579fb8a
Add `by_admin` flag to deactivate_account_handler
dklimpel 81f2e66
Merge remote-tracking branch 'synapse/develop' into remove_avatar
dklimpel dab6941
Merge remote-tracking branch 'synapse/develop' into remove_avatar
dklimpel 53df1f8
Apply suggestions from code review - Part 1
dklimpel dbb619a
Apply suggestions from code review - Part 2
dklimpel 8cb8796
small fix
dklimpel 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 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 @@ | ||
Remove a user's avatar URL and display name when deactivated with the Admin API. |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -244,7 +244,7 @@ async def on_PUT(self, request, user_id): | |
|
||
if deactivate and not user["deactivated"]: | ||
await self.deactivate_account_handler.deactivate_account( | ||
target_user.to_string(), False | ||
target_user.to_string(), False, requester, by_admin=True | ||
) | ||
elif not deactivate and user["deactivated"]: | ||
if "password" not in body: | ||
|
@@ -486,12 +486,22 @@ async def on_GET(self, request, user_id): | |
class DeactivateAccountRestServlet(RestServlet): | ||
PATTERNS = admin_patterns("/deactivate/(?P<target_user_id>[^/]*)") | ||
|
||
def __init__(self, hs): | ||
def __init__(self, hs: "HomeServer"): | ||
self._deactivate_account_handler = hs.get_deactivate_account_handler() | ||
self.auth = hs.get_auth() | ||
self.is_mine = hs.is_mine | ||
self.store = hs.get_datastore() | ||
|
||
async def on_POST(self, request, target_user_id): | ||
async def on_POST(self, request: str, target_user_id: str) -> Tuple[int, JsonDict]: | ||
await assert_requester_is_admin(self.auth, request) | ||
|
||
if not self.is_mine(UserID.from_string(target_user_id)): | ||
raise SynapseError(400, "Can only lookup local users") | ||
dklimpel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if not await self.store.get_user_by_id(target_user_id): | ||
raise NotFoundError("User not found") | ||
|
||
requester = await self.auth.get_user_by_req(request) | ||
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. It seems like it would be better to move this to the top and then use |
||
body = parse_json_object_from_request(request, allow_empty_body=True) | ||
erase = body.get("erase", False) | ||
if not isinstance(erase, bool): | ||
|
@@ -501,10 +511,8 @@ async def on_POST(self, request, target_user_id): | |
Codes.BAD_JSON, | ||
) | ||
|
||
UserID.from_string(target_user_id) | ||
|
||
result = await self._deactivate_account_handler.deactivate_account( | ||
target_user_id, erase | ||
target_user_id, erase, requester, by_admin=True | ||
) | ||
if result: | ||
id_server_unbind_result = "success" | ||
|
This file contains 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only create a single
UserID
instance and re-use it.