Add ability to dismiss notifications
This commit is contained in:
parent
34fc279092
commit
32b2ecdfa6
9 changed files with 162 additions and 11 deletions
|
@ -74,10 +74,12 @@ def user_view(user):
|
|||
|
||||
def notification_view(notification):
|
||||
return {
|
||||
'id': notification.uuid,
|
||||
'organization': notification.target.username if notification.target.organization else None,
|
||||
'kind': notification.kind.name,
|
||||
'created': format_date(notification.created),
|
||||
'metadata': json.loads(notification.metadata_json),
|
||||
'dismissed': notification.dismissed
|
||||
}
|
||||
|
||||
|
||||
|
@ -409,6 +411,46 @@ class UserNotificationList(ApiResource):
|
|||
}
|
||||
|
||||
|
||||
@resource('/v1/user/notifications/<uuid>')
|
||||
@internal_only
|
||||
class UserNotification(ApiResource):
|
||||
schemas = {
|
||||
'UpdateNotification': {
|
||||
'id': 'UpdateNotification',
|
||||
'type': 'object',
|
||||
'description': 'Information for updating a notification',
|
||||
'properties': {
|
||||
'dismissed': {
|
||||
'type': 'boolean',
|
||||
'description': 'Whether the notification is dismissed by the user',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@require_user_admin
|
||||
@nickname('getUserNotification')
|
||||
def get(self, uuid):
|
||||
notification = model.lookup_notification(get_authenticated_user(), uuid)
|
||||
if not notification:
|
||||
raise NotFound()
|
||||
|
||||
return notification_view(notification)
|
||||
|
||||
@require_user_admin
|
||||
@nickname('updateUserNotification')
|
||||
@validate_json_request('UpdateNotification')
|
||||
def put(self, uuid):
|
||||
notification = model.lookup_notification(get_authenticated_user(), uuid)
|
||||
if not notification:
|
||||
raise NotFound()
|
||||
|
||||
notification.dismissed = request.get_json().get('dismissed', False)
|
||||
notification.save()
|
||||
|
||||
return notification_view(notification)
|
||||
|
||||
|
||||
def authorization_view(access_token):
|
||||
oauth_app = access_token.application
|
||||
return {
|
||||
|
|
Reference in a new issue