]> source.dussan.org Git - sonarqube.git/commitdiff
return `isDefault` in /api/navigation/organization
authorStas Vilchik <vilchiks@gmail.com>
Mon, 20 Feb 2017 09:56:59 +0000 (10:56 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 20 Feb 2017 09:56:59 +0000 (10:56 +0100)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java

index 47cc9146e5cd5f8bb36a4f0e16f3cb8159d08682..2b66b7b9eb31f3e48fbf3dc61991c46fb0dcade4 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.organization.OrganizationDto;
+import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.user.UserSession;
 
 import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
@@ -38,10 +39,12 @@ public class OrganizationAction implements NavigationWsAction {
   private static final String PARAM_ORGANIZATION = "organization";
 
   private final DbClient dbClient;
+  private final DefaultOrganizationProvider defaultOrganizationProvider;
   private final UserSession userSession;
 
-  public OrganizationAction(DbClient dbClient, UserSession userSession) {
+  public OrganizationAction(DbClient dbClient, DefaultOrganizationProvider defaultOrganizationProvider, UserSession userSession) {
     this.dbClient = dbClient;
+    this.defaultOrganizationProvider = defaultOrganizationProvider;
     this.userSession = userSession;
   }
 
@@ -83,6 +86,7 @@ public class OrganizationAction implements NavigationWsAction {
       .prop("canAdmin", userSession.hasOrganizationPermission(organizationUuid, SYSTEM_ADMIN))
       .prop("canProvisionProjects", userSession.hasOrganizationPermission(organizationUuid, GlobalPermissions.PROVISIONING))
       .prop("canDelete", organization.isGuarded() ? userSession.isSystemAdministrator() : userSession.hasOrganizationPermission(organizationUuid, SYSTEM_ADMIN))
+      .prop("isDefault", organization.getKey().equals(defaultOrganizationProvider.get().getKey()))
       .endObject();
   }
 }
index 47193174de5c266d9eb77fa72912b69fdbfeda27..46174db1ace1f935b8aab550b4a7b87fd388d000 100644 (file)
@@ -28,6 +28,8 @@ import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.organization.OrganizationDto;
+import org.sonar.server.organization.DefaultOrganizationProvider;
+import org.sonar.server.organization.TestDefaultOrganizationProvider;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
@@ -46,8 +48,9 @@ public class OrganizationActionTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   private DbClient dbClient = dbTester.getDbClient();
+  private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
 
-  private WsActionTester underTest = new WsActionTester(new OrganizationAction(dbClient, userSession));
+  private WsActionTester underTest = new WsActionTester(new OrganizationAction(dbClient, defaultOrganizationProvider, userSession));
 
   @Test
   public void verify_definition() {