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

Commit

Permalink
Fix missing conditional for registering `on_remove_user_third_party_i…
Browse files Browse the repository at this point in the history
…dentifier` module api callbacks (#15227
  • Loading branch information
anoadragon453 committed Mar 10, 2023
1 parent 9418344 commit e157c63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/15227.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +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.
5 changes: 5 additions & 0 deletions synapse/events/third_party_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ def register_third_party_rules_callbacks(
on_add_user_third_party_identifier
)

if on_remove_user_third_party_identifier is not None:
self._on_remove_user_third_party_identifier_callbacks.append(
on_remove_user_third_party_identifier
)

async def check_event_allowed(
self,
event: EventBase,
Expand Down
19 changes: 10 additions & 9 deletions tests/rest/client/test_third_party_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,18 +941,16 @@ def test_on_add_and_remove_user_third_party_identifier(self) -> None:
just before associating and removing a 3PID to/from an account.
"""
# Pretend to be a Synapse module and register both callbacks as mocks.
third_party_rules = self.hs.get_third_party_event_rules()
on_add_user_third_party_identifier_callback_mock = Mock(
return_value=make_awaitable(None)
)
on_remove_user_third_party_identifier_callback_mock = Mock(
return_value=make_awaitable(None)
)
third_party_rules._on_threepid_bind_callbacks.append(
on_add_user_third_party_identifier_callback_mock
)
third_party_rules._on_threepid_bind_callbacks.append(
on_remove_user_third_party_identifier_callback_mock
third_party_rules = self.hs.get_third_party_event_rules()
third_party_rules.register_third_party_rules_callbacks(
on_add_user_third_party_identifier=on_add_user_third_party_identifier_callback_mock,
on_remove_user_third_party_identifier=on_remove_user_third_party_identifier_callback_mock,
)

# Register an admin user.
Expand Down Expand Up @@ -1008,12 +1006,12 @@ def test_on_remove_user_third_party_identifier_is_called_on_deactivate(
when a user is deactivated and their third-party ID associations are deleted.
"""
# Pretend to be a Synapse module and register both callbacks as mocks.
third_party_rules = self.hs.get_third_party_event_rules()
on_remove_user_third_party_identifier_callback_mock = Mock(
return_value=make_awaitable(None)
)
third_party_rules._on_threepid_bind_callbacks.append(
on_remove_user_third_party_identifier_callback_mock
third_party_rules = self.hs.get_third_party_event_rules()
third_party_rules.register_third_party_rules_callbacks(
on_remove_user_third_party_identifier=on_remove_user_third_party_identifier_callback_mock,
)

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

# Check that the mock was not called on the act of adding a third-party ID.
on_remove_user_third_party_identifier_callback_mock.assert_not_called()

# Now deactivate the user.
channel = self.make_request(
"PUT",
Expand Down

0 comments on commit e157c63

Please sign in to comment.