Search in sources :

Example 1 with GroupPermissionChange

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

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

Example 3 with GroupPermissionChange

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

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

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

GroupPermissionChange (org.sonar.server.permission.GroupPermissionChange)6 ProjectId (org.sonar.server.permission.ProjectId)6 PermissionUpdater (org.sonar.server.permission.PermissionUpdater)4 DbSession (org.sonar.db.DbSession)2 PermissionChange (org.sonar.server.permission.PermissionChange)2 GroupIdOrAnyone (org.sonar.server.usergroups.ws.GroupIdOrAnyone)2 ComponentDao (org.sonar.db.component.ComponentDao)1 ComponentDto (org.sonar.db.component.ComponentDto)1 OrganizationDao (org.sonar.db.organization.OrganizationDao)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1