use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class OrganizationCreationImpl method insertOrganization.
private OrganizationDto insertOrganization(DbSession dbSession, NewOrganization newOrganization, Consumer<OrganizationDto> extendCreation) {
OrganizationDto res = new OrganizationDto().setUuid(uuidFactory.create()).setName(newOrganization.getName()).setKey(newOrganization.getKey()).setDescription(newOrganization.getDescription()).setUrl(newOrganization.getUrl()).setAvatarUrl(newOrganization.getAvatar());
extendCreation.accept(res);
dbClient.organizationDao().insert(dbSession, res);
return res;
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class OrganizationCreationImpl method create.
@Override
public OrganizationDto create(DbSession dbSession, int creatorUserId, NewOrganization newOrganization) throws KeyConflictException {
validate(newOrganization);
String key = newOrganization.getKey();
if (organizationKeyIsUsed(dbSession, key)) {
throw new KeyConflictException(format("Organization key '%s' is already used", key));
}
OrganizationDto organization = insertOrganization(dbSession, newOrganization, dto -> {
});
GroupDto group = insertOwnersGroup(dbSession, organization);
insertDefaultTemplate(dbSession, organization, group);
addCurrentUserToGroup(dbSession, group, creatorUserId);
dbSession.commit();
return organization;
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(request.mandatoryParamAsInt(Param.PAGE_SIZE)).andTotal(0);
OrganizationQuery organizationQuery = newOrganizationQueryBuilder().setKeys(request.paramAsStrings(PARAM_ORGANIZATIONS)).build();
List<OrganizationDto> dtos = dbClient.organizationDao().selectByQuery(dbSession, organizationQuery, paging.offset(), paging.pageSize());
writeResponse(request, response, dtos);
}
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
organizationFlags.checkEnabled(dbSession);
String key = request.mandatoryParam(PARAM_KEY);
UpdateOrganizationRequest updateRequest = new UpdateOrganizationRequest(request.getParam(PARAM_NAME, (rqt, paramKey) -> wsSupport.getAndCheckName(rqt)), request.getParam(PARAM_DESCRIPTION, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckDescription(rqt))), request.getParam(PARAM_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckUrl(rqt))), request.getParam(PARAM_AVATAR_URL, (rqt, paramKey) -> emptyAsNull(wsSupport.getAndCheckAvatar(rqt))));
OrganizationDto dto = getDto(dbSession, key);
userSession.checkPermission(ADMINISTER, dto);
dto.setName(updateRequest.getName().or(dto::getName)).setDescription(updateRequest.getDescription().or(dto::getDescription)).setUrl(updateRequest.getUrl().or(dto::getUrl)).setAvatarUrl(updateRequest.getAvatar().or(dto::getAvatarUrl));
dbClient.organizationDao().update(dbSession, dto);
dbSession.commit();
writeResponse(request, response, dto);
}
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class RemoveUserAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
UserId user = support.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
checkProjectAdmin(userSession, org.getUuid(), projectId);
PermissionChange change = new UserPermissionChange(PermissionChange.Operation.REMOVE, org.getUuid(), request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), user);
permissionUpdater.apply(dbSession, asList(change));
response.noContent();
}
}
Aggregations