use of org.sonar.db.user.UserMembershipDto in project sonarqube by SonarSource.
the class UsersAction method writeMembers.
private static void writeMembers(JsonWriter json, List<UserMembershipDto> users) {
json.name("users").beginArray();
for (UserMembershipDto user : users) {
json.beginObject().prop(FIELD_LOGIN, user.getLogin()).prop(FIELD_NAME, user.getName()).prop(FIELD_SELECTED, user.getGroupId() != null).endObject();
}
json.endArray();
}
use of org.sonar.db.user.UserMembershipDto in project sonarqube by SonarSource.
the class UsersAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
int page = request.mandatoryParamAsInt(Param.PAGE);
String queryString = request.param(Param.TEXT_QUERY);
String selected = request.mandatoryParam(Param.SELECTED);
try (DbSession dbSession = dbClient.openSession(false)) {
GroupId group = support.findGroup(dbSession, request);
userSession.checkPermission(OrganizationPermission.ADMINISTER, group.getOrganizationUuid());
UserMembershipQuery query = UserMembershipQuery.builder().groupId(group.getId()).memberSearch(queryString).membership(getMembership(selected)).pageIndex(page).pageSize(pageSize).build();
int total = dbClient.groupMembershipDao().countMembers(dbSession, query);
Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
List<UserMembershipDto> users = dbClient.groupMembershipDao().selectMembers(dbSession, query, paging.offset(), paging.pageSize());
JsonWriter json = response.newJsonWriter().beginObject();
writeMembers(json, users);
writePaging(json, paging);
json.endObject().close();
}
}
use of org.sonar.db.user.UserMembershipDto 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.UserMembershipDto 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());
}
Aggregations