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");
}
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()));
});
}
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());
}
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"));
}
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());
});
}
Aggregations