Search in sources :

Example 1 with ProjectId

use of org.sonar.server.permission.ProjectId 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 ProjectId

use of org.sonar.server.permission.ProjectId 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 ProjectId

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

the class SearchProjectPermissionsAction method checkAuthorized.

private void checkAuthorized(DbSession dbSession, SearchProjectPermissionsWsRequest request) {
    com.google.common.base.Optional<ProjectWsRef> projectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
    if (projectRef.isPresent()) {
        ComponentDto project = wsSupport.getRootComponentOrModule(dbSession, projectRef.get());
        PermissionPrivilegeChecker.checkProjectAdmin(userSession, project.getOrganizationUuid(), Optional.of(new ProjectId(project)));
    } else {
        userSession.checkLoggedIn().checkIsSystemAdministrator();
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ProjectId(org.sonar.server.permission.ProjectId)

Example 4 with ProjectId

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

the class UsersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
        Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
        checkProjectAdmin(userSession, org.getUuid(), projectId);
        PermissionQuery query = buildPermissionQuery(request, projectId);
        List<UserDto> users = findUsers(dbSession, org, query);
        int total = dbClient.userPermissionDao().countUsers(dbSession, org.getUuid(), query);
        List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId);
        Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
        UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging);
        writeProtobuf(usersWsResponse, request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) Paging(org.sonar.api.utils.Paging) ProjectId(org.sonar.server.permission.ProjectId) UserPermissionDto(org.sonar.db.permission.UserPermissionDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) PermissionQuery(org.sonar.db.permission.PermissionQuery) UsersWsResponse(org.sonarqube.ws.WsPermissions.UsersWsResponse)

Example 5 with ProjectId

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

the class SearchActionMediumTest method setProjectPermission.

private void setProjectPermission(ComponentDto project, String... permissions) {
    // project can be seen by anyone and by code viewer
    userSessionRule.logIn("admin");
    Arrays.stream(permissions).forEach(permission -> userSessionRule.addProjectUuidPermissions(permission, project.uuid()));
    tester.get(PermissionUpdater.class).apply(session, Arrays.stream(permissions).map(permission -> new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid()))).collect(Collectors.toList()));
}
Also used : PermissionUpdater(org.sonar.server.permission.PermissionUpdater) ProjectId(org.sonar.server.permission.ProjectId) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange)

Aggregations

ProjectId (org.sonar.server.permission.ProjectId)11 DbSession (org.sonar.db.DbSession)6 GroupPermissionChange (org.sonar.server.permission.GroupPermissionChange)6 OrganizationDto (org.sonar.db.organization.OrganizationDto)5 PermissionChange (org.sonar.server.permission.PermissionChange)4 PermissionUpdater (org.sonar.server.permission.PermissionUpdater)4 ComponentDto (org.sonar.db.component.ComponentDto)3 Paging (org.sonar.api.utils.Paging)2 PermissionQuery (org.sonar.db.permission.PermissionQuery)2 UserId (org.sonar.server.permission.UserId)2 UserPermissionChange (org.sonar.server.permission.UserPermissionChange)2 GroupIdOrAnyone (org.sonar.server.usergroups.ws.GroupIdOrAnyone)2 ComponentDao (org.sonar.db.component.ComponentDao)1 OrganizationDao (org.sonar.db.organization.OrganizationDao)1 GroupPermissionDto (org.sonar.db.permission.GroupPermissionDto)1 UserPermissionDto (org.sonar.db.permission.UserPermissionDto)1 GroupDto (org.sonar.db.user.GroupDto)1 UserDto (org.sonar.db.user.UserDto)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 UsersWsResponse (org.sonarqube.ws.WsPermissions.UsersWsResponse)1