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();
}
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);
}
}
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();
}
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;
}
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));
}
Aggregations