use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class BackendCleanup method resetData.
/**
* Reset data in order to to be in same state as a fresh installation (but without having to drop db and restart the server).
*
* Please be careful when updating this method as it's called by Orchestrator.
*/
public void resetData() {
try (DbSession dbSession = dbClient.openSession(false);
Connection connection = dbSession.getConnection()) {
truncateAnalysisTables(connection);
deleteManualRules(connection);
truncateInternalProperties(null, null, connection);
truncateUsers(null, null, connection);
truncateOrganizations(null, null, connection);
} catch (SQLException e) {
throw new IllegalStateException("Fail to reset data", e);
}
clearIndex(IssueIndexDefinition.INDEX_TYPE_ISSUE.getIndex());
clearIndex(ViewIndexDefinition.INDEX_TYPE_VIEW.getIndex());
clearIndex(ProjectMeasuresIndexDefinition.INDEX_TYPE_PROJECT_MEASURES.getIndex());
clearIndex(ComponentIndexDefinition.INDEX_TYPE_COMPONENT.getIndex());
}
use of org.sonar.db.DbSession 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();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class UsersAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
checkProjectAdmin(userSession, org.getUuid(), projectId);
PermissionQuery query = buildPermissionQuery(request, projectId);
List<UserDto> users = findUsers(dbSession, org, query);
int total = dbClient.userPermissionDao().countUsers(dbSession, org.getUuid(), query);
List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId);
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging);
writeProtobuf(usersWsResponse, request, response);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class AddProjectCreatorToTemplateAction method doHandle.
private void doHandle(AddProjectCreatorToTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
Optional<PermissionTemplateCharacteristicDto> templatePermission = dbClient.permissionTemplateCharacteristicDao().selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getId());
if (templatePermission.isPresent()) {
updateTemplatePermission(dbSession, templatePermission.get());
} else {
addTemplatePermission(dbSession, request, template);
}
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ApplyTemplateAction method doHandle.
private void doHandle(ApplyTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, newWsProjectRef(request.getProjectId(), request.getProjectKey()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
permissionTemplateService.apply(dbSession, template, Collections.singletonList(project));
}
}
Aggregations