use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class CreateTemplateAction method insertTemplate.
private PermissionTemplateDto insertTemplate(DbSession dbSession, OrganizationDto org, CreateTemplateWsRequest request) {
Date now = new Date(system.now());
PermissionTemplateDto template = dbClient.permissionTemplateDao().insert(dbSession, new PermissionTemplateDto().setUuid(Uuids.create()).setOrganizationUuid(org.getUuid()).setName(request.getName()).setDescription(request.getDescription()).setKeyPattern(request.getProjectKeyPattern()).setCreatedAt(now).setUpdatedAt(now));
dbSession.commit();
return template;
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class OrganizationCreationImpl method insertDefaultTemplate.
private void insertDefaultTemplate(DbSession dbSession, OrganizationDto organizationDto, GroupDto group) {
Date now = new Date(system2.now());
PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().insert(dbSession, new PermissionTemplateDto().setOrganizationUuid(organizationDto.getUuid()).setUuid(uuidFactory.create()).setName(PERM_TEMPLATE_NAME).setDescription(format(PERM_TEMPLATE_DESCRIPTION_PATTERN, organizationDto.getName())).setCreatedAt(now).setUpdatedAt(now));
insertGroupPermission(dbSession, permissionTemplateDto, UserRole.ADMIN, group);
insertGroupPermission(dbSession, permissionTemplateDto, UserRole.ISSUE_ADMIN, group);
insertGroupPermission(dbSession, permissionTemplateDto, GlobalPermissions.SCAN_EXECUTION, group);
insertGroupPermission(dbSession, permissionTemplateDto, UserRole.USER, null);
insertGroupPermission(dbSession, permissionTemplateDto, UserRole.CODEVIEWER, null);
dbClient.organizationDao().setDefaultTemplates(dbSession, organizationDto.getUuid(), new DefaultTemplates().setProjectUuid(permissionTemplateDto.getUuid()));
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class PermissionTemplateService method applyDefault.
/**
* Apply the default permission template to project. The project can already exist (so it has permissions) or
* can be provisioned (so has no permissions yet).
* @param projectCreatorUserId id of the user who creates the project, only if project is provisioned. He will
*/
public void applyDefault(DbSession dbSession, String organizationUuid, ComponentDto component, @Nullable Integer projectCreatorUserId) {
PermissionTemplateDto template = findTemplate(dbSession, organizationUuid, component);
checkArgument(template != null, "Cannot retrieve default permission template");
copyPermissions(dbSession, template, component, projectCreatorUserId);
dbSession.commit();
indexProjectPermissions(dbSession, asList(component.uuid()));
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class UpdateTemplateAction method doHandle.
private UpdateTemplateWsResponse doHandle(UpdateTemplateWsRequest request) {
String uuid = request.getId();
String nameParam = request.getName();
String descriptionParam = request.getDescription();
String projectPatternParam = request.getProjectKeyPattern();
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto templateToUpdate = getAndBuildTemplateToUpdate(dbSession, uuid, nameParam, descriptionParam, projectPatternParam);
checkGlobalAdmin(userSession, templateToUpdate.getOrganizationUuid());
validateTemplate(dbSession, templateToUpdate);
PermissionTemplateDto updatedTemplate = updateTemplate(dbSession, templateToUpdate);
dbSession.commit();
return buildResponse(updatedTemplate);
}
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class UpdateTemplateAction method getAndBuildTemplateToUpdate.
private PermissionTemplateDto getAndBuildTemplateToUpdate(DbSession dbSession, String uuid, @Nullable String newName, @Nullable String newDescription, @Nullable String newProjectKeyPattern) {
PermissionTemplateDto templateToUpdate = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(uuid, null, null));
templateToUpdate.setName(firstNonNull(newName, templateToUpdate.getName()));
templateToUpdate.setDescription(firstNonNull(newDescription, templateToUpdate.getDescription()));
templateToUpdate.setKeyPattern(firstNonNull(newProjectKeyPattern, templateToUpdate.getKeyPattern()));
templateToUpdate.setUpdatedAt(new Date(system.now()));
return templateToUpdate;
}
Aggregations