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;
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;
}
.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();
}
}
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;
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() {