Search in sources :

Example 51 with PermissionTemplateDto

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;
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Date(java.util.Date)

Example 52 with PermissionTemplateDto

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()));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Date(java.util.Date) DefaultTemplates(org.sonar.db.organization.DefaultTemplates)

Example 53 with PermissionTemplateDto

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()));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto)

Example 54 with PermissionTemplateDto

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto)

Example 55 with PermissionTemplateDto

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;
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Date(java.util.Date)

Aggregations

PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)97 Test (org.junit.Test)63 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)42 OrganizationDto (org.sonar.db.organization.OrganizationDto)33 GroupDto (org.sonar.db.user.GroupDto)17 DbSession (org.sonar.db.DbSession)16 UserDto (org.sonar.db.user.UserDto)15 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 InputStream (java.io.InputStream)13 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)12 DefaultTemplates (org.sonar.db.organization.DefaultTemplates)10 PermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateUserDto)9 WsPermissions (org.sonarqube.ws.WsPermissions)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)8 PermissionTemplateTesting.newPermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto)7 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)7 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 ComponentDto (org.sonar.db.component.ComponentDto)6 Date (java.util.Date)5