@Test public void full_test() { Page result = underTest .setComponentQualifiers(PROJECT, MODULE) .setScope(COMPONENT) .setAdmin(true) .build(); assertThat(result.getKey()).isEqualTo("governance/project_dump"); assertThat(result.getPluginKey()).isEqualTo("governance"); assertThat(result.getName()).isEqualTo("Project Dump"); assertThat(result.getComponentQualifiers()).containsOnly(PROJECT, MODULE); assertThat(result.getScope()).isEqualTo(COMPONENT); assertThat(result.isAdmin()).isTrue(); }
@Test public void filter_out_admin_pages_when_user_is_not_admin() { 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()); OrganizationDto organization = db.organizations().insert(dto -> dto.setGuarded(true)); userSession.logIn() .addPermission(PROVISION_PROJECTS, organization); TestResponse response = executeRequest(organization); assertThat(response.getInput()) .contains("my-plugin/org-page") .doesNotContain("my-plugin/org-admin-page"); }
@Test public void get_organization_admin_pages() { PageDefinition plugin = context -> context .addPage(Page.builder("my_plugin/O1").setName("O1").setScope(ORGANIZATION).build()) .addPage(Page.builder("my_plugin/O2").setName("O2").setScope(ORGANIZATION).setAdmin(true).build()); underTest = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[]{plugin}); underTest.start(); List<Page> result = underTest.getOrganizationPages(true); assertThat(result) .extracting(Page::getKey) .containsExactly("my_plugin/O2"); }
@Override public void define(Context context) { context .addPage(Page.builder("example/custom_page_4_project") .setName("Custom Project Page (Pure JS)") .setScope(Scope.COMPONENT).build()) .addPage(Page.builder("example/measures_history") .setName("Custom Project Page using ReactJS") .setScope(Scope.COMPONENT).build()) .addPage(Page.builder("example/custom_page_4_admin") .setName("Custom Admin Page") .setScope(Scope.GLOBAL) .setAdmin(Boolean.TRUE).build()) .addPage(Page.builder("example/sanity_check") .setName("Custom Admin Page Sanity Check") .setScope(Scope.GLOBAL) .setAdmin(Boolean.TRUE).build()) .addPage(Page.builder("example/custom_page_global") .setName("Custom Global Page") .setScope(Scope.GLOBAL).build()); } }
@Override public void define(Context context) { context.addPage( Page.builder("dependencycheck/report") .setScope(Scope.COMPONENT) .setComponentQualifiers(Page.Qualifier.PROJECT, Page.Qualifier.MODULE) .setName("Dependency-Check") .setAdmin(false).build()); } }
@Test public void return_configuration_for_admin() { ComponentDto project = insertOrganizationAndProject(); UserDto user = db.users().insertUser(); userSession.logIn(user) .addProjectPermission(UserRole.USER, project) .addProjectPermission(UserRole.ADMIN, project); Page page1 = Page.builder("my_plugin/first_page") .setName("First Page") .setAdmin(true) .setScope(COMPONENT) .setComponentQualifiers(Qualifier.PROJECT) .build(); Page page2 = Page.builder("my_plugin/second_page") .setName("Second Page") .setAdmin(true) .setScope(COMPONENT) .setComponentQualifiers(Qualifier.PROJECT) .build(); init(page1, page2); executeAndVerify(project.getDbKey(), "return_configuration_for_admin.json"); }
private Page[] createPages() { Page page1 = Page.builder("my_plugin/first_page") .setName("First Page") .setScope(COMPONENT) .setComponentQualifiers(Qualifier.PROJECT) .build(); Page page2 = Page.builder("my_plugin/second_page") .setName("Second Page") .setScope(COMPONENT) .setComponentQualifiers(Qualifier.PROJECT) .build(); Page adminPage = Page.builder("my_plugin/admin_page") .setName("Admin Page") .setScope(COMPONENT) .setComponentQualifiers(Qualifier.PROJECT) .setAdmin(true) .build(); return new Page[] {page1, page2, adminPage}; }
@Test public void get_organization_pages() { PageDefinition plugin = context -> context .addPage(Page.builder("my_plugin/G1").setName("G1").setScope(GLOBAL).build()) .addPage(Page.builder("my_plugin/C1").setName("C1").setScope(COMPONENT).build()) .addPage(Page.builder("my_plugin/O1").setName("O1").setScope(ORGANIZATION).build()) .addPage(Page.builder("my_plugin/O2").setName("O2").setScope(ORGANIZATION).build()) .addPage(Page.builder("my_plugin/O3").setName("O3").setScope(ORGANIZATION).build()) .addPage(Page.builder("my_plugin/OA1").setName("OA1").setScope(ORGANIZATION).setAdmin(true).build()); underTest = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[]{plugin}); underTest.start(); List<Page> result = underTest.getOrganizationPages(false); assertThat(result) .extracting(Page::getKey) .containsExactly("my_plugin/O1", "my_plugin/O2", "my_plugin/O3"); }
private Page[] createPages() { Page page = Page.builder("my_plugin/page").setName("My Plugin Page").build(); Page anotherPage = Page.builder("another_plugin/page").setName("My Another Page").build(); Page adminPage = Page.builder("my_plugin/admin_page").setName("Admin Page").setAdmin(true).build(); return new Page[] {page, anotherPage, adminPage}; } }
@Test public void json_example() { 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()); OrganizationDto organization = db.organizations().insert(dto -> dto.setGuarded(true)); userSession.logIn() .addPermission(ADMINISTER, organization) .addPermission(PROVISION_PROJECTS, organization); TestResponse response = executeRequest(organization); assertJson(response.getInput()).isSimilarTo(ws.getDef().responseExampleAsString()); }