Search in sources :

Example 6 with PermissionTemplateDto

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();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) ResolvedDefaultTemplates(org.sonar.server.permission.ws.template.DefaultTemplatesResolver.ResolvedDefaultTemplates) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) ResolvedDefaultTemplates(org.sonar.server.permission.ws.template.DefaultTemplatesResolver.ResolvedDefaultTemplates)

Example 7 with PermissionTemplateDto

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

Example 8 with PermissionTemplateDto

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UsersWsResponse(org.sonarqube.ws.WsPermissions.UsersWsResponse) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) Paging(org.sonar.api.utils.Paging) UserDto(org.sonar.db.user.UserDto) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) WsPermissions(org.sonarqube.ws.WsPermissions) PermissionQuery(org.sonar.db.permission.PermissionQuery)

Example 9 with PermissionTemplateDto

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

Example 10 with PermissionTemplateDto

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

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