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