mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Incorporate review
This commit is contained in:
parent
e2f1cccc8a
commit
dd11f575a2
@ -540,6 +540,9 @@ class ServerConfig(Config):
|
|||||||
if not isinstance(self.users_new_default_push_rules, list):
|
if not isinstance(self.users_new_default_push_rules, list):
|
||||||
raise ConfigError("'users_new_default_push_rules' must be a list")
|
raise ConfigError("'users_new_default_push_rules' must be a list")
|
||||||
|
|
||||||
|
# Turn the list into a set to improve lookup speed.
|
||||||
|
self.users_new_default_push_rules = set(self.users_new_default_push_rules)
|
||||||
|
|
||||||
def has_tls_listener(self) -> bool:
|
def has_tls_listener(self) -> bool:
|
||||||
return any(listener.tls for listener in self.listeners)
|
return any(listener.tls for listener in self.listeners)
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ def list_with_base_rules(rawrules, use_new_defaults=False):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
rawrules(list): The rules the user has modified or set.
|
rawrules(list): The rules the user has modified or set.
|
||||||
|
use_new_defaults(bool): Whether to use the new experimental default rules when
|
||||||
|
appending or prepending default rules.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A new list with the rules set by the user combined with the defaults.
|
A new list with the rules set by the user combined with the defaults.
|
||||||
@ -125,11 +127,7 @@ def make_base_prepend_rules(kind, modified_base_rules, use_new_defaults=False):
|
|||||||
rules = []
|
rules = []
|
||||||
|
|
||||||
if kind == "override":
|
if kind == "override":
|
||||||
rules = (
|
rules = BASE_PREPEND_OVERRIDE_RULES
|
||||||
NEW_PREPEND_OVERRIDE_RULES
|
|
||||||
if use_new_defaults
|
|
||||||
else BASE_PREPEND_OVERRIDE_RULES
|
|
||||||
)
|
|
||||||
|
|
||||||
# Copy the rules before modifying them
|
# Copy the rules before modifying them
|
||||||
rules = copy.deepcopy(rules)
|
rules = copy.deepcopy(rules)
|
||||||
@ -171,16 +169,6 @@ BASE_PREPEND_OVERRIDE_RULES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
NEW_PREPEND_OVERRIDE_RULES = [
|
|
||||||
{
|
|
||||||
"rule_id": "global/override/.m.rule.master",
|
|
||||||
"enabled": False,
|
|
||||||
"conditions": [],
|
|
||||||
"actions": [],
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
BASE_APPEND_OVERRIDE_RULES = [
|
BASE_APPEND_OVERRIDE_RULES = [
|
||||||
{
|
{
|
||||||
"rule_id": "global/override/.m.rule.suppress_notices",
|
"rule_id": "global/override/.m.rule.suppress_notices",
|
||||||
@ -573,7 +561,7 @@ for r in BASE_APPEND_CONTENT_RULES:
|
|||||||
r["default"] = True
|
r["default"] = True
|
||||||
NEW_RULE_IDS.add(r["rule_id"])
|
NEW_RULE_IDS.add(r["rule_id"])
|
||||||
|
|
||||||
for r in NEW_PREPEND_OVERRIDE_RULES:
|
for r in BASE_PREPEND_OVERRIDE_RULES:
|
||||||
r["priority_class"] = PRIORITY_CLASS_MAP["override"]
|
r["priority_class"] = PRIORITY_CLASS_MAP["override"]
|
||||||
r["default"] = True
|
r["default"] = True
|
||||||
NEW_RULE_IDS.add(r["rule_id"])
|
NEW_RULE_IDS.add(r["rule_id"])
|
||||||
|
@ -45,7 +45,7 @@ class PushRuleRestServlet(RestServlet):
|
|||||||
self.notifier = hs.get_notifier()
|
self.notifier = hs.get_notifier()
|
||||||
self._is_worker = hs.config.worker_app is not None
|
self._is_worker = hs.config.worker_app is not None
|
||||||
|
|
||||||
self.users_new_default_push_rules = hs.config.users_new_default_push_rules
|
self._users_new_default_push_rules = hs.config.users_new_default_push_rules
|
||||||
|
|
||||||
async def on_PUT(self, request, path):
|
async def on_PUT(self, request, path):
|
||||||
if self._is_worker:
|
if self._is_worker:
|
||||||
@ -181,7 +181,7 @@ class PushRuleRestServlet(RestServlet):
|
|||||||
rule_id = spec["rule_id"]
|
rule_id = spec["rule_id"]
|
||||||
is_default_rule = rule_id.startswith(".")
|
is_default_rule = rule_id.startswith(".")
|
||||||
if is_default_rule:
|
if is_default_rule:
|
||||||
if user_id in self.users_new_default_push_rules:
|
if user_id in self._users_new_default_push_rules:
|
||||||
rule_ids = NEW_RULE_IDS
|
rule_ids = NEW_RULE_IDS
|
||||||
else:
|
else:
|
||||||
rule_ids = BASE_RULE_IDS
|
rule_ids = BASE_RULE_IDS
|
||||||
|
@ -105,7 +105,7 @@ class PushRulesWorkerStore(
|
|||||||
prefilled_cache=push_rules_prefill,
|
prefilled_cache=push_rules_prefill,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.users_new_default_push_rules = hs.config.users_new_default_push_rules
|
self._users_new_default_push_rules = hs.config.users_new_default_push_rules
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_max_push_rules_stream_id(self):
|
def get_max_push_rules_stream_id(self):
|
||||||
@ -136,7 +136,7 @@ class PushRulesWorkerStore(
|
|||||||
|
|
||||||
enabled_map = yield self.get_push_rules_enabled_for_user(user_id)
|
enabled_map = yield self.get_push_rules_enabled_for_user(user_id)
|
||||||
|
|
||||||
use_new_defaults = user_id in self.users_new_default_push_rules
|
use_new_defaults = user_id in self._users_new_default_push_rules
|
||||||
|
|
||||||
rules = _load_rules(rows, enabled_map, use_new_defaults)
|
rules = _load_rules(rows, enabled_map, use_new_defaults)
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ class PushRulesWorkerStore(
|
|||||||
enabled_map_by_user = yield self.bulk_get_push_rules_enabled(user_ids)
|
enabled_map_by_user = yield self.bulk_get_push_rules_enabled(user_ids)
|
||||||
|
|
||||||
for user_id, rules in results.items():
|
for user_id, rules in results.items():
|
||||||
use_new_defaults = user_id in self.users_new_default_push_rules
|
use_new_defaults = user_id in self._users_new_default_push_rules
|
||||||
|
|
||||||
results[user_id] = _load_rules(
|
results[user_id] = _load_rules(
|
||||||
rules, enabled_map_by_user.get(user_id, {}), use_new_defaults,
|
rules, enabled_map_by_user.get(user_id, {}), use_new_defaults,
|
||||||
|
Loading…
Reference in New Issue
Block a user