Add e-mail authorization to the repository notification flow. Also validates the creation of the other notification methods.

This commit is contained in:
Joseph Schorr 2014-07-28 14:58:12 -04:00
parent 56fec63fcd
commit 34fc279092
15 changed files with 483 additions and 34 deletions

View file

@ -1,11 +1,13 @@
import json
from flask import request
from flask import request, abort
from app import notification_queue
from endpoints.api import (RepositoryParamResource, nickname, resource, require_repo_admin,
log_action, validate_json_request, api, NotFound)
log_action, validate_json_request, api, NotFound, request_error)
from endpoints.notificationevent import NotificationEvent
from endpoints.notificationmethod import (NotificationMethod,
CannotValidateNotificationMethodException)
from data import model
@ -62,6 +64,15 @@ class RepositoryNotificationList(RepositoryParamResource):
repo = model.get_repository(namespace, repository)
json = request.get_json()
method_handler = NotificationMethod.get_method(json['method'])
if not method_handler:
raise request_error(message='Unknown method')
try:
method_handler.validate(repo, json['config'])
except CannotValidateNotificationMethodException as ex:
raise request_error(message=ex.message)
notification = model.create_repo_notification(repo, json['event'], json['method'],
json['config'])