diff options
author | Mark Haines <mjark@negativecurvature.net> | 2016-01-27 17:13:36 +0100 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2016-01-27 17:13:36 +0100 |
commit | d6c831bd3d07a08e9d002fa047343f189f85637f (patch) | |
tree | 32389de09e2b1cbe25221502d983b23c5a10c6f0 | |
parent | Merge pull request #529 from matrix-org/dbkr/one_to_one_only_messages (diff) | |
parent | Fix adding push rules relative to other rules (diff) | |
download | synapse-d6c831bd3d07a08e9d002fa047343f189f85637f.tar.xz |
Merge pull request #531 from matrix-org/markjh/relative_push_rules
Fix adding push rules relative to other rules
-rw-r--r-- | synapse/rest/client/v1/push_rule.py | 15 | ||||
-rw-r--r-- | synapse/storage/push_rule.py | 3 |
2 files changed, 12 insertions, 6 deletions
diff --git a/synapse/rest/client/v1/push_rule.py b/synapse/rest/client/v1/push_rule.py index cb3ec23872..96633a176c 100644 --- a/synapse/rest/client/v1/push_rule.py +++ b/synapse/rest/client/v1/push_rule.py @@ -66,11 +66,12 @@ class PushRuleRestServlet(ClientV1RestServlet): raise SynapseError(400, e.message) before = request.args.get("before", None) - if before and len(before): - before = before[0] + if before: + before = _namespaced_rule_id(spec, before[0]) + after = request.args.get("after", None) - if after and len(after): - after = after[0] + if after: + after = _namespaced_rule_id(spec, after[0]) try: yield self.hs.get_datastore().add_push_rule( @@ -452,11 +453,15 @@ def _strip_device_condition(rule): def _namespaced_rule_id_from_spec(spec): + return _namespaced_rule_id(spec, spec['rule_id']) + + +def _namespaced_rule_id(spec, rule_id): if spec['scope'] == 'global': scope = 'global' else: scope = 'device/%s' % (spec['profile_tag']) - return "%s/%s/%s" % (scope, spec['template'], spec['rule_id']) + return "%s/%s/%s" % (scope, spec['template'], rule_id) def _rule_id_from_namespaced(in_rule_id): diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index 1f51c90ee5..f9a48171ba 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -130,7 +130,8 @@ class PushRuleStore(SQLBaseStore): def _add_push_rule_relative_txn(self, txn, user_id, **kwargs): after = kwargs.pop("after", None) - relative_to_rule = kwargs.pop("before", after) + before = kwargs.pop("before", None) + relative_to_rule = before or after res = self._simple_select_one_txn( txn, |