mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-16 10:03:52 +01:00
Fix adding rules without before/after & add the rule that we couldn't find to the error
This commit is contained in:
parent
6927b6b197
commit
bcd48b9636
2 changed files with 7 additions and 5 deletions
|
@ -166,8 +166,8 @@ class PushRuleRestServlet(RestServlet):
|
||||||
)
|
)
|
||||||
except InconsistentRuleException as e:
|
except InconsistentRuleException as e:
|
||||||
raise SynapseError(400, e.message)
|
raise SynapseError(400, e.message)
|
||||||
except RuleNotFoundException:
|
except RuleNotFoundException as e:
|
||||||
raise SynapseError(400, "before/after rule not found")
|
raise SynapseError(400, e.message)
|
||||||
|
|
||||||
defer.returnValue((200, {}))
|
defer.returnValue((200, {}))
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class PushRuleStore(SQLBaseStore):
|
||||||
defer.returnValue(dicts)
|
defer.returnValue(dicts)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def add_push_rule(self, **kwargs):
|
def add_push_rule(self, before, after, **kwargs):
|
||||||
vals = copy.copy(kwargs)
|
vals = copy.copy(kwargs)
|
||||||
if 'conditions' in vals:
|
if 'conditions' in vals:
|
||||||
vals['conditions'] = json.dumps(vals['conditions'])
|
vals['conditions'] = json.dumps(vals['conditions'])
|
||||||
|
@ -57,10 +57,12 @@ class PushRuleStore(SQLBaseStore):
|
||||||
if 'id' in vals:
|
if 'id' in vals:
|
||||||
del vals['id']
|
del vals['id']
|
||||||
|
|
||||||
if 'after' in kwargs or 'before' in kwargs:
|
if before or after:
|
||||||
ret = yield self.runInteraction(
|
ret = yield self.runInteraction(
|
||||||
"_add_push_rule_relative_txn",
|
"_add_push_rule_relative_txn",
|
||||||
self._add_push_rule_relative_txn,
|
self._add_push_rule_relative_txn,
|
||||||
|
before=before,
|
||||||
|
after=after,
|
||||||
**vals
|
**vals
|
||||||
)
|
)
|
||||||
defer.returnValue(ret)
|
defer.returnValue(ret)
|
||||||
|
@ -89,7 +91,7 @@ class PushRuleStore(SQLBaseStore):
|
||||||
txn.execute(sql, (user_name, relative_to_rule))
|
txn.execute(sql, (user_name, relative_to_rule))
|
||||||
res = txn.fetchall()
|
res = txn.fetchall()
|
||||||
if not res:
|
if not res:
|
||||||
raise RuleNotFoundException()
|
raise RuleNotFoundException("before/after rule not found: %s" % (relative_to_rule))
|
||||||
(priority_class, base_rule_priority) = res[0]
|
(priority_class, base_rule_priority) = res[0]
|
||||||
|
|
||||||
if 'priority_class' in kwargs and kwargs['priority_class'] != priority_class:
|
if 'priority_class' in kwargs and kwargs['priority_class'] != priority_class:
|
||||||
|
|
Loading…
Reference in a new issue