From 52bdd1b8342e0bc20739d277c3c42bddbac77891 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 22 Jan 2016 14:58:19 +0000 Subject: Overlay the push_rules_enabled map for users, otherwise they won't be able to disable server default rules. --- synapse/push/bulk_push_rule_evaluator.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'synapse/push') diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index b91c165e2b..baa32a4e18 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -36,6 +36,7 @@ def decode_rule_json(rule): @defer.inlineCallbacks def _get_rules(room_id, user_ids, store): rules_by_user = yield store.bulk_get_push_rules(user_ids) + rules_enabled_by_user = yield store.bulk_get_push_rules_enabled(user_ids) rules_by_user = { uid: baserules.list_with_base_rules([ @@ -44,6 +45,19 @@ def _get_rules(room_id, user_ids, store): ]) for uid in user_ids } + + # We apply the rules-enabled map here: bulk_get_push_rules doesn't + # fetch disabled rules, but this won't account for any server default + # rules the user has disabled, so we need to do this too. + for uid in user_ids: + user_enabled_map = rules_enabled_by_user[uid] + + for rule in rules_by_user[uid]: + rule_id = rule['rule_id'] + + if rule_id in user_enabled_map: + rule['enabled'] = user_enabled_map[rule_id] + defer.returnValue(rules_by_user) -- cgit 1.4.1 From 7065b75bfd52a87771ad36537a374826dc45496a Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 22 Jan 2016 15:13:44 +0000 Subject: Don't crash if a user has no push rule enabled entries --- synapse/push/bulk_push_rule_evaluator.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'synapse/push') diff --git a/synapse/push/bulk_push_rule_evaluator.py b/synapse/push/bulk_push_rule_evaluator.py index baa32a4e18..06250d2d96 100644 --- a/synapse/push/bulk_push_rule_evaluator.py +++ b/synapse/push/bulk_push_rule_evaluator.py @@ -50,6 +50,9 @@ def _get_rules(room_id, user_ids, store): # fetch disabled rules, but this won't account for any server default # rules the user has disabled, so we need to do this too. for uid in user_ids: + if uid not in rules_enabled_by_user: + continue + user_enabled_map = rules_enabled_by_user[uid] for rule in rules_by_user[uid]: -- cgit 1.4.1