use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class DeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn().checkIsSystemAdministrator();
try (DbSession dbSession = dbClient.openSession(false)) {
List<Integer> ids = loadIds(dbSession, request);
dbClient.metricDao().disableCustomByIds(dbSession, ids);
dbClient.customMeasureDao().deleteByMetricIds(dbSession, ids);
dbSession.commit();
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class AutoDbMigration method installH2.
@VisibleForTesting
void installH2() {
Connection connection = null;
try (DbSession session = dbClient.openSession(false)) {
connection = session.getConnection();
createH2Schema(connection, dbClient.getDatabase().getDialect().getId());
} finally {
DbUtils.closeQuietly(connection);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class RemoveGroupFromTemplateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
String permission = request.mandatoryParam(PARAM_PERMISSION);
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.fromRequest(request));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
GroupIdOrAnyone groupId = wsSupport.findGroup(dbSession, request);
checkArgument(groupId.getOrganizationUuid().equals(template.getOrganizationUuid()), "Group and template are on different organizations");
dbClient.permissionTemplateDao().deleteGroupPermission(dbSession, template.getId(), groupId.getId(), permission);
dbSession.commit();
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class SetDefaultTemplateAction method doHandle.
private void doHandle(SetDefaultTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
String qualifier = request.getQualifier();
PermissionTemplateDto template = findTemplate(dbSession, request);
checkGlobalAdmin(userSession, template.getOrganizationUuid());
validateQualifier(qualifier, resourceTypes);
setDefaultTemplateUuid(dbSession, template, qualifier);
dbSession.commit();
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class TemplateUsersAction method handle.
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
WsTemplateRef templateRef = WsTemplateRef.fromRequest(wsRequest);
PermissionTemplateDto template = support.findTemplate(dbSession, templateRef);
checkGlobalAdmin(userSession, template.getOrganizationUuid());
PermissionQuery query = buildQuery(wsRequest, template);
int total = dbClient.permissionTemplateDao().countUserLoginsByQueryAndTemplate(dbSession, query, template.getId());
Paging paging = Paging.forPageIndex(wsRequest.mandatoryParamAsInt(PAGE)).withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)).andTotal(total);
List<UserDto> users = findUsers(dbSession, query, template);
List<PermissionTemplateUserDto> permissionTemplateUsers = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateIdAndUserLogins(dbSession, template.getId(), users.stream().map(UserDto::getLogin).collect(Collectors.toList()));
WsPermissions.UsersWsResponse templateUsersResponse = buildResponse(users, permissionTemplateUsers, paging);
writeProtobuf(templateUsersResponse, wsRequest, wsResponse);
}
}
Aggregations