Search in sources :

Example 46 with PermissionTemplateDto

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

Example 47 with PermissionTemplateDto

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

Example 48 with PermissionTemplateDto

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

Example 49 with PermissionTemplateDto

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

Example 50 with PermissionTemplateDto

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

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