import java.util.List;
import java.util.function.Consumer;
-import java.util.function.Predicate;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.server.ui.PageRepository;
import org.sonar.server.user.UserSession;
-import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.db.permission.OrganizationPermission.PROVISION_PROJECTS;
import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001;
.prop("canUpdateProjectsVisibilityToPrivate",
userSession.hasPermission(ADMINISTER, organization) &&
billingValidations.canUpdateProjectVisibilityToPrivate(new BillingValidations.Organization(organization.getKey(), organization.getUuid())));
- Predicate<Page> personalOrgForBilling = page -> organization.getUserId() == null || !page.getKey().startsWith("billing/");
- List<Page> pages = pageRepository.getOrganizationPages(false).stream().filter(personalOrgForBilling).collect(toList());
json.name("pages");
- writePages(json, pages);
+ writePages(json, pageRepository.getOrganizationPages(false));
if (userSession.hasPermission(ADMINISTER, organization)) {
- List<Page> adminPages = pageRepository.getOrganizationPages(true).stream().filter(personalOrgForBilling).collect(toList());
json.name("adminPages");
- writePages(json, adminPages);
+ writePages(json, pageRepository.getOrganizationPages(true));
}
json.endObject();
}
.doesNotContain("my-plugin/org-admin-page");
}
- @Test
- public void filter_out_billing_pages_for_personal_organizations() {
- initWithPages(
- Page.builder("my-plugin/org-page").setName("Organization page").setScope(ORGANIZATION).build(),
- Page.builder("my-plugin/org-admin-page").setName("Organization admin page").setScope(ORGANIZATION).setAdmin(true).build(),
- Page.builder("billing/org-page").setName("Organization page").setScope(ORGANIZATION).build(),
- Page.builder("billing/org-admin-page").setName("Organization admin page").setScope(ORGANIZATION).setAdmin(true).build());
- OrganizationDto organization = dbTester.organizations().insert(dto -> dto.setUserId(101));
- userSession.logIn().addPermission(ADMINISTER, organization);
-
- TestResponse response = executeRequest(organization);
-
- assertThat(response.getInput())
- .contains("my-plugin/org-page", "my-plugin/org-admin-page")
- .doesNotContain("billing/org-page")
- .doesNotContain("billing/org-admin-page");
- }
-
- @Test
- public void include_billing_pages_for_non_personal_organizations() {
- initWithPages(
- Page.builder("billing/org-page").setName("Organization page").setScope(ORGANIZATION).build(),
- Page.builder("billing/org-admin-page").setName("Organization admin page").setScope(ORGANIZATION).setAdmin(true).build());
- OrganizationDto organization = dbTester.organizations().insert(dto -> dto.setUserId(null));
- userSession.logIn().addPermission(ADMINISTER, organization);
-
- TestResponse response = executeRequest(organization);
-
- assertThat(response.getInput())
- .contains("billing/org-page", "billing/org-admin-page");
- }
-
@Test
public void returns_non_admin_and_canDelete_false_when_user_not_logged_in_and_key_is_the_default_organization() {
TestResponse response = executeRequest(dbTester.getDefaultOrganization());