use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
int page = request.mandatoryParamAsInt(Param.PAGE);
int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
SearchOptions options = new SearchOptions().setPage(page, pageSize);
String query = defaultIfBlank(request.param(Param.TEXT_QUERY), "");
Set<String> fields = neededFields(request);
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = groupWsSupport.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY));
userSession.checkLoggedIn().checkPermission(ADMINISTER, organization);
int limit = dbClient.groupDao().countByQuery(dbSession, organization.getUuid(), query);
List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, organization.getUuid(), query, options.getOffset(), pageSize);
List<Integer> groupIds = groups.stream().map(GroupDto::getId).collect(Collectors.toList(groups.size()));
Map<String, Integer> userCountByGroup = dbClient.groupMembershipDao().countUsersByGroups(dbSession, groupIds);
JsonWriter json = response.newJsonWriter().beginObject();
options.writeJson(json, limit);
writeGroups(json, groups, userCountByGroup, fields);
json.endObject().close();
}
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
int groupId = request.mandatoryParamAsInt(PARAM_GROUP_ID);
GroupDto group = dbClient.groupDao().selectById(dbSession, groupId);
checkFound(group, "Could not find a user group with id '%s'.", groupId);
Optional<OrganizationDto> org = dbClient.organizationDao().selectByUuid(dbSession, group.getOrganizationUuid());
checkFoundWithOptional(org, "Could not find organization with id '%s'.", group.getOrganizationUuid());
userSession.checkPermission(ADMINISTER, org.get());
boolean changed = false;
String newName = request.param(PARAM_GROUP_NAME);
if (newName != null) {
changed = true;
UserGroupValidation.validateGroupName(newName);
support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), newName);
String oldName = group.getName();
group.setName(newName);
updateDefaultGroupIfNeeded(dbSession, org.get(), oldName, newName);
}
String description = request.param(PARAM_GROUP_DESCRIPTION);
if (description != null) {
changed = true;
group.setDescription(support.validateDescription(description));
}
if (changed) {
dbClient.groupDao().update(dbSession, group);
dbSession.commit();
}
writeResponse(dbSession, request, response, org.get(), group);
}
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class CreateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = support.findOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION_KEY));
userSession.checkPermission(ADMINISTER, organization);
GroupDto group = new GroupDto().setOrganizationUuid(organization.getUuid()).setName(request.mandatoryParam(PARAM_GROUP_NAME)).setDescription(request.param(PARAM_GROUP_DESCRIPTION));
// validations
UserGroupValidation.validateGroupName(group.getName());
support.validateDescription(group.getDescription());
support.checkNameDoesNotExist(dbSession, group.getOrganizationUuid(), group.getName());
dbClient.groupDao().insert(dbSession, group);
dbSession.commit();
writeResponse(request, response, organization, group);
}
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserIdentityAuthenticatorTest method authenticate_new_user_with_groups.
@Test
public void authenticate_new_user_with_groups() throws Exception {
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
authenticate(USER_LOGIN, "group1", "group2", "group3");
Optional<UserDto> user = db.users().selectUserByLogin(USER_LOGIN);
assertThat(user).isPresent();
assertThat(user.get().isRoot()).isFalse();
assertThat(db.users().selectGroupIdsOfUser(user.get())).containsOnly(group1.getId(), group2.getId());
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_groups.
@Test
public void authenticate_existing_user_and_remove_groups() throws Exception {
UserDto user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN).setActive(true).setName("John"));
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
db.users().insertMember(group1, user);
db.users().insertMember(group2, user);
authenticate(USER_LOGIN, "group1");
assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group1.getId());
}
Aggregations