Search in sources :

Example 26 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class OrganizationCreationImpl method create.

@Override
public OrganizationDto create(DbSession dbSession, int creatorUserId, NewOrganization newOrganization) throws KeyConflictException {
    validate(newOrganization);
    String key = newOrganization.getKey();
    if (organizationKeyIsUsed(dbSession, key)) {
        throw new KeyConflictException(format("Organization key '%s' is already used", key));
    }
    OrganizationDto organization = insertOrganization(dbSession, newOrganization, dto -> {
    });
    GroupDto group = insertOwnersGroup(dbSession, organization);
    insertDefaultTemplate(dbSession, organization, group);
    addCurrentUserToGroup(dbSession, group, creatorUserId);
    dbSession.commit();
    return organization;
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 27 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupWsSupport method findGroup.

/**
   * Finds a user group by its reference. If organization is not defined then group
   * is searched in default organization.
   *
   * @return non-null group
   * @throws NotFoundException if the requested group does not exist
   * @throws NotFoundException if the requested group is Anyone
   */
public GroupId findGroup(DbSession dbSession, GroupWsRef ref) {
    if (ref.hasId()) {
        GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId());
        checkFound(group, "No group with id '%s'", ref.getId());
        return GroupId.from(group);
    }
    OrganizationDto org = findOrganizationByKey(dbSession, ref.getOrganizationKey());
    Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, org.getUuid(), ref.getName());
    checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", ref.getName(), org.getKey());
    return GroupId.from(group.get());
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 28 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class UserIdentityAuthenticatorTest method authenticate_new_user_with_groups.

@Test
public void authenticate_new_user_with_groups() throws Exception {
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    authenticate(USER_LOGIN, "group1", "group2", "group3");
    Optional<UserDto> user = db.users().selectUserByLogin(USER_LOGIN);
    assertThat(user).isPresent();
    assertThat(user.get().isRoot()).isFalse();
    assertThat(db.users().selectGroupIdsOfUser(user.get())).containsOnly(group1.getId(), group2.getId());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 29 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_groups.

@Test
public void authenticate_existing_user_and_remove_groups() throws Exception {
    UserDto user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN).setActive(true).setName("John"));
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    db.users().insertMember(group1, user);
    db.users().insertMember(group2, user);
    authenticate(USER_LOGIN, "group1");
    assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group1.getId());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 30 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_all_groups.

@Test
public void authenticate_existing_user_and_remove_all_groups() throws Exception {
    UserDto user = db.users().insertUser();
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    db.users().insertMember(group1, user);
    db.users().insertMember(group2, user);
    authenticate(user.getLogin());
    assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)424 Test (org.junit.Test)387 UserDto (org.sonar.db.user.UserDto)148 ComponentDto (org.sonar.db.component.ComponentDto)127 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)70 OrganizationDto (org.sonar.db.organization.OrganizationDto)42 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)36 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)34 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)28 DbSession (org.sonar.db.DbSession)20 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)17 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)13 UserGroupDto (org.sonar.db.user.UserGroupDto)12 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)12 TestResponse (org.sonar.server.ws.TestResponse)11 Qualitygates (org.sonarqube.ws.Qualitygates)10 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)9 SearchGroupsResponse (org.sonarqube.ws.Qualityprofiles.SearchGroupsResponse)9