Search in sources :

Example 1 with UserGroupDto

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

the class SearchActionTest method search_with_groups.

@Test
public void search_with_groups() throws Exception {
    loginAsSystemAdministrator();
    List<UserDto> users = injectUsers(1);
    GroupDto group1 = dbClient.groupDao().insert(dbSession, newGroupDto().setName("sonar-users"));
    GroupDto group2 = dbClient.groupDao().insert(dbSession, newGroupDto().setName("sonar-admins"));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(group1.getId()).setUserId(users.get(0).getId()));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(group2.getId()).setUserId(users.get(0).getId()));
    dbSession.commit();
    ws.newGetRequest("api/users", "search").execute().assertJson(getClass(), "user_with_groups.json");
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) Test(org.junit.Test)

Example 2 with UserGroupDto

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

the class UserIdentityAuthenticator method addGroups.

private void addGroups(DbSession dbSession, UserDto userDto, Collection<String> groupsToAdd, Map<String, GroupDto> groupsByName) {
    groupsToAdd.stream().map(groupsByName::get).filter(Objects::nonNull).forEach(groupDto -> {
        LOGGER.debug("Adding group '{}' to user '{}'", groupDto.getName(), userDto.getLogin());
        dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(groupDto.getId()).setUserId(userDto.getId()));
    });
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto)

Example 3 with UserGroupDto

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

the class UserUpdater method addDefaultGroup.

private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
    List<GroupDto> userGroups = dbClient.groupDao().selectByUserLogin(dbSession, userDto.getLogin());
    GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession);
    if (isUserAlreadyMemberOfDefaultGroup(defaultGroup, userGroups)) {
        return;
    }
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserUuid(userDto.getUuid()).setGroupUuid(defaultGroup.getUuid()), defaultGroup.getName(), userDto.getLogin());
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto)

Example 4 with UserGroupDto

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

the class SearchActionTest method search_json_example.

@Test
public void search_json_example() throws Exception {
    UserDto fmallet = db.users().insertUser(newUserDto("fmallet", "Freddy Mallet", "f@m.com").setActive(true).setLocal(true).setScmAccounts(emptyList()));
    UserDto simon = db.users().insertUser(newUserDto("sbrandhof", "Simon", "s.brandhof@company.tld").setActive(true).setLocal(false).setExternalIdentity("sbrandhof@ldap.com").setExternalIdentityProvider("LDAP").setScmAccounts(newArrayList("simon.brandhof", "s.brandhof@company.tld")));
    GroupDto sonarUsers = db.users().insertGroup(newGroupDto().setName("sonar-users"));
    GroupDto sonarAdministrators = db.users().insertGroup(newGroupDto().setName("sonar-administrators"));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(simon.getId()).setGroupId(sonarUsers.getId()));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(fmallet.getId()).setGroupId(sonarUsers.getId()));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(fmallet.getId()).setGroupId(sonarAdministrators.getId()));
    for (int i = 0; i < 3; i++) {
        dbClient.userTokenDao().insert(dbSession, newUserToken().setLogin(simon.getLogin()));
    }
    dbClient.userTokenDao().insert(dbSession, newUserToken().setLogin(fmallet.getLogin()));
    db.commit();
    userIndexer.indexOnStartup(null);
    loginAsSystemAdministrator();
    String response = ws.newGetRequest("api/users", "search").execute().outputAsString();
    assertJson(response).isSimilarTo(getClass().getResource("search-example.json"));
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) Test(org.junit.Test)

Example 5 with UserGroupDto

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

the class UserRegistrarImpl method addGroups.

private void addGroups(DbSession dbSession, UserDto userDto, Collection<String> groupsToAdd, Map<String, GroupDto> groupsByName) {
    groupsToAdd.stream().map(groupsByName::get).filter(Objects::nonNull).forEach(groupDto -> {
        LOGGER.debug("Adding user '{}' to group '{}'", userDto.getLogin(), groupDto.getName());
        dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupUuid(groupDto.getUuid()).setUserUuid(userDto.getUuid()), groupDto.getName(), userDto.getLogin());
    });
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto)

Aggregations

UserGroupDto (org.sonar.db.user.UserGroupDto)6 GroupDto (org.sonar.db.user.GroupDto)4 UserDto (org.sonar.db.user.UserDto)3 Test (org.junit.Test)2 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)2 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)2 DbSession (org.sonar.db.DbSession)1