use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class SearchTemplatesDataLoader method load.
public SearchTemplatesData load(DbSession dbSession, SearchTemplatesWsRequest request) {
SearchTemplatesData.Builder data = builder();
List<PermissionTemplateDto> templates = searchTemplates(dbSession, request);
List<Long> templateIds = Lists.transform(templates, PermissionTemplateDto::getId);
DefaultTemplates defaultTemplates = checkFoundWithOptional(dbClient.organizationDao().getDefaultTemplates(dbSession, request.getOrganizationUuid()), "No Default templates for organization with uuid '%s'", request.getOrganizationUuid());
ResolvedDefaultTemplates resolvedDefaultTemplates = defaultTemplatesResolver.resolve(defaultTemplates);
data.templates(templates).defaultTemplates(resolvedDefaultTemplates).userCountByTemplateIdAndPermission(userCountByTemplateIdAndPermission(dbSession, templateIds)).groupCountByTemplateIdAndPermission(groupCountByTemplateIdAndPermission(dbSession, templateIds)).withProjectCreatorByTemplateIdAndPermission(withProjectCreatorsByTemplateIdAndPermission(dbSession, templateIds));
return data.build();
}
use of org.sonar.db.permission.template.PermissionTemplateDto 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.permission.template.PermissionTemplateDto 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);
}
}
use of org.sonar.db.permission.template.PermissionTemplateDto 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.permission.template.PermissionTemplateDto 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