From: Stas Vilchik Date: Mon, 20 Feb 2017 09:56:59 +0000 (+0100) Subject: return `isDefault` in /api/navigation/organization X-Git-Tag: 6.3.0.18800~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=297243e70a3ed48eb281a0a1e5ea00813f61eb40;p=sonarqube.git return `isDefault` in /api/navigation/organization --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java index 47cc9146e5c..2b66b7b9eb3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/OrganizationAction.java @@ -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(); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java index 47193174de5..46174db1ace 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/OrganizationActionTest.java @@ -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() {