Search in sources :

Example 1 with GroupDto

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();
}
Also used : UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerException(org.sonar.server.exceptions.ServerException) Multimap(com.google.common.collect.Multimap) TestDefaultOrganizationProvider(org.sonar.server.organization.TestDefaultOrganizationProvider) DbSession(org.sonar.db.DbSession) BadRequestException(org.sonar.server.exceptions.BadRequestException) Collections.singletonList(java.util.Collections.singletonList) Strings(com.google.common.base.Strings) ArgumentCaptor(org.mockito.ArgumentCaptor) OrganizationCreation(org.sonar.server.organization.OrganizationCreation) UserTesting.newDisabledUser(org.sonar.db.user.UserTesting.newDisabledUser) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) GroupTesting(org.sonar.db.user.GroupTesting) Assert.fail(org.junit.Assert.fail) NewUserHandler(org.sonar.api.platform.NewUserHandler) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) SearchHit(org.elasticsearch.search.SearchHit) GroupDto(org.sonar.db.user.GroupDto) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserIndexDefinition(org.sonar.server.user.index.UserIndexDefinition) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UserTesting.newLocalUser(org.sonar.db.user.UserTesting.newLocalUser) Mockito.verify(org.mockito.Mockito.verify) UserIndexer(org.sonar.server.user.index.UserIndexer) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SQ_AUTHORITY(org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) UserTesting(org.sonar.db.user.UserTesting) MapEntry.entry(org.assertj.core.data.MapEntry.entry) CORE_DEFAULT_GROUP(org.sonar.api.CoreProperties.CORE_DEFAULT_GROUP) Mockito.mock(org.mockito.Mockito.mock) 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 2 with GroupDto

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();
}
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 3 with GroupDto

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");
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Test(org.junit.Test)

Example 4 with GroupDto

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");
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Test(org.junit.Test)

Example 5 with GroupDto

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

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