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

Move ThirdPartyEventRules into module_api/callbacks #15535

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@
GET_USERS_FOR_STATES_CALLBACK,
PresenceRouter,
)
from synapse.events.third_party_rules import (
CHECK_CAN_DEACTIVATE_USER_CALLBACK,
CHECK_CAN_SHUTDOWN_ROOM_CALLBACK,
CHECK_EVENT_ALLOWED_CALLBACK,
CHECK_THREEPID_CAN_BE_INVITED_CALLBACK,
CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK,
ON_ADD_USER_THIRD_PARTY_IDENTIFIER_CALLBACK,
ON_CREATE_ROOM_CALLBACK,
ON_NEW_EVENT_CALLBACK,
ON_PROFILE_UPDATE_CALLBACK,
ON_REMOVE_USER_THIRD_PARTY_IDENTIFIER_CALLBACK,
ON_THREEPID_BIND_CALLBACK,
ON_USER_DEACTIVATION_STATUS_CHANGED_CALLBACK,
)
from synapse.handlers.account_data import ON_ACCOUNT_DATA_UPDATED_CALLBACK
from synapse.handlers.auth import (
CHECK_3PID_AUTH_CALLBACK,
Expand Down Expand Up @@ -105,6 +91,20 @@
USER_MAY_SEND_3PID_INVITE_CALLBACK,
SpamCheckerModuleApiCallbacks,
)
from synapse.module_api.callbacks.third_party_event_rules_callbacks import (
CHECK_CAN_DEACTIVATE_USER_CALLBACK,
CHECK_CAN_SHUTDOWN_ROOM_CALLBACK,
CHECK_EVENT_ALLOWED_CALLBACK,
CHECK_THREEPID_CAN_BE_INVITED_CALLBACK,
CHECK_VISIBILITY_CAN_BE_MODIFIED_CALLBACK,
ON_ADD_USER_THIRD_PARTY_IDENTIFIER_CALLBACK,
ON_CREATE_ROOM_CALLBACK,
ON_NEW_EVENT_CALLBACK,
ON_PROFILE_UPDATE_CALLBACK,
ON_REMOVE_USER_THIRD_PARTY_IDENTIFIER_CALLBACK,
ON_THREEPID_BIND_CALLBACK,
ON_USER_DEACTIVATION_STATUS_CHANGED_CALLBACK,
)
from synapse.push.httppusher import HttpPusher
from synapse.rest.client.login import LoginResponse
from synapse.storage import DataStore
Expand Down Expand Up @@ -273,7 +273,6 @@ def __init__(self, hs: "HomeServer", auth_handler: AuthHandler) -> None:
self._public_room_list_manager = PublicRoomListManager(hs)
self._account_data_manager = AccountDataManager(hs)

self._third_party_event_rules = hs.get_third_party_event_rules()
self._password_auth_provider = hs.get_password_auth_provider()
self._presence_router = hs.get_presence_router()
self._account_data_handler = hs.get_account_data_handler()
Expand Down Expand Up @@ -371,7 +370,7 @@ def register_third_party_rules_callbacks(

Added in Synapse v1.39.0.
"""
return self._third_party_event_rules.register_third_party_rules_callbacks(
return self._callbacks.third_party_event_rules.register_third_party_rules_callbacks(
check_event_allowed=check_event_allowed,
on_create_room=on_create_room,
check_threepid_can_be_invited=check_threepid_can_be_invited,
Expand Down
3 changes: 3 additions & 0 deletions synapse/module_api/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
SpamCheckerModuleApiCallbacks,
)

from .third_party_event_rules_callbacks import ThirdPartyEventRulesModuleApiCallbacks
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved


class ModuleApiCallbacks:
def __init__(self, hs: "HomeServer") -> None:
self.account_validity = AccountValidityModuleApiCallbacks()
self.spam_checker = SpamCheckerModuleApiCallbacks(hs)
self.third_party_event_rules = ThirdPartyEventRulesModuleApiCallbacks(hs)
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def run(*args: Any, **kwargs: Any) -> Awaitable:
api.register_third_party_rules_callbacks(**hooks)


class ThirdPartyEventRules:
class ThirdPartyEventRulesModuleApiCallbacks:
"""Allows server admins to provide a Python module implementing an extra
set of rules to apply when processing events.

Expand All @@ -149,8 +149,6 @@ class ThirdPartyEventRules:
"""

def __init__(self, hs: "HomeServer"):
self.third_party_rules = None

self.store = hs.get_datastores().main
self._storage_controllers = hs.get_storage_controllers()

Expand Down
5 changes: 0 additions & 5 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from synapse.crypto.keyring import Keyring
from synapse.events.builder import EventBuilderFactory
from synapse.events.presence_router import PresenceRouter
from synapse.events.third_party_rules import ThirdPartyEventRules
from synapse.events.utils import EventClientSerializer
from synapse.federation.federation_client import FederationClient
from synapse.federation.federation_server import (
Expand Down Expand Up @@ -691,10 +690,6 @@ def get_user_directory_handler(self) -> UserDirectoryHandler:
def get_stats_handler(self) -> StatsHandler:
return StatsHandler(self)

@cache_in_self
def get_third_party_event_rules(self) -> ThirdPartyEventRules:
return ThirdPartyEventRules(self)

@cache_in_self
def get_password_auth_provider(self) -> PasswordAuthProvider:
return PasswordAuthProvider()
Expand Down