setNullable(organization.getDescription(), builder::setDescription);
setNullable(organization.getUrl(), builder::setUrl);
setNullable(organization.getAvatarUrl(), builder::setAvatar);
- if (organizationAlmBinding != null) {
+ if (onlyMembershipOrganizations && organizationAlmBinding != null) {
builder.setAlm(Organization.Alm.newBuilder()
.setKey(organizationAlmBinding.getAlm().getId())
.setUrl(organizationAlmBinding.getUrl()));
package org.sonar.server.ui.ws;
import java.util.List;
+import java.util.Optional;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.web.page.Page;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.alm.OrganizationAlmBindingDto;
import org.sonar.db.component.ComponentQuery;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.organization.BillingValidations;
JsonWriter json = response.newJsonWriter();
json.beginObject();
- writeOrganization(json, organization, newProjectPrivate);
+ writeOrganization(json, organization, dbClient.organizationAlmBindingDao().selectByOrganization(dbSession, organization), newProjectPrivate);
json.endObject()
.close();
}
}
- private void writeOrganization(JsonWriter json, OrganizationDto organization, boolean newProjectPrivate) {
+ private void writeOrganization(JsonWriter json, OrganizationDto organization, Optional<OrganizationAlmBindingDto> organizationAlmBinding, boolean newProjectPrivate) {
json.name("organization")
.beginObject()
.prop("isDefault", organization.getKey().equals(defaultOrganizationProvider.get().getKey()))
.prop("canUpdateProjectsVisibilityToPrivate",
userSession.hasPermission(ADMINISTER, organization) &&
billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid())));
+ writeAlm(json, organizationAlmBinding);
json.name("pages");
writePages(json, pageRepository.getOrganizationPages(false));
if (userSession.hasPermission(ADMINISTER, organization)) {
.endObject());
json.endArray();
}
+
+ private static void writeAlm(JsonWriter json, Optional<OrganizationAlmBindingDto> organizationAlmBindingOpt) {
+ organizationAlmBindingOpt.ifPresent(
+ organizationAlmBinding -> json
+ .name("alm")
+ .beginObject()
+ .prop("key", organizationAlmBinding.getAlm().getId())
+ .prop("url", organizationAlmBinding.getUrl())
+ .endObject());
+ }
}
}
@Test
- public void return_alm_info() {
+ public void return_alm_info_when_member_parameter_is_set_to_true() {
+ UserDto user = db.users().insertUser();
+ userSession.logIn(user);
OrganizationDto organization = db.organizations().insert();
AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
OrganizationAlmBindingDto organizationAlmBinding = db.alm().insertOrganizationAlmBinding(organization, almAppInstall);
OrganizationDto organizationNotBoundToAlm = db.organizations().insert();
+ db.organizations().addMember(organization, user);
+ db.organizations().addMember(organizationNotBoundToAlm, user);
- SearchWsResponse result = call(ws.newRequest());
+ SearchWsResponse result = call(ws.newRequest().setParam("member", "true"));
Map<String, Organization> orgByKey = result.getOrganizationsList().stream().collect(toMap(Organization::getKey, identity()));
assertThat(orgByKey.get(organization.getKey()).getAlm().getKey()).isEqualTo(organizationAlmBinding.getAlm().getId());
assertThat(orgByKey.get(organizationNotBoundToAlm.getKey()).hasAlm()).isEqualTo(false);
}
+ @Test
+ public void do_not_return_alm_info_when_no_member_parameter() {
+ OrganizationDto organization = db.organizations().insert();
+ AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
+ OrganizationAlmBindingDto organizationAlmBinding = db.alm().insertOrganizationAlmBinding(organization, almAppInstall);
+ OrganizationDto organizationNotBoundToAlm = db.organizations().insert();
+
+ SearchWsResponse result = call(ws.newRequest());
+
+ assertThat(result.getOrganizationsList())
+ .extracting(Organization::getKey, Organization::hasAlm)
+ .containsExactlyInAnyOrder(
+ tuple(organization.getKey(), false),
+ tuple(organizationNotBoundToAlm.getKey(), false));
+ }
+
@Test
public void return_subscription_info_when_member_parameter_is_set_to_true() {
UserDto user = db.users().insertUser();
+ userSession.logIn(user);
OrganizationDto organization1 = db.organizations().insert(o -> o.setSubscription(FREE));
OrganizationDto organization2 = db.organizations().insert(o -> o.setSubscription(PAID));
OrganizationDto organization3 = db.organizations().insert(o -> o.setSubscription(PAID));
db.organizations().addMember(organization1, user);
db.organizations().addMember(organization2, user);
- userSession.logIn(user);
SearchWsResponse result = call(ws.newRequest().setParam("member", "true"));
}
@Test
- public void subscription_info_is_not_returned_when_no_member_parameter() {
+ public void do_not_return_subscription_info_when_no_member_parameter() {
UserDto user = db.users().insertUser();
OrganizationDto organization1 = db.organizations().insert(o -> o.setSubscription(FREE));
OrganizationDto organization2 = db.organizations().insert(o -> o.setSubscription(PAID));
import org.sonar.core.platform.PluginRepository;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.alm.AlmAppInstallDto;
+import org.sonar.db.alm.OrganizationAlmBindingDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.organization.BillingValidations;
OrganizationDto organization = db.organizations().insert();
db.organizations().setNewProjectPrivate(organization, true);
userSession.logIn().addPermission(PROVISION_PROJECTS, organization);
- assertJson(executeRequest(organization).getInput()).isSimilarTo("{\"organization\": {\"projectVisibility\": \"private\"}}");
+
+ TestResponse response = executeRequest(organization);
+
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"projectVisibility\": \"private\"}}");
}
@Test
OrganizationDto organization = db.organizations().insert();
db.organizations().setNewProjectPrivate(organization, false);
userSession.logIn().addPermission(PROVISION_PROJECTS, organization);
- assertJson(executeRequest(organization).getInput()).isSimilarTo("{\"organization\": {\"projectVisibility\": \"public\"}}");
+
+ TestResponse response = executeRequest(organization);
+
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"projectVisibility\": \"public\"}}");
}
@Test
}
@Test
- public void return_subscription_flag() {
+ public void return_FREE_subscription_flag() {
OrganizationDto freeOrganization = db.organizations().insert(o -> o.setSubscription(FREE));
- assertJson(executeRequest(freeOrganization).getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"FREE\"}}");
-
- OrganizationDto sonarQubeOrganization = db.organizations().insert(o -> o.setSubscription(SONARQUBE));
- assertJson(executeRequest(sonarQubeOrganization).getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"SONARQUBE\"}}");
- OrganizationDto paidOrganization = db.organizations().insert(o -> o.setSubscription(PAID));
+ TestResponse response = executeRequest(freeOrganization);
- userSession.logIn()
- .addMembership(paidOrganization);
-
- assertJson(executeRequest(paidOrganization).getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"PAID\"}}");
- }
-
- @Test
- public void do_not_throws_FE_when_not_member_on_free_organization() {
- OrganizationDto freeOrganization = db.organizations().insert(o -> o.setSubscription(FREE));
- executeRequest(freeOrganization).getInput();
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"FREE\"}}");
}
@Test
- public void do_not_throws_FE_when_not_member_on_sonarqube_organization() {
+ public void return_SONARQUBE_subscription_flag() {
OrganizationDto sonarQubeOrganization = db.organizations().insert(o -> o.setSubscription(SONARQUBE));
- executeRequest(sonarQubeOrganization).getInput();
+
+ TestResponse response = executeRequest(sonarQubeOrganization);
+
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"SONARQUBE\"}}");
}
@Test
- public void throws_FE_when_not_member_on_private_organization() {
+ public void return_PAID_subscription_flag() {
OrganizationDto paidOrganization = db.organizations().insert(o -> o.setSubscription(PAID));
+ userSession.logIn().addMembership(paidOrganization);
- expectedException.expect(ForbiddenException.class);
- expectedException.expectMessage("You're not member of organization");
- assertJson(executeRequest(paidOrganization).getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"PAID\"}}");
+ TestResponse response = executeRequest(paidOrganization);
+
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"PAID\"}}");
}
@Test
- public void do_no_throws_FE_when_not_member_on_private_organization_with_public_project() {
+ public void return_PAID_subscription_flag_when_not_member_on_private_organization_with_public_project() {
OrganizationDto paidOrganization = db.organizations().insert(o -> o.setSubscription(PAID));
db.components().insertPublicProject(paidOrganization);
+ userSession.anonymous();
+
+ TestResponse response = executeRequest(paidOrganization);
- assertJson(executeRequest(paidOrganization).getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"PAID\"}}");
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": {\"subscription\": \"PAID\"}}");
}
@Test
- public void return_information_when_member_of_the_organization() {
+ public void throw_FE_when_not_member_on_private_organization_and_no_public_project() {
OrganizationDto paidOrganization = db.organizations().insert(o -> o.setSubscription(PAID));
- userSession.logIn()
- .addMembership(paidOrganization);
+ db.components().insertPrivateProject(paidOrganization);
+
+ expectedException.expect(ForbiddenException.class);
+ expectedException.expectMessage("You're not member of organization");
- executeRequest(paidOrganization).getInput();
+ executeRequest(paidOrganization);
}
@Test
- public void fails_with_IAE_if_parameter_organization_is_not_specified() {
+ public void return_alm_binding() {
+ OrganizationDto organization = db.organizations().insert();
+ AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall();
+ OrganizationAlmBindingDto organizationAlmBinding = db.alm().insertOrganizationAlmBinding(organization, almAppInstall);
+
+ TestResponse response = executeRequest(organization);
+
+ assertJson(response.getInput()).isSimilarTo("{\"organization\": " +
+ " {" +
+ " \"alm\": {" +
+ " \"key\": \"" + organizationAlmBinding.getAlm().getId() + "\"," +
+ " \"url\": \"" + organizationAlmBinding.getUrl() + "\"" +
+ " }" +
+ " }" +
+ "}");
+ }
+
+ @Test
+ public void fail_with_IAE_if_parameter_organization_is_not_specified() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The 'organization' parameter is missing");
TestResponse response = executeRequest(organization);
- assertJson(response.getInput())
- .isSimilarTo(ws.getDef().responseExampleAsString());
+ assertJson(response.getInput()).isSimilarTo(ws.getDef().responseExampleAsString());
}
@Test