Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unfreeze notification_levels for PushRuleEvaluator #18103

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
3 changes: 3 additions & 0 deletions changelog.d/18103.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed a bug that disturbed room creation when a check_event_allowed callback was registered by a module and power_level Notifications mapping exists.

Contributed by @c-cal
8 changes: 7 additions & 1 deletion synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from synapse.synapse_rust.events import EventInternalMetadata
from synapse.types import JsonDict, StrCollection
from synapse.util.caches import intern_dict
from synapse.util.frozenutils import freeze
from synapse.util.frozenutils import freeze, unfreeze
from synapse.util.stringutils import strtobool

if TYPE_CHECKING:
Expand Down Expand Up @@ -319,6 +319,12 @@ def freeze(self) -> None:
# this will be a no-op if the event dict is already frozen.
self._dict = freeze(self._dict)

def unfreeze(self) -> None:
"""'Unfreeze' the event dict, so it can be modified afterwards"""

# this will be a no-op if the event dict is already unfrozen.
self._dict = unfreeze(self._dict)

def __str__(self) -> str:
return self.__repr__()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ async def check_event_allowed(
# the hashes and signatures.
event.freeze()

allow = True
event_dict = None

for callback in self._check_event_allowed_callbacks:
try:
res, replacement_data = await delay_cancellation(
Expand All @@ -318,11 +321,15 @@ async def check_event_allowed(
# Return if the event shouldn't be allowed or if the module came up with a
# replacement dict for the event.
if res is False:
return res, None
allow = False
break
elif isinstance(replacement_data, dict):
return True, replacement_data
event_dict = replacement_data
break

event.unfreeze()

return True, None
return allow, event_dict

async def on_create_room(
self, requester: Requester, config: dict, is_requester_admin: bool
Expand Down