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