/** * Owners group has an hard coded name, a description based on the organization's name and has all global permissions. */ private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) { GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto() .setOrganizationUuid(organization.getUuid()) .setName(OWNERS_GROUP_NAME) .setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName()))); permissionService.getAllOrganizationPermissions().forEach(p -> addPermissionToGroup(dbSession, group, p)); return group; }
public GroupDto create(DbSession dbSession, String organizationUuid) { Optional<GroupDto> existingMembersGroup = dbClient.groupDao().selectByName(dbSession, organizationUuid, DEFAULT_GROUP_NAME); checkArgument(!existingMembersGroup.isPresent(), "The group '%s' already exist on organization '%s'", DEFAULT_GROUP_NAME, organizationUuid); GroupDto defaultGroup = new GroupDto() .setName(DEFAULT_GROUP_NAME) .setDescription("All members of the organization") .setOrganizationUuid(organizationUuid); dbClient.groupDao().insert(dbSession, defaultGroup); dbClient.organizationDao().setDefaultGroupId(dbSession, organizationUuid, defaultGroup); return defaultGroup; }
private List<GroupDto> findGroups(DbSession dbSession, PermissionQuery dbQuery, PermissionTemplateDto template) { List<String> orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getId()); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE)); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
@Test public void select_by_query_with_special_characters() { String groupNameWithSpecialCharacters = "group%_%/name"; underTest.insert(dbSession, newGroupDto().setName(groupNameWithSpecialCharacters).setOrganizationUuid("org1")); db.commit(); List<GroupDto> result = underTest.selectByQuery(dbSession, "org1", "roup%_%/nam", 0, 10); int resultCount = underTest.countByQuery(dbSession, "org1", "roup%_%/nam"); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo(groupNameWithSpecialCharacters); assertThat(resultCount).isEqualTo(1); }
private List<GroupDto> findGroups(DbSession dbSession, OrganizationDto org, PermissionQuery dbQuery) { List<String> orderedNames = dbClient.groupPermissionDao().selectGroupNamesByQuery(dbSession, dbQuery); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, org.getUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
@Test public void selectByNames() { GroupDto group1InOrg1 = underTest.insert(dbSession, newGroupDto().setName("group1").setOrganizationUuid("org1")); GroupDto group2InOrg1 = underTest.insert(dbSession, newGroupDto().setName("group2").setOrganizationUuid("org1")); GroupDto group1InOrg2 = underTest.insert(dbSession, newGroupDto().setName("group1").setOrganizationUuid("org2")); GroupDto group3InOrg2 = underTest.insert(dbSession, newGroupDto().setName("group3").setOrganizationUuid("org2")); dbSession.commit(); assertThat(underTest.selectByNames(dbSession, "org1", asList("group1", "group2", "group3", "missingGroup"))).extracting(GroupDto::getId) .containsOnly(group1InOrg1.getId(), group2InOrg1.getId()); assertThat(underTest.selectByNames(dbSession, "org1", Collections.emptyList())).isEmpty(); assertThat(underTest.selectByNames(dbSession, "missingOrg", asList("group1"))).isEmpty(); }
public GroupDto insertGroup(OrganizationDto organization, String name) { GroupDto group = newGroupDto().setName(name).setOrganizationUuid(organization.getUuid()); return insertGroup(group); }
private static GroupDto newGroup(OrganizationDto org, String name, String description) { return GroupTesting.newGroupDto().setName(name).setDescription(description).setOrganizationUuid(org.getUuid()); } }
public GroupDto insertDefaultGroup(OrganizationDto organization, String name) { return insertDefaultGroup(newGroupDto().setName(name).setOrganizationUuid(organization.getUuid())); }
private void insertDefaultGroup(OrganizationDto org, String name, int numberOfMembers) { GroupDto group = newGroupDto().setName(name).setDescription(capitalize(name)).setOrganizationUuid(org.getUuid()); db.users().insertDefaultGroup(group); addMembers(group, numberOfMembers); }
private void insertGroup(OrganizationDto org, String name, int numberOfMembers) { GroupDto group = newGroupDto().setName(name).setDescription(capitalize(name)).setOrganizationUuid(org.getUuid()); db.users().insertGroup(group); addMembers(group, numberOfMembers); }
@Test public void return_group_membership() { UserDto user = db.users().insertUser(); userSession.logIn(user); db.users().insertMember(db.users().insertGroup(newGroupDto().setName("Jedi")), user); db.users().insertMember(db.users().insertGroup(newGroupDto().setName("Rebel")), user); CurrentWsResponse response = call(); assertThat(response.getGroupsList()).containsOnly("Jedi", "Rebel"); }
public static GroupDto newGroupDto() { GroupDto group = new GroupDto() .setId(nextInt()) .setOrganizationUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(255)) .setDescription(randomAlphanumeric(200)) .setCreatedAt(new Date(nextLong())) .setUpdatedAt(new Date(nextLong())); return group; } }
@Test public void select_group_names_by_query_and_template_returns_anyone() { OrganizationDto organization = db.organizations().insert(); PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate(organization); GroupDto group = db.users().insertGroup(newGroupDto().setName("Group")); PermissionTemplateDto otherTemplate = permissionTemplateDbTester.insertTemplate(organization); permissionTemplateDbTester.addGroupToTemplate(otherTemplate.getId(), group.getId(), USER); assertThat(selectGroupNamesByQueryAndTemplate(builder().setSearchQuery("nyo"), organization, template)) .containsExactly("Anyone"); }
private GroupDto insertGroup(String name, String description) { return db.users().insertGroup(newGroupDto().setName(name).setDescription(description).setOrganizationUuid(db.getDefaultOrganization().getUuid())); }
private GroupDto insertDefaultGroup(String name, String description) { return db.users().insertDefaultGroup(newGroupDto().setName(name).setDescription(description).setOrganizationUuid(db.getDefaultOrganization().getUuid())); }
private GroupDto insertGroupOnDefaultOrganization(String name, String description) { return db.users().insertGroup(newGroupDto().setName(name).setDescription(description).setOrganizationUuid(db.getDefaultOrganization().getUuid())); }
@Test public void associate_default_groups_when_reactivating_user_and_organizations_are_disabled() { UserDto userDto = db.users().insertDisabledUser(); db.organizations().insertForUuid("org1"); GroupDto groupDto = db.users().insertGroup(GroupTesting.newGroupDto().setName("sonar-devs").setOrganizationUuid("org1")); db.users().insertMember(groupDto, userDto); GroupDto defaultGroup = createDefaultGroup(); underTest.reactivateAndCommit(db.getSession(), userDto, NewUser.builder() .setLogin(userDto.getLogin()) .setName(userDto.getName()) .build(), u -> { }); session.commit(); Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, singletonList(userDto.getLogin())); assertThat(groups.get(userDto.getLogin()).stream().anyMatch(g -> g.equals(defaultGroup.getName()))).isTrue(); }
private UserGroupDto insertUserGroup(UserDto user) { GroupDto group = newGroupDto().setName(randomAlphanumeric(30)); dbClient.groupDao().insert(session, group); UserGroupDto dto = new UserGroupDto().setUserId(user.getId()).setGroupId(group.getId()); dbClient.userGroupDao().insert(session, dto); return dto; } }
@Test public void return_groups_from_given_organization() { UserDto user = insertUser(); OrganizationDto organizationDto = db.organizations().insert(); OrganizationDto otherOrganizationDto = db.organizations().insert(); GroupDto group = db.users().insertDefaultGroup(newGroupDto().setName("group1").setOrganizationUuid(organizationDto.getUuid())); GroupDto otherGroup = db.users().insertDefaultGroup(newGroupDto().setName("group2").setOrganizationUuid(otherOrganizationDto.getUuid())); addUserToGroup(user, group); addUserToGroup(user, otherGroup); GroupsWsResponse response = call(ws.newRequest() .setParam("login", USER_LOGIN) .setParam("organization", organizationDto.getKey()) .setParam(Param.SELECTED, ALL.value())); assertThat(response.getGroupsList()) .extracting(GroupsWsResponse.Group::getId, GroupsWsResponse.Group::getName, GroupsWsResponse.Group::getDescription, GroupsWsResponse.Group::getSelected, GroupsWsResponse.Group::getDefault) .containsOnly(tuple(group.getId().longValue(), group.getName(), group.getDescription(), true, true)); }