private String getOrganizationKey(DbSession dbSession, ComponentDto component) { String organizationUuid = component.getOrganizationUuid(); return dbClient.organizationDao().selectByUuid(dbSession, organizationUuid) .orElseThrow(() -> new IllegalStateException("Unknown organization: " + organizationUuid)) .getKey(); }
void checkProjectBelongsToOrganization(OrganizationDto organization, ComponentDto project) { if (project.getOrganizationUuid().equals(organization.getUuid())) { return; } throw new NotFoundException(format("Project '%s' doesn't exist in organization '%s'", project.getKey(), organization.getKey())); }
public QProfileDto getProfile(DbSession dbSession, OrganizationDto organization, String name, String language) { QProfileDto profile = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name, language); checkFound(profile, "Quality Profile for language '%s' and name '%s' does not exist in organization '%s'", language, name, organization.getKey()); return profile; }
GroupDto getGroup(DbSession dbSession, OrganizationDto organization, String groupName) { Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), groupName); checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", groupName, organization.getKey()); return group.get(); }
private void setCompareToProfile(DbSession dbSession, RuleQuery query, Request request) { String compareToProfileUuid = request.param(PARAM_COMPARE_TO_PROFILE); if (compareToProfileUuid == null) { return; } QProfileDto profileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, compareToProfileUuid); QProfileDto profile = checkFound(profileOptional, "The specified qualityProfile '%s' does not exist", compareToProfileUuid); checkArgument(query.getOrganization().getUuid().equals(profile.getOrganizationUuid()), format("The specified quality profile '%s' is not part of the specified organization '%s'", profile.getKee(), query.getOrganization().getKey())); query.setCompareToQProfile(profile); } }
static UserGroups.Group.Builder toProtobuf(OrganizationDto organization, GroupDto group, int membersCount, boolean isDefault) { UserGroups.Group.Builder wsGroup = UserGroups.Group.newBuilder() .setId(group.getId()) .setOrganization(organization.getKey()) .setName(group.getName()) .setMembersCount(membersCount) .setDefault(isDefault); ofNullable(group.getDescription()).ifPresent(wsGroup::setDescription); return wsGroup; }
@Test public void no_content_http_204_returned() { TestResponse result = call(organization.getKey(), user.getLogin()); assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT); assertThat(result.getInput()).isEmpty(); }
@Test public void get_returns_DefaultOrganization_populated_from_DB() { insertOrganization(ORGANIZATION_DTO_1, DATE_1); dbClient.internalPropertiesDao().save(dbSession, DEFAULT_ORGANIZATION, ORGANIZATION_DTO_1.getUuid()); dbSession.commit(); DefaultOrganization defaultOrganization = underTest.get(); assertThat(defaultOrganization.getUuid()).isEqualTo(ORGANIZATION_DTO_1.getUuid()); assertThat(defaultOrganization.getKey()).isEqualTo(ORGANIZATION_DTO_1.getKey()); assertThat(defaultOrganization.getName()).isEqualTo(ORGANIZATION_DTO_1.getName()); assertThat(defaultOrganization.getCreatedAt()).isEqualTo(DATE_1); assertThat(defaultOrganization.getUpdatedAt()).isEqualTo(DATE_1); }
@Before public void setUp() throws Exception { defaultOrganizationKey = db.getDefaultOrganization().getKey(); defaultOrganizationUuid = db.getDefaultOrganization().getUuid(); }
@Test public void execute_set_organization_from_ce_task_when_organizationKey_is_not_set_in_report() { reportReader.setMetadata( newBatchReportBuilder() .build()); underTest.execute(new TestComputationStepContext()); Organization organization = analysisMetadataHolder.getOrganization(); OrganizationDto defaultOrganization = db.getDefaultOrganization(); assertThat(organization.getUuid()).isEqualTo(defaultOrganization.getUuid()); assertThat(organization.getKey()).isEqualTo(defaultOrganization.getKey()); assertThat(organization.getName()).isEqualTo(defaultOrganization.getName()); }
@Test public void fail_if_project_exists_but_does_not_belong_to_requested_organization() { OrganizationDto organization = organizationDbTester.insert(); ComponentDto project = componentDbTester.insertPrivateProject(); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Project '%s' does not belong to organisation '%s'", project.getKey(), organization.getKey())); userSession.logIn().addProjectPermission(ADMIN, project); wsActionTester.newRequest() .setParam(ORGANIZATION_KEY_PARAM, organization.getKey()) .setParam(PROJECT_KEY_PARAM, project.getKey()) .execute(); }
@Test public void remove_from_default_organization_group() { GroupDto defaultGroup = db.users().insertDefaultGroup(organization, "default"); db.users().insertMember(defaultGroup, user); call(organization.getKey(), user.getLogin()); assertThat(dbClient.groupMembershipDao().selectGroupIdsByUserId(dbSession, user.getId())).isEmpty(); }
private void executeRequest(GroupDto groupDto, OrganizationDto organizationDto, String permission) { newRequest() .setParam(PARAM_GROUP_NAME, groupDto.getName()) .setParam(PARAM_PERMISSION, permission) .setParam(PARAM_ORGANIZATION, organizationDto.getKey()) .execute(); }
@Test public void filter_organization_user_is_member_of() { UserDto user = db.users().insertUser(); userSession.logIn(user); OrganizationDto organization = db.organizations().insert(); OrganizationDto organizationWithoutMember = db.organizations().insert(); db.organizations().addMember(organization, user); SearchWsResponse result = call(ws.newRequest().setParam(PARAM_MEMBER, String.valueOf(true))); assertThat(result.getOrganizationsList()).extracting(Organization::getKey) .containsExactlyInAnyOrder(organization.getKey()) .doesNotContain(organizationWithoutMember.getKey()); }
@Test public void remove_member_from_db_and_user_index() { assertMember(organization.getUuid(), user); call(organization.getKey(), user.getLogin()); assertNotAMember(organization.getUuid(), user); }
@Test public void request_fails_if_user_is_administrator_of_another_organization() { OrganizationDto org = dbTester.organizations().insert(); logInAsAdministrator(dbTester.getDefaultOrganization()); expectedException.expect(ForbiddenException.class); expectedException.expectMessage("Insufficient privileges"); executeKeyRequest(org.getKey(), "name"); }
@Test public void return_homepage_when_set_to_an_organization() { OrganizationDto organizationDto = db.organizations().insert(); UserDto user = db.users().insertUser(u -> u.setHomepageType("ORGANIZATION").setHomepageParameter(organizationDto.getUuid())); userSessionRule.logIn(user); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType, CurrentWsResponse.Homepage::getOrganization) .containsExactly(CurrentWsResponse.HomepageType.ORGANIZATION, organizationDto.getKey()); }
@Test public void selectOrganizationsWithNcloc_with_organization_without_projects() { MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY)); OrganizationDto org1 = db.organizations().insert(); assertThat(underTest.selectOrganizationsWithNcloc(dbSession, Lists.newArrayList(org1.getUuid()))) .extracting(OrganizationWithNclocDto::getId, OrganizationWithNclocDto::getKee, OrganizationWithNclocDto::getName, OrganizationWithNclocDto::getNcloc) .containsExactlyInAnyOrder( tuple(org1.getUuid(), org1.getKey(), org1.getName(), 0L) ); }
@Test public void search_for_projects_on_given_organization() { OrganizationDto organization1 = db.organizations().insert(); OrganizationDto organization2 = db.organizations().insert(); userSession.addPermission(ADMINISTER, organization1); ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organization1); ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organization1); ComponentDto project3 = ComponentTesting.newPrivateProjectDto(organization2); db.components().insertComponents(project1, project2, project3); SearchWsResponse response = call(SearchRequest.builder().setOrganization(organization1.getKey()).build()); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project1.getDbKey(), project2.getDbKey()); }
@Test public void add_member_as_organization_admin() { OrganizationDto organization = db.organizations().insert(); db.users().insertDefaultGroup(organization, "default"); UserDto user = db.users().insertUser(); db.organizations().addMember(db.getDefaultOrganization(), user); userSession.logIn().addPermission(ADMINISTER, organization); call(organization.getKey(), user.getLogin()); assertMember(organization.getUuid(), user.getId()); }