use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class RemoveUserFromTemplateAction method doHandle.
private void doHandle(RemoveUserFromTemplateWsRequest request) {
String permission = request.getPermission();
String userLogin = request.getLogin();
try (DbSession dbSession = dbClient.openSession(false)) {
validateProjectPermission(permission);
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
UserId user = wsSupport.findUser(dbSession, userLogin);
dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getId(), user.getId(), permission);
dbSession.commit();
}
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class TemplateGroupsAction 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 = buildPermissionQuery(wsRequest);
int total = dbClient.permissionTemplateDao().countGroupNamesByQueryAndTemplate(dbSession, query, template.getOrganizationUuid(), template.getId());
Paging paging = Paging.forPageIndex(wsRequest.mandatoryParamAsInt(PAGE)).withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)).andTotal(total);
List<GroupDto> groups = findGroups(dbSession, query, template);
List<PermissionTemplateGroupDto> groupPermissions = findGroupPermissions(dbSession, groups, template);
WsPermissions.WsGroupsResponse groupsResponse = buildResponse(groups, groupPermissions, paging);
writeProtobuf(groupsResponse, wsRequest, wsResponse);
}
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class AddUserToTemplateAction method doHandle.
private void doHandle(AddUserToTemplateWsRequest request) {
String permission = request.getPermission();
String userLogin = request.getLogin();
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
UserId user = wsSupport.findUser(dbSession, userLogin);
if (!isUserAlreadyAdded(dbSession, template.getId(), userLogin, permission)) {
dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getId(), user.getId(), permission);
dbSession.commit();
}
}
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class CreateTemplateAction method doHandle.
private CreateTemplateWsResponse doHandle(CreateTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto org = wsSupport.findOrganization(dbSession, request.getOrganizationKey());
checkGlobalAdmin(userSession, org.getUuid());
validateTemplateNameForCreation(dbSession, org, request.getName());
validateProjectPattern(request.getProjectKeyPattern());
PermissionTemplateDto permissionTemplate = insertTemplate(dbSession, org, request);
return buildResponse(permissionTemplate);
}
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class CreateTemplateAction method validateTemplateNameForCreation.
private void validateTemplateNameForCreation(DbSession dbSession, OrganizationDto org, String name) {
validateTemplateNameFormat(name);
PermissionTemplateDto permissionTemplateWithSameName = dbClient.permissionTemplateDao().selectByName(dbSession, org.getUuid(), name);
checkRequest(permissionTemplateWithSameName == null, format(MSG_TEMPLATE_WITH_SAME_NAME, name));
}
Aggregations