Search in sources :

Example 96 with GroupDto

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

the class UserIdentityAuthenticatorTest method ignore_groups_on_non_default_organizations.

@Test
public void ignore_groups_on_non_default_organizations() throws Exception {
    OrganizationDto org = db.organizations().insert();
    UserDto user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN).setActive(true).setName("John"));
    String groupName = "a-group";
    GroupDto groupInDefaultOrg = db.users().insertGroup(db.getDefaultOrganization(), groupName);
    GroupDto groupInOrg = db.users().insertGroup(org, groupName);
    // adding a group with the same name than in non-default organization
    underTest.authenticate(UserIdentity.builder().setProviderLogin("johndoo").setLogin(user.getLogin()).setName(user.getName()).setGroups(newHashSet(groupName)).build(), IDENTITY_PROVIDER, Source.sso());
    assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(groupInDefaultOrg.getId());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 97 with GroupDto

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

the class CreateActionTest method request_creates_owners_group_with_all_permissions_for_new_organization_and_add_current_user_to_it.

@Test
public void request_creates_owners_group_with_all_permissions_for_new_organization_and_add_current_user_to_it() {
    mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
    UserDto user = dbTester.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    executeRequest("orgFoo");
    DbSession dbSession = dbTester.getSession();
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "orgfoo").get();
    Optional<GroupDto> groupDtoOptional = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners");
    assertThat(groupDtoOptional).isNotEmpty();
    GroupDto groupDto = groupDtoOptional.get();
    assertThat(groupDto.getDescription()).isEqualTo("Owners of organization orgFoo");
    assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()]));
    List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers(dbSession, UserMembershipQuery.builder().groupId(groupDto.getId()).membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE);
    assertThat(members).extracting(UserMembershipDto::getLogin).containsOnly(user.getLogin());
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserMembershipDto(org.sonar.db.user.UserMembershipDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 98 with GroupDto

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

the class DeleteActionTest method request_also_deletes_permissions_templates_and_permissions_and_groups_of_specified_organization.

@Test
public void request_also_deletes_permissions_templates_and_permissions_and_groups_of_specified_organization() {
    OrganizationDto org = dbTester.organizations().insert();
    OrganizationDto otherOrg = dbTester.organizations().insert();
    UserDto user1 = dbTester.users().insertUser();
    UserDto user2 = dbTester.users().insertUser();
    GroupDto group1 = dbTester.users().insertGroup(org);
    GroupDto group2 = dbTester.users().insertGroup(org);
    GroupDto otherGroup1 = dbTester.users().insertGroup(otherOrg);
    GroupDto otherGroup2 = dbTester.users().insertGroup(otherOrg);
    ComponentDto projectDto = dbTester.components().insertProject(org);
    ComponentDto otherProjectDto = dbTester.components().insertProject(otherOrg);
    dbTester.users().insertPermissionOnAnyone(org, "u1");
    dbTester.users().insertPermissionOnAnyone(otherOrg, "not deleted u1");
    dbTester.users().insertPermissionOnUser(org, user1, "u2");
    dbTester.users().insertPermissionOnUser(otherOrg, user1, "not deleted u2");
    dbTester.users().insertPermissionOnGroup(group1, "u3");
    dbTester.users().insertPermissionOnGroup(otherGroup1, "not deleted u3");
    dbTester.users().insertProjectPermissionOnAnyone("u4", projectDto);
    dbTester.users().insertProjectPermissionOnAnyone("not deleted u4", otherProjectDto);
    dbTester.users().insertProjectPermissionOnGroup(group1, "u5", projectDto);
    dbTester.users().insertProjectPermissionOnGroup(otherGroup1, "not deleted u5", otherProjectDto);
    dbTester.users().insertProjectPermissionOnUser(user1, "u6", projectDto);
    dbTester.users().insertProjectPermissionOnUser(user1, "not deleted u6", otherProjectDto);
    PermissionTemplateDto templateDto = dbTester.permissionTemplates().insertTemplate(org);
    PermissionTemplateDto otherTemplateDto = dbTester.permissionTemplates().insertTemplate(otherOrg);
    logInAsAdministrator(org);
    sendRequest(org);
    verifyOrganizationDoesNotExist(org);
    assertThat(dbClient.groupDao().selectByIds(session, of(group1.getId(), otherGroup1.getId(), group2.getId(), otherGroup2.getId()))).extracting(GroupDto::getId).containsOnly(otherGroup1.getId(), otherGroup2.getId());
    assertThat(dbClient.permissionTemplateDao().selectByUuid(session, templateDto.getUuid())).isNull();
    assertThat(dbClient.permissionTemplateDao().selectByUuid(session, otherTemplateDto.getUuid())).isNotNull();
    assertThat(dbTester.select("select role as \"role\" from USER_ROLES")).extracting(row -> (String) row.get("role")).doesNotContain("u2", "u6").contains("not deleted u2", "not deleted u6");
    assertThat(dbTester.select("select role as \"role\" from GROUP_ROLES")).extracting(row -> (String) row.get("role")).doesNotContain("u1", "u3", "u4", "u5").contains("not deleted u1", "not deleted u3", "not deleted u4", "not deleted u5");
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 99 with GroupDto

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

the class OrganizationCreationImplTest method verifyGroupOwners.

private void verifyGroupOwners(UserDto user, String organizationKey, String organizationName) {
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, organizationKey).get();
    List<GroupDto> groups = dbClient.groupDao().selectByOrganizationUuid(dbSession, organization.getUuid());
    assertThat(groups).extracting(GroupDto::getName).containsOnly("Owners");
    GroupDto groupDto = groups.iterator().next();
    assertThat(groupDto.getDescription()).isEqualTo("Owners of organization " + organizationName);
    assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()]));
    List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers(dbSession, UserMembershipQuery.builder().groupId(groupDto.getId()).membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE);
    assertThat(members).extracting(UserMembershipDto::getLogin).containsOnly(user.getLogin());
}
Also used : PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserMembershipDto(org.sonar.db.user.UserMembershipDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 100 with GroupDto

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

the class SearchMyOrganizationsActionTest method do_not_return_organization_twice_if_user_has_ADMIN_permission_twice_or_more.

@Test
public void do_not_return_organization_twice_if_user_has_ADMIN_permission_twice_or_more() {
    UserDto user = dbTester.users().insertUser();
    OrganizationDto organization = dbTester.organizations().insert();
    GroupDto group1 = dbTester.users().insertGroup(organization);
    dbTester.users().insertPermissionOnGroup(group1, ADMINISTER);
    dbTester.users().insertPermissionOnUser(organization, user, SYSTEM_ADMIN);
    userSessionRule.logIn(user);
    assertJson(underTest.newRequest().execute().getInput()).isSimilarTo("{\"organizations\": [" + "\"" + organization.getKey() + "\"" + "]}");
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)177 Test (org.junit.Test)158 OrganizationDto (org.sonar.db.organization.OrganizationDto)74 UserDto (org.sonar.db.user.UserDto)67 ComponentDto (org.sonar.db.component.ComponentDto)38 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)31 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)18 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)17 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 UserGroupDto (org.sonar.db.user.UserGroupDto)12 DbSession (org.sonar.db.DbSession)11 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)3 System2 (org.sonar.api.utils.System2)3 DbClient (org.sonar.db.DbClient)3 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)3 Strings (com.google.common.base.Strings)2