|
|
|
@ -27,11 +27,14 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
@cachedInlineCallbacks() |
|
|
|
|
def get_push_rules_for_user(self, user_name): |
|
|
|
|
rows = yield self._simple_select_list( |
|
|
|
|
table=PushRuleTable.table_name, |
|
|
|
|
table="push_rules", |
|
|
|
|
keyvalues={ |
|
|
|
|
"user_name": user_name, |
|
|
|
|
}, |
|
|
|
|
retcols=PushRuleTable.fields, |
|
|
|
|
retcols=( |
|
|
|
|
"user_name", "rule_id", "priority_class", "priority", |
|
|
|
|
"conditions", "actions", |
|
|
|
|
), |
|
|
|
|
desc="get_push_rules_enabled_for_user", |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -44,11 +47,13 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
@cachedInlineCallbacks() |
|
|
|
|
def get_push_rules_enabled_for_user(self, user_name): |
|
|
|
|
results = yield self._simple_select_list( |
|
|
|
|
table=PushRuleEnableTable.table_name, |
|
|
|
|
table="push_rules_enable", |
|
|
|
|
keyvalues={ |
|
|
|
|
'user_name': user_name |
|
|
|
|
}, |
|
|
|
|
retcols=PushRuleEnableTable.fields, |
|
|
|
|
retcols=( |
|
|
|
|
"user_name", "rule_id", "enabled", |
|
|
|
|
), |
|
|
|
|
desc="get_push_rules_enabled_for_user", |
|
|
|
|
) |
|
|
|
|
defer.returnValue({ |
|
|
|
@ -65,12 +70,12 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
def f(txn, user_ids_to_fetch): |
|
|
|
|
sql = ( |
|
|
|
|
"SELECT pr.*" |
|
|
|
|
" FROM push_rules as pr " |
|
|
|
|
" LEFT JOIN push_rules_enable as pre " |
|
|
|
|
" ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id " |
|
|
|
|
" WHERE pr.user_name " |
|
|
|
|
" FROM push_rules AS pr" |
|
|
|
|
" LEFT JOIN push_rules_enable AS pre" |
|
|
|
|
" ON pr.user_name = pre.user_name AND pr.rule_id = pre.rule_id" |
|
|
|
|
" WHERE pr.user_name" |
|
|
|
|
" IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")" |
|
|
|
|
" AND (pre.enabled is null or pre.enabled = 1)" |
|
|
|
|
" AND (pre.enabled IS NULL OR pre.enabled = 1)" |
|
|
|
|
" ORDER BY pr.user_name, pr.priority_class DESC, pr.priority DESC" |
|
|
|
|
) |
|
|
|
|
txn.execute(sql, user_ids_to_fetch) |
|
|
|
@ -123,7 +128,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
|
|
|
|
|
res = self._simple_select_one_txn( |
|
|
|
|
txn, |
|
|
|
|
table=PushRuleTable.table_name, |
|
|
|
|
table="push_rules", |
|
|
|
|
keyvalues={ |
|
|
|
|
"user_name": user_name, |
|
|
|
|
"rule_id": relative_to_rule, |
|
|
|
@ -162,7 +167,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
new_rule['priority'] = new_rule_priority |
|
|
|
|
|
|
|
|
|
sql = ( |
|
|
|
|
"SELECT COUNT(*) FROM " + PushRuleTable.table_name + |
|
|
|
|
"SELECT COUNT(*) FROM push_rules" |
|
|
|
|
" WHERE user_name = ? AND priority_class = ? AND priority = ?" |
|
|
|
|
) |
|
|
|
|
txn.execute(sql, (user_name, priority_class, new_rule_priority)) |
|
|
|
@ -171,7 +176,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
|
|
|
|
|
# if there are conflicting rules, bump everything |
|
|
|
|
if num_conflicting: |
|
|
|
|
sql = "UPDATE "+PushRuleTable.table_name+" SET priority = priority " |
|
|
|
|
sql = "UPDATE push_rules SET priority = priority " |
|
|
|
|
if after: |
|
|
|
|
sql += "-1" |
|
|
|
|
else: |
|
|
|
@ -194,7 +199,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
|
|
|
|
|
self._simple_insert_txn( |
|
|
|
|
txn, |
|
|
|
|
table=PushRuleTable.table_name, |
|
|
|
|
table="push_rules", |
|
|
|
|
values=new_rule, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -202,7 +207,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
priority_class, **kwargs): |
|
|
|
|
# find the highest priority rule in that class |
|
|
|
|
sql = ( |
|
|
|
|
"SELECT COUNT(*), MAX(priority) FROM " + PushRuleTable.table_name + |
|
|
|
|
"SELECT COUNT(*), MAX(priority) FROM push_rules" |
|
|
|
|
" WHERE user_name = ? and priority_class = ?" |
|
|
|
|
) |
|
|
|
|
txn.execute(sql, (user_name, priority_class)) |
|
|
|
@ -229,7 +234,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
|
|
|
|
|
self._simple_insert_txn( |
|
|
|
|
txn, |
|
|
|
|
table=PushRuleTable.table_name, |
|
|
|
|
table="push_rules", |
|
|
|
|
values=new_rule, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -245,7 +250,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
rule_id (str): The rule_id of the rule to be deleted |
|
|
|
|
""" |
|
|
|
|
yield self._simple_delete_one( |
|
|
|
|
PushRuleTable.table_name, |
|
|
|
|
"push_rules", |
|
|
|
|
{'user_name': user_name, 'rule_id': rule_id}, |
|
|
|
|
desc="delete_push_rule", |
|
|
|
|
) |
|
|
|
@ -266,7 +271,7 @@ class PushRuleStore(SQLBaseStore): |
|
|
|
|
new_id = self._push_rules_enable_id_gen.get_next_txn(txn) |
|
|
|
|
self._simple_upsert_txn( |
|
|
|
|
txn, |
|
|
|
|
PushRuleEnableTable.table_name, |
|
|
|
|
"push_rules_enable", |
|
|
|
|
{'user_name': user_name, 'rule_id': rule_id}, |
|
|
|
|
{'enabled': 1 if enabled else 0}, |
|
|
|
|
{'id': new_id}, |
|
|
|
@ -285,27 +290,3 @@ class RuleNotFoundException(Exception): |
|
|
|
|
|
|
|
|
|
class InconsistentRuleException(Exception): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PushRuleTable(object): |
|
|
|
|
table_name = "push_rules" |
|
|
|
|
|
|
|
|
|
fields = [ |
|
|
|
|
"id", |
|
|
|
|
"user_name", |
|
|
|
|
"rule_id", |
|
|
|
|
"priority_class", |
|
|
|
|
"priority", |
|
|
|
|
"conditions", |
|
|
|
|
"actions", |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PushRuleEnableTable(object): |
|
|
|
|
table_name = "push_rules_enable" |
|
|
|
|
|
|
|
|
|
fields = [ |
|
|
|
|
"user_name", |
|
|
|
|
"rule_id", |
|
|
|
|
"enabled" |
|
|
|
|
] |
|
|
|
|