Send content rules with pattern_type to clients (#14356)

This commit is contained in:
DeepBlueV7.X 2022-11-15 16:29:30 +01:00 committed by GitHub
parent b5ab2c428a
commit 63cc56affa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

1
changelog.d/14356.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a bug introduced in 1.66 which would not send certain pushrules to clients. Contributed by Nico.

View File

@ -44,6 +44,12 @@ def format_push_rules_for_user(
rulearray.append(template_rule)
pattern_type = template_rule.pop("pattern_type", None)
if pattern_type == "user_id":
template_rule["pattern"] = user.to_string()
elif pattern_type == "user_localpart":
template_rule["pattern"] = user.localpart
template_rule["enabled"] = enabled
if "conditions" not in template_rule:
@ -93,10 +99,14 @@ def _rule_to_template(rule: PushRule) -> Optional[Dict[str, Any]]:
if len(rule.conditions) != 1:
return None
thecond = rule.conditions[0]
if "pattern" not in thecond:
return None
templaterule = {"actions": rule.actions}
templaterule["pattern"] = thecond["pattern"]
if "pattern" in thecond:
templaterule["pattern"] = thecond["pattern"]
elif "pattern_type" in thecond:
templaterule["pattern_type"] = thecond["pattern_type"]
else:
return None
else:
# This should not be reached unless this function is not kept in sync
# with PRIORITY_CLASS_INVERSE_MAP.