Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e157c63

Browse files
Fix missing conditional for registering on_remove_user_third_party_identifier module api callbacks (#15227
1 parent 9418344 commit e157c63

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

changelog.d/15227.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.79.0rc1 where attempting to register a `on_remove_user_third_party_identifier` module API callback would be a no-op.

synapse/events/third_party_rules.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ def register_third_party_rules_callbacks(
247247
on_add_user_third_party_identifier
248248
)
249249

250+
if on_remove_user_third_party_identifier is not None:
251+
self._on_remove_user_third_party_identifier_callbacks.append(
252+
on_remove_user_third_party_identifier
253+
)
254+
250255
async def check_event_allowed(
251256
self,
252257
event: EventBase,

tests/rest/client/test_third_party_rules.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -941,18 +941,16 @@ def test_on_add_and_remove_user_third_party_identifier(self) -> None:
941941
just before associating and removing a 3PID to/from an account.
942942
"""
943943
# Pretend to be a Synapse module and register both callbacks as mocks.
944-
third_party_rules = self.hs.get_third_party_event_rules()
945944
on_add_user_third_party_identifier_callback_mock = Mock(
946945
return_value=make_awaitable(None)
947946
)
948947
on_remove_user_third_party_identifier_callback_mock = Mock(
949948
return_value=make_awaitable(None)
950949
)
951-
third_party_rules._on_threepid_bind_callbacks.append(
952-
on_add_user_third_party_identifier_callback_mock
953-
)
954-
third_party_rules._on_threepid_bind_callbacks.append(
955-
on_remove_user_third_party_identifier_callback_mock
950+
third_party_rules = self.hs.get_third_party_event_rules()
951+
third_party_rules.register_third_party_rules_callbacks(
952+
on_add_user_third_party_identifier=on_add_user_third_party_identifier_callback_mock,
953+
on_remove_user_third_party_identifier=on_remove_user_third_party_identifier_callback_mock,
956954
)
957955

958956
# Register an admin user.
@@ -1008,12 +1006,12 @@ def test_on_remove_user_third_party_identifier_is_called_on_deactivate(
10081006
when a user is deactivated and their third-party ID associations are deleted.
10091007
"""
10101008
# Pretend to be a Synapse module and register both callbacks as mocks.
1011-
third_party_rules = self.hs.get_third_party_event_rules()
10121009
on_remove_user_third_party_identifier_callback_mock = Mock(
10131010
return_value=make_awaitable(None)
10141011
)
1015-
third_party_rules._on_threepid_bind_callbacks.append(
1016-
on_remove_user_third_party_identifier_callback_mock
1012+
third_party_rules = self.hs.get_third_party_event_rules()
1013+
third_party_rules.register_third_party_rules_callbacks(
1014+
on_remove_user_third_party_identifier=on_remove_user_third_party_identifier_callback_mock,
10171015
)
10181016

10191017
# Register an admin user.
@@ -1039,6 +1037,9 @@ def test_on_remove_user_third_party_identifier_is_called_on_deactivate(
10391037
)
10401038
self.assertEqual(channel.code, 200, channel.json_body)
10411039

1040+
# Check that the mock was not called on the act of adding a third-party ID.
1041+
on_remove_user_third_party_identifier_callback_mock.assert_not_called()
1042+
10421043
# Now deactivate the user.
10431044
channel = self.make_request(
10441045
"PUT",

0 commit comments

Comments
 (0)