Search in sources :

Example 6 with ProjectId

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

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

the class GroupsAction 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);
        // TODO validatePermission(groupsRequest.getPermission(), wsProjectRef);
        List<GroupDto> groups = findGroups(dbSession, org, query);
        int total = dbClient.groupPermissionDao().countGroupsByQuery(dbSession, org.getUuid(), query);
        List<GroupPermissionDto> groupsWithPermission = findGroupPermissions(dbSession, org, groups, projectId);
        Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
        WsGroupsResponse groupsResponse = buildResponse(groups, groupsWithPermission, paging);
        writeProtobuf(groupsResponse, request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) ProjectId(org.sonar.server.permission.ProjectId) GroupDto(org.sonar.db.user.GroupDto) WsGroupsResponse(org.sonarqube.ws.WsPermissions.WsGroupsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) PermissionQuery(org.sonar.db.permission.PermissionQuery) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 8 with ProjectId

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

Example 9 with ProjectId

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

the class IssueServiceMediumTest method newProject.

private ComponentDto newProject() {
    OrganizationDto organization = OrganizationTesting.newOrganizationDto();
    tester.get(OrganizationDao.class).insert(session, organization);
    ComponentDto project = ComponentTesting.newProjectDto(organization);
    tester.get(ComponentDao.class).insert(session, project);
    userSessionRule.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
    session.commit();
    // project can be seen by group "anyone"
    // TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone"
    // for each organization
    GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(project), GroupIdOrAnyone.forAnyone(organization.getUuid()));
    tester.get(PermissionUpdater.class).apply(session, asList(permissionChange));
    userSessionRule.logIn();
    return project;
}
Also used : PermissionUpdater(org.sonar.server.permission.PermissionUpdater) ComponentDto(org.sonar.db.component.ComponentDto) ProjectId(org.sonar.server.permission.ProjectId) OrganizationDao(org.sonar.db.organization.OrganizationDao) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange) OrganizationDto(org.sonar.db.organization.OrganizationDto) ComponentDao(org.sonar.db.component.ComponentDao)

Example 10 with ProjectId

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

the class SearchActionMediumTest method setDefaultProjectPermission.

private void setDefaultProjectPermission(ComponentDto project) {
    // project can be seen by anyone and by code viewer
    userSessionRule.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
    // TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone"
    // for each organization
    GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid()));
    tester.get(PermissionUpdater.class).apply(session, asList(permissionChange));
}
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