Incorporate review

This commit is contained in:
Brendan Abolivier 2020-08-06 10:52:26 +01:00
parent e2f1cccc8a
commit dd11f575a2
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD
4 changed files with 12 additions and 21 deletions

View File

@ -540,6 +540,9 @@ class ServerConfig(Config):
if not isinstance(self.users_new_default_push_rules, 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:
return any(listener.tls for listener in self.listeners)

View File

@ -24,6 +24,8 @@ def list_with_base_rules(rawrules, use_new_defaults=False):
Args:
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:
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 = []
if kind == "override":
rules = (
NEW_PREPEND_OVERRIDE_RULES
if use_new_defaults
else BASE_PREPEND_OVERRIDE_RULES
)
rules = BASE_PREPEND_OVERRIDE_RULES
# Copy the rules before modifying them
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 = [
{
"rule_id": "global/override/.m.rule.suppress_notices",
@ -573,7 +561,7 @@ for r in BASE_APPEND_CONTENT_RULES:
r["default"] = True
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["default"] = True
NEW_RULE_IDS.add(r["rule_id"])

View File

@ -45,7 +45,7 @@ class PushRuleRestServlet(RestServlet):
self.notifier = hs.get_notifier()
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):
if self._is_worker:
@ -181,7 +181,7 @@ class PushRuleRestServlet(RestServlet):
rule_id = spec["rule_id"]
is_default_rule = rule_id.startswith(".")
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
else:
rule_ids = BASE_RULE_IDS

View File

@ -105,7 +105,7 @@ class PushRulesWorkerStore(
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
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)
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)
@ -198,7 +198,7 @@ class PushRulesWorkerStore(
enabled_map_by_user = yield self.bulk_get_push_rules_enabled(user_ids)
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(
rules, enabled_map_by_user.get(user_id, {}), use_new_defaults,