add notification path and use for service keys
This commit is contained in:
parent
97ae800e6c
commit
42b5196b21
4 changed files with 39 additions and 18 deletions
|
@ -6,10 +6,11 @@ from data.database import (Notification, NotificationKind, User, Team, TeamMembe
|
|||
ExternalNotificationMethod, Namespace)
|
||||
|
||||
|
||||
def create_notification(kind_name, target, metadata={}):
|
||||
def create_notification(kind_name, target, metadata={}, lookup_path=None):
|
||||
kind_ref = NotificationKind.get(name=kind_name)
|
||||
notification = Notification.create(kind=kind_ref, target=target,
|
||||
metadata_json=json.dumps(metadata))
|
||||
metadata_json=json.dumps(metadata),
|
||||
lookup_path=lookup_path)
|
||||
return notification
|
||||
|
||||
|
||||
|
@ -27,6 +28,12 @@ def lookup_notification(user, uuid):
|
|||
return results[0]
|
||||
|
||||
|
||||
def lookup_notifications_by_path_prefix(prefix):
|
||||
return list((Notification
|
||||
.select()
|
||||
.where(Notification.lookup_path % prefix)))
|
||||
|
||||
|
||||
def list_notifications(user, kind_name=None, id_filter=None, include_dismissed=False,
|
||||
page=None, limit=None):
|
||||
|
||||
|
@ -69,6 +76,13 @@ def list_notifications(user, kind_name=None, id_filter=None, include_dismissed=F
|
|||
return query.order_by(base_query.c.created.desc())
|
||||
|
||||
|
||||
def delete_all_notifications_by_path_prefix(prefix):
|
||||
(Notification
|
||||
.delete()
|
||||
.where(Notification.lookup_path % prefix)
|
||||
.execute())
|
||||
|
||||
|
||||
def delete_all_notifications_by_kind(kind_name):
|
||||
kind_ref = NotificationKind.get(name=kind_name)
|
||||
(Notification
|
||||
|
@ -87,9 +101,10 @@ def delete_matching_notifications(target, kind_name, **kwargs):
|
|||
kind_ref = NotificationKind.get(name=kind_name)
|
||||
|
||||
# Load all notifications for the user with the given kind.
|
||||
notifications = Notification.select().where(
|
||||
Notification.target == target,
|
||||
Notification.kind == kind_ref)
|
||||
notifications = (Notification
|
||||
.select()
|
||||
.where(Notification.target == target,
|
||||
Notification.kind == kind_ref))
|
||||
|
||||
# For each, match the metadata to the specified values.
|
||||
for notification in notifications:
|
||||
|
|
Reference in a new issue