Convert over to notifications system. Note this is incomplete

This commit is contained in:
Joseph Schorr 2014-07-17 22:51:58 -04:00
parent de8e898ad0
commit 8d7493cb86
17 changed files with 432 additions and 166 deletions

View file

@ -2,8 +2,10 @@ import json
from flask import request
from app import notification_queue
from endpoints.api import (RepositoryParamResource, nickname, resource, require_repo_admin,
log_action, validate_json_request, api, NotFound)
from endpoints.notificationevent import NotificationEvent
from data import model
@ -23,7 +25,7 @@ def notification_view(notification):
@resource('/v1/repository/<repopath:repository>/notification/')
class NotificaitonList(RepositoryParamResource):
class RepositoryNotificationList(RepositoryParamResource):
""" Resource for dealing with listing and creating notifications on a repository. """
schemas = {
'NotificationCreateRequest': {
@ -81,7 +83,7 @@ class NotificaitonList(RepositoryParamResource):
@resource('/v1/repository/<repopath:repository>/notification/<uuid>')
class Notification(RepositoryParamResource):
class RepositoryNotification(RepositoryParamResource):
""" Resource for dealing with specific notifications. """
@require_repo_admin
@nickname('getRepoNotification')
@ -105,3 +107,28 @@ class Notification(RepositoryParamResource):
repo=model.get_repository(namespace, repository))
return 'No Content', 204
@resource('/v1/repository/<repopath:repository>/notification/<uuid>/test')
class TestRepositoryNotification(RepositoryParamResource):
""" Resource for queuing a test of a notification. """
@require_repo_admin
@nickname('testRepoNotification')
def post(self, namespace, repository, uuid):
""" Queues a test notification for this repository. """
try:
notification = model.get_repo_notification(namespace, repository, uuid)
except model.InvalidNotificationException:
raise NotFound()
event_info = NotificationEvent.get_event(notification.event.name)
sample_data = event_info.get_sample_data(repository=notification.repository)
notification_data = {
'notification_id': notification.id,
'repository_id': notification.repository.id,
'event_data': sample_data
}
notification_queue.put([namespace, repository, notification.event.name],
json.dumps(notification_data))
return {}