Don't use repository object anywhere in endpoints/api/repositorynotification

Also adds support for audit logging with repo name only
This commit is contained in:
Evan Cordell 2017-07-17 17:55:00 -04:00
parent 047722b295
commit 9dad44e93d
5 changed files with 36 additions and 41 deletions

View file

@ -61,16 +61,15 @@ class RepositoryNotificationList(RepositoryParamResource):
@validate_json_request('NotificationCreateRequest')
def post(self, namespace_name, repository_name):
parsed = request.get_json()
repository = model.get_repository(namespace_name, repository_name)
method_handler = NotificationMethod.get_method(parsed['method'])
try:
method_handler.validate(repository, parsed['config'])
method_handler.validate(namespace_name, repository_name, parsed['config'])
except CannotValidateNotificationMethodException as ex:
raise request_error(message=ex.message)
new_notification = model.create_repo_notification(repository,
new_notification = model.create_repo_notification(namespace_name, repository_name,
parsed['event'],
parsed['method'],
parsed['config'],
@ -81,7 +80,7 @@ class RepositoryNotificationList(RepositoryParamResource):
{'repo': repository_name, 'namespace': namespace_name,
'notification_id': new_notification.uuid,
'event': parsed['event'], 'method': parsed['method']},
repo=repository)
repo_name=repository_name)
return new_notification.to_dict(), 201
@require_repo_admin
@ -117,12 +116,11 @@ class RepositoryNotification(RepositoryParamResource):
@disallow_for_app_repositories
def delete(self, namespace_name, repository_name, uuid):
""" Deletes the specified notification. """
repository = model.get_repository(namespace_name, repository_name)
deleted = model.delete_repo_notification(repository, uuid)
deleted = model.delete_repo_notification(namespace_name, repository_name, uuid)
log_action('delete_repo_notification', namespace_name,
{'repo': repository_name, 'namespace': namespace_name, 'notification_id': uuid,
'event': deleted.event.name, 'method': deleted.method.name},
repo=repository)
repo_name=repository_name)
return 'No Content', 204
@ -131,13 +129,12 @@ class RepositoryNotification(RepositoryParamResource):
@disallow_for_app_repositories
def post(self, namespace_name, repository_name, uuid):
""" Resets repository notification to 0 failures. """
repository = model.get_repository(namespace_name, repository_name)
reset = model.reset_notification_number_of_failures(repository, uuid)
reset = model.reset_notification_number_of_failures(namespace_name, repository_name, uuid)
if reset is not None:
log_action('reset_repo_notification', namespace_name,
{'repo': repository_name, 'namespace': namespace_name, 'notification_id': uuid,
'event': reset.event.name, 'method': reset.method.name},
repo=repository)
repo_name=repository_name)
return 'No Content', 204