mirror of
https://github.com/element-hq/synapse.git
synced 2026-12-03 15:54:45 +00:00
TLDR: `PUT` on a server-default push rule now applies the same existence check that `GET` already does. A rule that is not served cannot be modified. Synapse ships some server-default push rules behind experimental feature flags, so the set of server-default rules a user has depends on the server's configuration. Most flags add rules that only exist while the flag is on. [MSC4210](https://github.com/matrix-org/matrix-spec-proposals/pull/4210) works the other way: it removes the three legacy mention rules while its flag is on. The flags that change the set are: - `msc1767_enabled`: [MSC1767](https://github.com/matrix-org/matrix-spec-proposals/pull/1767) extensible events rules - `msc3381_polls_enabled`: [MSC3381](https://github.com/matrix-org/matrix-spec-proposals/pull/3381) poll rules - `msc3664_enabled`: [MSC3664](https://github.com/matrix-org/matrix-spec-proposals/pull/3664) reply rule - `msc4028_push_encrypted_events`: [MSC4028](https://github.com/matrix-org/matrix-spec-proposals/pull/4028) encrypted event rule - `msc4306_enabled`: [MSC4306](https://github.com/matrix-org/matrix-spec-proposals/pull/4306) thread subscription rules - `msc4210_enabled`: removes `.m.rule.contains_display_name`, `.m.rule.contains_user_name` and `.m.rule.roomnotif` `GET /pushrules/` only lists the rules that exist for that configuration. `GET` on a single rule that is not in the set returns `404 M_NOT_FOUND`. The same set is used to evaluate notifications, and to build the `m.push_rules` account data in `/sync`. `PUT .../enabled` and `PUT .../actions` did not use that set. They accepted any rule ID that Synapse knows about, whether or not the server currently serves it. Clients could modify a rule the server had just said did not exist. The request returned `200`, the change was stored, and it was then ignored. Both endpoints now return `404 M_NOT_FOUND` for such a rule, as [the spec requires](https://spec.matrix.org/v1.19/client-server-api/#put_matrixclientv3pushrulesglobalkindruleidenabled) for a rule that does not exist. Before (`msc4210_enabled: true`): ``` GET /_matrix/client/v3/pushrules/global/override/.m.rule.roomnotif 404 {"errcode": "M_NOT_FOUND", "error": "..."} PUT /_matrix/client/v3/pushrules/global/override/.m.rule.roomnotif/enabled {"enabled": false} 200 {} ``` After: ``` GET /_matrix/client/v3/pushrules/global/override/.m.rule.roomnotif 404 {"errcode": "M_NOT_FOUND", "error": "..."} PUT /_matrix/client/v3/pushrules/global/override/.m.rule.roomnotif/enabled {"enabled": false} 404 {"errcode": "M_NOT_FOUND", "error": "Unknown rule"} ``` This is a no-op for default configurations. All of these flags are off by default, and rules that are served are still modifiable as before.
86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
# Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
# Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from typing import Any, Collection, Mapping, Sequence
|
|
|
|
from synapse.types import JsonDict, JsonValue
|
|
|
|
class PushRule:
|
|
@property
|
|
def rule_id(self) -> str: ...
|
|
@property
|
|
def priority_class(self) -> int: ...
|
|
@property
|
|
def conditions(self) -> Sequence[Mapping[str, str]]: ...
|
|
@property
|
|
def actions(self) -> Sequence[Mapping[str, Any] | str]: ...
|
|
@property
|
|
def default(self) -> bool: ...
|
|
@property
|
|
def default_enabled(self) -> bool: ...
|
|
@staticmethod
|
|
def from_db(
|
|
rule_id: str, priority_class: int, conditions: str, actions: str
|
|
) -> "PushRule": ...
|
|
|
|
class PushRules:
|
|
def __init__(self, rules: Collection[PushRule]): ...
|
|
def rules(self) -> Collection[PushRule]: ...
|
|
|
|
class FilteredPushRules:
|
|
def __init__(
|
|
self,
|
|
push_rules: PushRules,
|
|
enabled_map: dict[str, bool],
|
|
msc1767_enabled: bool,
|
|
msc3381_polls_enabled: bool,
|
|
msc3664_enabled: bool,
|
|
msc4028_push_encrypted_events: bool,
|
|
msc4075_enabled: bool,
|
|
msc4210_enabled: bool,
|
|
msc4306_enabled: bool,
|
|
): ...
|
|
def rules(self) -> Collection[tuple[PushRule, bool]]: ...
|
|
|
|
class PushRuleEvaluator:
|
|
def __init__(
|
|
self,
|
|
flattened_keys: Mapping[str, JsonValue],
|
|
has_mentions: bool,
|
|
room_member_count: int,
|
|
sender_power_level: int | None,
|
|
notification_power_levels: Mapping[str, int],
|
|
related_events_flattened: Mapping[str, Mapping[str, JsonValue]],
|
|
related_event_match_enabled: bool,
|
|
room_version_feature_flags: list[str],
|
|
msc3931_enabled: bool,
|
|
msc4210_enabled: bool,
|
|
msc4306_enabled: bool,
|
|
): ...
|
|
def run(
|
|
self,
|
|
push_rules: FilteredPushRules,
|
|
user_id: str | None,
|
|
display_name: str | None,
|
|
msc4306_thread_subscription_state: bool | None,
|
|
) -> Collection[Mapping | str]: ...
|
|
def matches(
|
|
self,
|
|
condition: JsonDict,
|
|
user_id: str | None,
|
|
display_name: str | None,
|
|
msc4306_thread_subscription_state: bool | None = None,
|
|
) -> bool: ...
|