mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Add the master push rule for the break-my-push button. Allow server default rules to be disabled by default.
This commit is contained in:
parent
8916acbc13
commit
04f8478aaa
@ -105,7 +105,11 @@ class Pusher(object):
|
||||
room_member_count += 1
|
||||
|
||||
for r in rules:
|
||||
if r['rule_id'] in enabled_map and not enabled_map[r['rule_id']]:
|
||||
if r['rule_id'] in enabled_map:
|
||||
r['enabled'] = enabled_map[r['rule_id']]
|
||||
elif 'enabled' not in r:
|
||||
r['enabled'] = True
|
||||
if not r['enabled']:
|
||||
continue
|
||||
matches = True
|
||||
|
||||
|
@ -6,36 +6,63 @@ def list_with_base_rules(rawrules, user_name):
|
||||
|
||||
# shove the server default rules for each kind onto the end of each
|
||||
current_prio_class = PRIORITY_CLASS_INVERSE_MAP.keys()[-1]
|
||||
|
||||
ruleslist.extend(make_base_prepend_rules(
|
||||
user_name, PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
|
||||
for r in rawrules:
|
||||
if r['priority_class'] < current_prio_class:
|
||||
while r['priority_class'] < current_prio_class:
|
||||
ruleslist.extend(make_base_rules(
|
||||
ruleslist.extend(make_base_append_rules(
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
current_prio_class -= 1
|
||||
if current_prio_class > 0:
|
||||
ruleslist.extend(make_base_prepend_rules(
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
|
||||
ruleslist.append(r)
|
||||
|
||||
while current_prio_class > 0:
|
||||
ruleslist.extend(make_base_rules(
|
||||
ruleslist.extend(make_base_append_rules(
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
current_prio_class -= 1
|
||||
if current_prio_class > 0:
|
||||
ruleslist.extend(make_base_prepend_rules(
|
||||
user_name,
|
||||
PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
|
||||
))
|
||||
|
||||
return ruleslist
|
||||
|
||||
|
||||
def make_base_rules(user, kind):
|
||||
def make_base_append_rules(user, kind):
|
||||
rules = []
|
||||
|
||||
if kind == 'override':
|
||||
rules = make_base_override_rules()
|
||||
rules = make_base_append_override_rules()
|
||||
elif kind == 'underride':
|
||||
rules = make_base_underride_rules(user)
|
||||
rules = make_base_append_underride_rules(user)
|
||||
elif kind == 'content':
|
||||
rules = make_base_content_rules(user)
|
||||
rules = make_base_append_content_rules(user)
|
||||
|
||||
for r in rules:
|
||||
r['priority_class'] = PRIORITY_CLASS_MAP[kind]
|
||||
r['default'] = True # Deprecated, left for backwards compat
|
||||
|
||||
return rules
|
||||
|
||||
def make_base_prepend_rules(user, kind):
|
||||
rules = []
|
||||
|
||||
if kind == 'override':
|
||||
rules = make_base_prepend_override_rules()
|
||||
|
||||
for r in rules:
|
||||
r['priority_class'] = PRIORITY_CLASS_MAP[kind]
|
||||
@ -44,7 +71,7 @@ def make_base_rules(user, kind):
|
||||
return rules
|
||||
|
||||
|
||||
def make_base_content_rules(user):
|
||||
def make_base_append_content_rules(user):
|
||||
return [
|
||||
{
|
||||
'rule_id': 'global/content/.m.rule.contains_user_name',
|
||||
@ -68,7 +95,20 @@ def make_base_content_rules(user):
|
||||
]
|
||||
|
||||
|
||||
def make_base_override_rules():
|
||||
def make_base_prepend_override_rules():
|
||||
return [
|
||||
{
|
||||
'rule_id': 'global/override/.m.rule.master',
|
||||
'enabled': False,
|
||||
'conditions': [],
|
||||
'actions': [
|
||||
"dont_notify"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def make_base_append_override_rules():
|
||||
return [
|
||||
{
|
||||
'rule_id': 'global/override/.m.rule.call',
|
||||
@ -142,7 +182,7 @@ def make_base_override_rules():
|
||||
]
|
||||
|
||||
|
||||
def make_base_underride_rules(user):
|
||||
def make_base_append_underride_rules(user):
|
||||
return [
|
||||
{
|
||||
'rule_id': 'global/underride/.m.rule.invite_for_me',
|
||||
|
@ -156,9 +156,12 @@ class PushRuleRestServlet(ClientV1RestServlet):
|
||||
|
||||
template_rule = _rule_to_template(r)
|
||||
if template_rule:
|
||||
template_rule['enabled'] = True
|
||||
if r['rule_id'] in enabled_map:
|
||||
template_rule['enabled'] = enabled_map[r['rule_id']]
|
||||
elif 'enabled' in r:
|
||||
template_rule['enabled'] = r['enabled']
|
||||
else:
|
||||
template_rule['enabled'] = True
|
||||
rulearray.append(template_rule)
|
||||
|
||||
path = request.postpath[1:]
|
||||
|
@ -56,17 +56,6 @@ class PushRuleStore(SQLBaseStore):
|
||||
{r['rule_id']: False if r['enabled'] == 0 else True for r in results}
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_push_rule_enabled_by_user_rule_id(self, user_name, rule_id):
|
||||
results = yield self._simple_select_list(
|
||||
PushRuleEnableTable.table_name,
|
||||
{'user_name': user_name, 'rule_id': rule_id},
|
||||
['enabled']
|
||||
)
|
||||
if not results:
|
||||
defer.returnValue(True)
|
||||
defer.returnValue(results[0])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def add_push_rule(self, before, after, **kwargs):
|
||||
vals = copy.copy(kwargs)
|
||||
@ -217,17 +206,11 @@ class PushRuleStore(SQLBaseStore):
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def set_push_rule_enabled(self, user_name, rule_id, enabled):
|
||||
if enabled:
|
||||
yield self._simple_delete_one(
|
||||
PushRuleEnableTable.table_name,
|
||||
{'user_name': user_name, 'rule_id': rule_id}
|
||||
)
|
||||
else:
|
||||
yield self._simple_upsert(
|
||||
PushRuleEnableTable.table_name,
|
||||
{'user_name': user_name, 'rule_id': rule_id},
|
||||
{'enabled': False}
|
||||
)
|
||||
yield self._simple_upsert(
|
||||
PushRuleEnableTable.table_name,
|
||||
{'user_name': user_name, 'rule_id': rule_id},
|
||||
{'enabled': enabled}
|
||||
)
|
||||
|
||||
|
||||
class RuleNotFoundException(Exception):
|
||||
|
Loading…
Reference in New Issue
Block a user