Search in sources :

Example 1 with PermissionChange

use of org.sonar.server.permission.PermissionChange in project sonarqube by SonarSource.

the class AddGroupAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        GroupIdOrAnyone group = support.findGroup(dbSession, request);
        Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
        checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId);
        PermissionChange change = new GroupPermissionChange(PermissionChange.Operation.ADD, request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), group);
        permissionUpdater.apply(dbSession, asList(change));
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionChange(org.sonar.server.permission.PermissionChange) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange) ProjectId(org.sonar.server.permission.ProjectId) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange)

Example 2 with PermissionChange

use of org.sonar.server.permission.PermissionChange in project sonarqube by SonarSource.

the class RemoveUserAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserId user = support.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
        Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
        OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
        checkProjectAdmin(userSession, org.getUuid(), projectId);
        PermissionChange change = new UserPermissionChange(PermissionChange.Operation.REMOVE, org.getUuid(), request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), user);
        permissionUpdater.apply(dbSession, asList(change));
        response.noContent();
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserId(org.sonar.server.permission.UserId) PermissionChange(org.sonar.server.permission.PermissionChange) UserPermissionChange(org.sonar.server.permission.UserPermissionChange) ProjectId(org.sonar.server.permission.ProjectId) UserPermissionChange(org.sonar.server.permission.UserPermissionChange) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 3 with PermissionChange

use of org.sonar.server.permission.PermissionChange in project sonarqube by SonarSource.

the class AddUserAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserId user = support.findUser(dbSession, request.mandatoryParam(PARAM_USER_LOGIN));
        Optional<ComponentDto> project = support.findProject(dbSession, request);
        String organizationKey = request.param(PARAM_ORGANIZATION);
        checkArgument(!project.isPresent() || organizationKey == null, "Organization must not be set when project is set.");
        OrganizationDto org = project.map(dto -> dbClient.organizationDao().selectByUuid(dbSession, dto.getOrganizationUuid())).orElseGet(() -> Optional.ofNullable(support.findOrganization(dbSession, organizationKey))).orElseThrow(() -> new NotFoundException(String.format("Organization with key '%s' not found", organizationKey)));
        Optional<ProjectId> projectId = project.map(ProjectId::new);
        checkProjectAdmin(userSession, org.getUuid(), projectId);
        PermissionChange change = new UserPermissionChange(PermissionChange.Operation.ADD, org.getUuid(), request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), user);
        permissionUpdater.apply(dbSession, asList(change));
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) UserId(org.sonar.server.permission.UserId) PermissionChange(org.sonar.server.permission.PermissionChange) UserPermissionChange(org.sonar.server.permission.UserPermissionChange) ComponentDto(org.sonar.db.component.ComponentDto) ProjectId(org.sonar.server.permission.ProjectId) NotFoundException(org.sonar.server.exceptions.NotFoundException) UserPermissionChange(org.sonar.server.permission.UserPermissionChange) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 4 with PermissionChange

use of org.sonar.server.permission.PermissionChange in project sonarqube by SonarSource.

the class RemoveGroupAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        GroupIdOrAnyone group = support.findGroup(dbSession, request);
        Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
        checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId);
        PermissionChange change = new GroupPermissionChange(PermissionChange.Operation.REMOVE, request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), group);
        permissionUpdater.apply(dbSession, asList(change));
    }
    response.noContent();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionChange(org.sonar.server.permission.PermissionChange) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange) ProjectId(org.sonar.server.permission.ProjectId) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange)

Aggregations

DbSession (org.sonar.db.DbSession)4 PermissionChange (org.sonar.server.permission.PermissionChange)4 ProjectId (org.sonar.server.permission.ProjectId)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 GroupPermissionChange (org.sonar.server.permission.GroupPermissionChange)2 UserId (org.sonar.server.permission.UserId)2 UserPermissionChange (org.sonar.server.permission.UserPermissionChange)2 GroupIdOrAnyone (org.sonar.server.usergroups.ws.GroupIdOrAnyone)2 ComponentDto (org.sonar.db.component.ComponentDto)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1