use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserUpdaterTest method not_associate_default_group_when_updating_user_if_already_existing.
@Test
public void not_associate_default_group_when_updating_user_if_already_existing() {
UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com"));
GroupDto defaultGroup = createDefaultGroup();
db.users().insertMember(defaultGroup, user);
// User is already associate to the default group
Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).as("Current user groups : %s", groups.get(DEFAULT_GROUP)).isTrue();
underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").setScmAccounts(newArrayList("ma2")));
session.commit();
// Nothing as changed
groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).isTrue();
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserUpdaterTest method associate_default_groups_when_reactivating_user.
@Test
public void associate_default_groups_when_reactivating_user() {
UserDto userDto = db.users().insertUser(newDisabledUser(DEFAULT_LOGIN).setLocal(true).setCreatedAt(PAST).setUpdatedAt(PAST));
db.organizations().insertForUuid("org1");
GroupDto groupDto = db.users().insertGroup(GroupTesting.newGroupDto().setName("sonar-devs").setOrganizationUuid("org1"));
db.users().insertMember(groupDto, userDto);
createDefaultGroup();
underTest.create(NewUser.builder().setLogin(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").build());
session.commit();
Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).isTrue();
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class GroupsActionTest method selected_groups.
@Test
public void selected_groups() throws Exception {
UserDto user = createUser();
GroupDto usersGroup = createGroup("sonar-users", "Sonar Users");
createGroup("sonar-admins", "Sonar Admins");
addUserToGroup(user, usersGroup);
session.commit();
tester.newGetRequest("api/users", "groups").setParam("login", "john").execute().assertJson(getClass(), "selected.json");
tester.newGetRequest("api/users", "groups").setParam("login", "john").setParam(Param.SELECTED, SelectionMode.SELECTED.value()).execute().assertJson(getClass(), "selected.json");
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class GroupsActionTest method all_groups.
@Test
public void all_groups() throws Exception {
UserDto user = createUser();
GroupDto usersGroup = createGroup("sonar-users", "Sonar Users");
createGroup("sonar-admins", "Sonar Admins");
addUserToGroup(user, usersGroup);
session.commit();
tester.newGetRequest("api/users", "groups").setParam("login", "john").setParam(Param.SELECTED, SelectionMode.ALL.value()).execute().assertJson(getClass(), "all.json");
}
use of org.sonar.db.user.GroupDto 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");
}
Aggregations