Return 204 No Content if project/group description was deleted by PUT

Change-Id: I110ee16aacfc898326f2565be716ef8fea0aad4b
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-02-28 09:25:37 +01:00
parent 941229c37f
commit 114ab16e74
5 changed files with 20 additions and 14 deletions

View File

@@ -332,6 +332,8 @@ As response the new group description is returned.
"The committers of MyProject."
----
If the description was deleted the response is "`204 No Content`".
[[delete-group-description]]
DELETE /groups/\{group-id\}/description (Delete Group Description)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -147,6 +147,8 @@ As response the new project description is returned.
"Plugin for Gerrit that handles the replication."
----
If the description was deleted the response is "`204 No Content`".
[[delete-project-description]]
DELETE /projects/\{project-name\}/description (Delete Project Description)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -126,6 +126,14 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
assertEquals(HttpStatus.SC_NO_CONTENT, r.getStatusCode());
adminGroup = groupCache.get(adminGroupName);
assertNull(adminGroup.getDescription());
// set description to empty string
in = new GroupDescriptionInput();
in.description = "";
r = session.put(url, in);
assertEquals(HttpStatus.SC_NO_CONTENT, r.getStatusCode());
adminGroup = groupCache.get(adminGroupName);
assertNull(adminGroup.getDescription());
}
@Test

View File

@@ -47,13 +47,11 @@ public class PutDescription implements RestModifyView<GroupResource, Input> {
}
@Override
public Response<String> apply(GroupResource resource, Input input)
public Object apply(GroupResource resource, Input input)
throws MethodNotAllowedException, AuthException, NoSuchGroupException,
ResourceNotFoundException, OrmException {
boolean delete = false;
if (input == null) {
input = new Input(); // Delete would set description to null.
delete = true;
}
if (resource.toAccountGroup() == null) {
@@ -72,9 +70,8 @@ public class PutDescription implements RestModifyView<GroupResource, Input> {
db.accountGroups().update(Collections.singleton(group));
groupCache.evict(group);
if (delete) {
return Response.none();
}
return Response.ok(Strings.nullToEmpty(input.description));
return Strings.isNullOrEmpty(input.description)
? Response.none()
: input.description;
}
}

View File

@@ -57,13 +57,11 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
}
@Override
public Response<String> apply(ProjectResource resource, Input input)
public Object apply(ProjectResource resource, Input input)
throws AuthException, BadRequestException, ResourceConflictException,
ResourceNotFoundException, IOException {
boolean delete = false;
if (input == null) {
input = new Input(); // Delete would set description to null.
delete = true;
}
ProjectControl ctl = resource.getControl();
@@ -93,10 +91,9 @@ class PutDescription implements RestModifyView<ProjectResource, Input> {
resource.getNameKey(),
project.getDescription());
if (delete) {
return Response.none();
}
return Response.ok(Strings.nullToEmpty(project.getDescription()));
return Strings.isNullOrEmpty(project.getDescription())
? Response.none()
: project.getDescription();
} finally {
md.close();
}