From 43aed7c6f4720ff29316ebf185dfbf6908c4e0cd Mon Sep 17 00:00:00 2001 From: EvB Date: Tue, 6 Dec 2016 16:26:28 -0500 Subject: [PATCH] fix(endpoints/api): return empty 204 resp Return an empty body on API requests with status code 204, which means "No content". Incorrect 'Deleted' responses were being returned after successful DELETE operations despite the "No Content" definition of 204. --- endpoints/api/manifest.py | 2 +- endpoints/api/organization.py | 6 +++--- endpoints/api/permission.py | 4 ++-- endpoints/api/prototype.py | 2 +- endpoints/api/repository.py | 2 +- endpoints/api/repotoken.py | 2 +- endpoints/api/robot.py | 4 ++-- endpoints/api/superuser.py | 4 ++-- endpoints/api/tag.py | 2 +- endpoints/api/team.py | 10 +++++----- endpoints/api/user.py | 6 +++--- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/endpoints/api/manifest.py b/endpoints/api/manifest.py index f41cb58b5..0307ecaba 100644 --- a/endpoints/api/manifest.py +++ b/endpoints/api/manifest.py @@ -154,5 +154,5 @@ class ManageRepositoryManifestLabel(RepositoryParamResource): } log_action('manifest_label_delete', namespace, metadata, repo=tag_manifest.tag.repository) - return 'Deleted', 204 + return '', 204 diff --git a/endpoints/api/organization.py b/endpoints/api/organization.py index 3f9beb869..854451454 100644 --- a/endpoints/api/organization.py +++ b/endpoints/api/organization.py @@ -215,7 +215,7 @@ class Organization(ApiResource): raise NotFound() model.user.delete_user(org, all_queues) - return 'Deleted', 204 + return '', 204 raise Unauthorized() @@ -380,7 +380,7 @@ class OrganizationMember(ApiResource): # Remove the user from the organization. model.organization.remove_organization_member(org, user) - return 'Deleted', 204 + return '', 204 raise Unauthorized() @@ -616,7 +616,7 @@ class OrganizationApplicationResource(ApiResource): log_action('delete_application', orgname, {'application_name': application.name, 'client_id': client_id}) - return 'Deleted', 204 + return '', 204 raise Unauthorized() diff --git a/endpoints/api/permission.py b/endpoints/api/permission.py index 7dac02d71..f07d87b2f 100644 --- a/endpoints/api/permission.py +++ b/endpoints/api/permission.py @@ -212,7 +212,7 @@ class RepositoryUserPermission(RepositoryParamResource): {'username': username, 'repo': repository}, repo=model.repository.get_repository(namespace, repository)) - return 'Deleted', 204 + return '', 204 @resource('/v1/repository//permissions/team/') @@ -278,4 +278,4 @@ class RepositoryTeamPermission(RepositoryParamResource): {'team': teamname, 'repo': repository}, repo=model.repository.get_repository(namespace, repository)) - return 'Deleted', 204 + return '', 204 diff --git a/endpoints/api/prototype.py b/endpoints/api/prototype.py index 24c661a26..f14458594 100644 --- a/endpoints/api/prototype.py +++ b/endpoints/api/prototype.py @@ -229,7 +229,7 @@ class PermissionPrototype(ApiResource): log_prototype_action('delete_prototype_permission', orgname, prototype) - return 'Deleted', 204 + return '', 204 raise Unauthorized() diff --git a/endpoints/api/repository.py b/endpoints/api/repository.py index 9557cb0e5..ec80269b1 100644 --- a/endpoints/api/repository.py +++ b/endpoints/api/repository.py @@ -363,7 +363,7 @@ class Repository(RepositoryParamResource): log_action('delete_repo', namespace, {'repo': repository, 'namespace': namespace}) - return 'Deleted', 204 + return '', 204 @resource('/v1/repository//changevisibility') diff --git a/endpoints/api/repotoken.py b/endpoints/api/repotoken.py index 53c060362..5ef427bf9 100644 --- a/endpoints/api/repotoken.py +++ b/endpoints/api/repotoken.py @@ -134,4 +134,4 @@ class RepositoryToken(RepositoryParamResource): 'code': code}, repo=model.repository.get_repository(namespace, repository)) - return 'Deleted', 204 + return '', 204 diff --git a/endpoints/api/robot.py b/endpoints/api/robot.py index f111ba17f..8f1cbde73 100644 --- a/endpoints/api/robot.py +++ b/endpoints/api/robot.py @@ -115,7 +115,7 @@ class UserRobot(ApiResource): parent = get_authenticated_user() model.user.delete_robot(format_robot_username(parent.username, robot_shortname)) log_action('delete_robot', parent.username, {'robot': robot_shortname}) - return 'Deleted', 204 + return '', 204 @resource('/v1/organization//robots') @@ -178,7 +178,7 @@ class OrgRobot(ApiResource): if permission.can(): model.user.delete_robot(format_robot_username(orgname, robot_shortname)) log_action('delete_robot', orgname, {'robot': robot_shortname}) - return 'Deleted', 204 + return '', 204 raise Unauthorized() diff --git a/endpoints/api/superuser.py b/endpoints/api/superuser.py index 4f5a77749..cdb12ca98 100644 --- a/endpoints/api/superuser.py +++ b/endpoints/api/superuser.py @@ -369,7 +369,7 @@ class SuperUserManagement(ApiResource): abort(403) model.user.delete_user(user, all_queues, force=True) - return 'Deleted', 204 + return '', 204 abort(403) @@ -503,7 +503,7 @@ class SuperUserOrganizationManagement(ApiResource): org = model.organization.get_organization(name) model.user.delete_user(org, all_queues) - return 'Deleted', 204 + return '', 204 abort(403) diff --git a/endpoints/api/tag.py b/endpoints/api/tag.py index eeca246df..51ace9d9c 100644 --- a/endpoints/api/tag.py +++ b/endpoints/api/tag.py @@ -122,7 +122,7 @@ class RepositoryTag(RepositoryParamResource): {'username': username, 'repo': repository, 'tag': tag}, repo=model.repository.get_repository(namespace, repository)) - return 'Deleted', 204 + return '', 204 @resource('/v1/repository//tag//images') diff --git a/endpoints/api/team.py b/endpoints/api/team.py index 3fdb5bd5f..a427c472a 100644 --- a/endpoints/api/team.py +++ b/endpoints/api/team.py @@ -175,7 +175,7 @@ class OrganizationTeam(ApiResource): if permission.can(): model.team.remove_team(orgname, teamname, get_authenticated_user().username) log_action('org_delete_team', orgname, {'team': teamname}) - return 'Deleted', 204 + return '', 204 raise Unauthorized() @@ -293,11 +293,11 @@ class TeamMember(ApiResource): 'team': teamname, 'member': membername }) - return 'Deleted', 204 + return '', 204 model.team.remove_user_from_team(orgname, teamname, membername, invoking_user) log_action('org_remove_team_member', orgname, {'member': membername, 'team': teamname}) - return 'Deleted', 204 + return '', 204 raise Unauthorized() @@ -353,7 +353,7 @@ class InviteTeamMember(ApiResource): 'team': teamname, 'member': email }) - return 'Deleted', 204 + return '', 204 raise Unauthorized() @@ -418,4 +418,4 @@ class TeamMemberInvite(ApiResource): 'inviter': inviter.username }) - return 'Deleted', 204 + return '', 204 diff --git a/endpoints/api/user.py b/endpoints/api/user.py index 114ac7277..e26727225 100644 --- a/endpoints/api/user.py +++ b/endpoints/api/user.py @@ -421,7 +421,7 @@ class User(ApiResource): abort(404) model.user.delete_user(get_authenticated_user(), all_queues) - return 'Deleted', 204 + return '', 204 @resource('/v1/user/private') @@ -873,7 +873,7 @@ class UserAuthorization(ApiResource): raise NotFound() access_token.delete_instance(recursive=True, delete_nullable=True) - return 'Deleted', 204 + return '', 204 @resource('/v1/user/starred') class StarredRepositoryList(ApiResource): @@ -956,7 +956,7 @@ class StarredRepository(RepositoryParamResource): if repo: model.repository.unstar_repository(user, repo) - return 'Deleted', 204 + return '', 204 @resource('/v1/users/')