aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java2
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/usergroups/ws/create-example.json3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java20
-rw-r--r--sonar-ws/src/main/protobuf/ws-user_groups.proto1
6 files changed, 31 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java
index ca57ed96931..554adff2c4d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/CreateAction.java
@@ -104,7 +104,8 @@ public class CreateAction implements UserGroupsWsAction {
private void writeResponse(Request request, Response response, OrganizationDto organization, GroupDto group) {
WsUserGroups.CreateWsResponse.Builder respBuilder = WsUserGroups.CreateWsResponse.newBuilder();
- respBuilder.setGroup(toProtobuf(organization, group, 0));
+ // 'default' is always false as it's not possible to create a default group
+ respBuilder.setGroup(toProtobuf(organization, group, 0, false));
writeProtobuf(respBuilder.build(), request, response);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java
index 2fa8788bc5b..f088eb21373 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/GroupWsSupport.java
@@ -34,6 +34,7 @@ import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonarqube.ws.WsUserGroups;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.server.user.UserUpdater.SONAR_USERS_GROUP_NAME;
import static org.sonar.server.ws.WsUtils.checkFound;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
@@ -152,15 +153,14 @@ public class GroupWsSupport {
checkArgument(!SONAR_USERS_GROUP_NAME.equals(groupDto.getName()), "Default group '%s' cannot be used to perform this action", SONAR_USERS_GROUP_NAME);
}
- static WsUserGroups.Group.Builder toProtobuf(OrganizationDto organization, GroupDto group, int membersCount) {
+ static WsUserGroups.Group.Builder toProtobuf(OrganizationDto organization, GroupDto group, int membersCount, boolean isDefault) {
WsUserGroups.Group.Builder wsGroup = WsUserGroups.Group.newBuilder()
.setId(group.getId())
.setOrganization(organization.getKey())
.setName(group.getName())
- .setMembersCount(membersCount);
- if (group.getDescription() != null) {
- wsGroup.setDescription(group.getDescription());
- }
+ .setMembersCount(membersCount)
+ .setDefault(isDefault);
+ setNullable(group.getDescription(), wsGroup::setDescription);
return wsGroup;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java
index 97713d237f8..57b7191fbd9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java
@@ -130,7 +130,7 @@ public class UpdateAction implements UserGroupsWsAction {
int membersCount = dbClient.groupMembershipDao().countMembers(dbSession, query);
WsUserGroups.UpdateWsResponse.Builder respBuilder = WsUserGroups.UpdateWsResponse.newBuilder();
- respBuilder.setGroup(toProtobuf(organization, group, membersCount));
+ respBuilder.setGroup(toProtobuf(organization, group, membersCount, false));
writeProtobuf(respBuilder.build(), request, response);
}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/usergroups/ws/create-example.json b/server/sonar-server/src/main/resources/org/sonar/server/usergroups/ws/create-example.json
index 91ea7df4d1a..909f1491ab6 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/usergroups/ws/create-example.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/usergroups/ws/create-example.json
@@ -4,6 +4,7 @@
"organization": "my-org",
"name": "some-product-bu",
"description": "Business Unit for Some Awesome Product",
- "membersCount": 0
+ "membersCount": 0,
+ "default": false
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java
index ba6b7b9040f..7bbcaf7a732 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java
@@ -100,6 +100,25 @@ public class CreateActionTest {
}
@Test
+ public void return_default_field() throws Exception {
+ loginAsAdminOnDefaultOrganization();
+
+ newRequest()
+ .setParam("name", "some-product-bu")
+ .setParam("description", "Business Unit for Some Awesome Product")
+ .execute()
+ .assertJson("{" +
+ " \"group\": {" +
+ " \"organization\": \"" + getDefaultOrganization().getKey() + "\"," +
+ " \"name\": \"some-product-bu\"," +
+ " \"description\": \"Business Unit for Some Awesome Product\"," +
+ " \"membersCount\": 0," +
+ " \"default\": false" +
+ " }" +
+ "}");
+ }
+
+ @Test
public void fail_if_not_administrator() throws Exception {
userSession.logIn("not-admin");
@@ -210,6 +229,7 @@ public class CreateActionTest {
.execute();
}
+
private WsTester.TestRequest newRequest() {
return ws.newPostRequest("api/user_groups", "create");
}
diff --git a/sonar-ws/src/main/protobuf/ws-user_groups.proto b/sonar-ws/src/main/protobuf/ws-user_groups.proto
index d9fc797f484..25c7704ce9f 100644
--- a/sonar-ws/src/main/protobuf/ws-user_groups.proto
+++ b/sonar-ws/src/main/protobuf/ws-user_groups.proto
@@ -48,4 +48,5 @@ message Group {
optional string name = 3;
optional string description = 4;
optional int32 membersCount = 5;
+ optional bool default = 6;
}