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
Update server notices user profile in room if changed #12115
Merged
clokep
merged 12 commits into
matrix-org:develop
from
watson28:update-server-notice-user-profile
Apr 8, 2022
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9615944
Update server notice profile in room if changed
watson28 809483d
add Changelog
watson28 d953606
fix failing test_resource_limits_server_notices
watson28 b3359ce
Merge branch 'develop' into update-server-notice-user-profile
watson28 4a7a6fa
Remove unsupported kwargs call_args uses in Python 3.7
watson28 9fb033a
Merge branch 'develop' into update-server-notice-user-profile
watson28 2b41d29
address review comments
watson28 6d02699
Merge branch 'develop' into update-server-notice-user-profile
watson28 d423e75
fix tests
watson28 48cab46
address review comments
watson28 bd7303d
Merge branch 'develop' into update-server-notice-user-profile
watson28 910b858
format test_server_notice.py file
watson28 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 @@ | ||
Fix a long-standing bug that updating the server notices user profile (display name/avatar URL) in the configuration would not be applied to pre-existing rooms. Contributed by Jorge Florian. |
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -240,7 +240,13 @@ def test_send_server_notice(self) -> None: | |||||||||||||||||
self.assertEqual(messages[1]["content"]["body"], "test msg two") | ||||||||||||||||||
self.assertEqual(messages[1]["sender"], "@notices:test") | ||||||||||||||||||
|
||||||||||||||||||
@override_config({"server_notices": {"system_mxid_localpart": "notices"}}) | ||||||||||||||||||
@override_config( | ||||||||||||||||||
{ | ||||||||||||||||||
"server_notices": { | ||||||||||||||||||
"system_mxid_localpart": "notices", | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
) | ||||||||||||||||||
def test_send_server_notice_leave_room(self) -> None: | ||||||||||||||||||
""" | ||||||||||||||||||
Tests that sending a server notices is successfully. | ||||||||||||||||||
|
@@ -409,6 +415,110 @@ def test_send_server_notice_delete_room(self) -> None: | |||||||||||||||||
# second room has new ID | ||||||||||||||||||
self.assertNotEqual(first_room_id, second_room_id) | ||||||||||||||||||
|
||||||||||||||||||
@override_config( | ||||||||||||||||||
{ | ||||||||||||||||||
"server_notices": { | ||||||||||||||||||
"system_mxid_localpart": "notices", | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
) | ||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||
def test_update_notice_user_name_when_changed(self) -> None: | ||||||||||||||||||
""" | ||||||||||||||||||
Tests that existing server notices user name in room is updated after | ||||||||||||||||||
server notice config changes. | ||||||||||||||||||
""" | ||||||||||||||||||
server_notice_request_content = { | ||||||||||||||||||
"user_id": self.other_user, | ||||||||||||||||||
"content": {"msgtype": "m.text", "body": "test msg one"}, | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
self.make_request( | ||||||||||||||||||
"POST", | ||||||||||||||||||
self.url, | ||||||||||||||||||
access_token=self.admin_user_tok, | ||||||||||||||||||
content=server_notice_request_content, | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
# simulate a change in server config after a server restart. | ||||||||||||||||||
new_display_name = "new display name" | ||||||||||||||||||
self.server_notices_manager._config.servernotices.server_notices_mxid_display_name = ( | ||||||||||||||||||
new_display_name | ||||||||||||||||||
) | ||||||||||||||||||
self.server_notices_manager.get_or_create_notice_room_for_user.cache.invalidate_all() | ||||||||||||||||||
|
||||||||||||||||||
self.make_request( | ||||||||||||||||||
"POST", | ||||||||||||||||||
self.url, | ||||||||||||||||||
access_token=self.admin_user_tok, | ||||||||||||||||||
content=server_notice_request_content, | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0) | ||||||||||||||||||
notice_room_id = invited_rooms[0].room_id | ||||||||||||||||||
self.helper.join( | ||||||||||||||||||
room=notice_room_id, user=self.other_user, tok=self.other_user_token | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
notice_user_state_in_room = self.helper.get_state( | ||||||||||||||||||
notice_room_id, | ||||||||||||||||||
"m.room.member", | ||||||||||||||||||
self.other_user_token, | ||||||||||||||||||
state_key="@notices:test", | ||||||||||||||||||
) | ||||||||||||||||||
self.assertEqual(notice_user_state_in_room["displayname"], new_display_name) | ||||||||||||||||||
|
||||||||||||||||||
@override_config( | ||||||||||||||||||
{ | ||||||||||||||||||
"server_notices": { | ||||||||||||||||||
"system_mxid_localpart": "notices", | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
) | ||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||
def test_update_notice_user_avatar_when_changed(self) -> None: | ||||||||||||||||||
""" | ||||||||||||||||||
Tests that existing server notices user avatar in room is updated when is | ||||||||||||||||||
different from the one in homeserver config. | ||||||||||||||||||
""" | ||||||||||||||||||
server_notice_request_content = { | ||||||||||||||||||
"user_id": self.other_user, | ||||||||||||||||||
"content": {"msgtype": "m.text", "body": "test msg one"}, | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
self.make_request( | ||||||||||||||||||
"POST", | ||||||||||||||||||
self.url, | ||||||||||||||||||
access_token=self.admin_user_tok, | ||||||||||||||||||
content=server_notice_request_content, | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
# simulate a change in server config after a server restart. | ||||||||||||||||||
new_avatar_url = "test/new-url" | ||||||||||||||||||
self.server_notices_manager._config.servernotices.server_notices_mxid_avatar_url = ( | ||||||||||||||||||
new_avatar_url | ||||||||||||||||||
) | ||||||||||||||||||
self.server_notices_manager.get_or_create_notice_room_for_user.cache.invalidate_all() | ||||||||||||||||||
|
||||||||||||||||||
self.make_request( | ||||||||||||||||||
"POST", | ||||||||||||||||||
self.url, | ||||||||||||||||||
access_token=self.admin_user_tok, | ||||||||||||||||||
content=server_notice_request_content, | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
invited_rooms = self._check_invite_and_join_status(self.other_user, 1, 0) | ||||||||||||||||||
notice_room_id = invited_rooms[0].room_id | ||||||||||||||||||
self.helper.join( | ||||||||||||||||||
room=notice_room_id, user=self.other_user, tok=self.other_user_token | ||||||||||||||||||
) | ||||||||||||||||||
|
||||||||||||||||||
notice_user_state = self.helper.get_state( | ||||||||||||||||||
notice_room_id, | ||||||||||||||||||
"m.room.member", | ||||||||||||||||||
self.other_user_token, | ||||||||||||||||||
state_key="@notices:test", | ||||||||||||||||||
) | ||||||||||||||||||
self.assertEqual(notice_user_state["avatar_url"], new_avatar_url) | ||||||||||||||||||
|
||||||||||||||||||
def _check_invite_and_join_status( | ||||||||||||||||||
self, user_id: str, expected_invites: int, expected_memberships: int | ||||||||||||||||||
) -> List[RoomsForUser]: | ||||||||||||||||||
|
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.