Skip to content

Commit 85ff6e7

Browse files
committed
merge fixes
1 parent 6387e45 commit 85ff6e7

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/api/Access.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public BundleDownloadInstance datafileBundle(@Context ContainerRequestContext cr
146146

147147
// This will throw a ForbiddenException if access isn't authorized:
148148
checkAuthorization(req.getUser(), df);
149-
if (checkGuestbookRequiredResponse(crc, uriInfo, df, gbrids)) {
149+
if (checkGuestbookRequiredResponse(req.getUser(), uriInfo, df, gbrids)) {
150150
throw new BadRequestException(BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", getGuestbookIdFromDatafile(df)));
151151
}
152152

@@ -251,7 +251,7 @@ public Response datafile(@Context ContainerRequestContext crc, @PathParam("fileI
251251

252252
// This will throw a ForbiddenException if access isn't authorized:
253253
checkAuthorization(req.getUser(), df);
254-
if (checkGuestbookRequiredResponse(crc, uriInfo, df, gbrids)) {
254+
if (checkGuestbookRequiredResponse(req.getUser(), uriInfo, df, gbrids)) {
255255
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("access.api.download.failure.guestbookResponseMissing", getGuestbookIdFromDatafile(df)));
256256
}
257257

@@ -428,7 +428,7 @@ private Response processDatafileWithGuestbookResponse(ContainerRequestContext cr
428428
// since all files must be in the same Dataset we can generate a Guestbook Response once and just replace the DataFile for each file in the list
429429
DataFile firstDatafile = datafilesMap.values().size() > 0 ? (DataFile) Arrays.stream(datafilesMap.values().toArray()).findFirst().get() : null;
430430
GuestbookResponse gbr = getGuestbookResponseFromBody(firstDatafile, GuestbookResponse.DOWNLOAD, jsonBody, user);
431-
boolean guestbookResponseRequired = checkGuestbookRequiredResponse(crc, uriInfo, firstDatafile, null);
431+
boolean guestbookResponseRequired = checkGuestbookRequiredResponse(user, uriInfo, firstDatafile, null);
432432
for (DataFile df : datafilesMap.values()) {
433433
displayName = df.getDisplayName();
434434
datasetId = df.getOwner().getId();
@@ -458,12 +458,13 @@ private Response processDatafileWithGuestbookResponse(ContainerRequestContext cr
458458
}
459459

460460
private Map<Long, DataFile> getDatafilesMap(ContainerRequestContext crc, String fileIds) {
461+
DataverseRequest req = createDataverseRequest(getRequestUser(crc));
461462
String fileIdParams[] = getFileIdsCSV(fileIds);
462463
Map<Long, DataFile> datafilesMap = new HashMap<>();
463464
// Get and validate all the DataFiles first
464465
if (fileIdParams != null && fileIdParams.length > 0) {
465466
for (int i = 0; i < fileIdParams.length; i++) {
466-
DataFile df = findDataFileUserCanSeeOrDieWrapper(fileIdParams[i]);
467+
DataFile df = findDataFileUserCanSeeOrDieWrapper(fileIdParams[i], req);
467468

468469
if (df.isHarvested()) {
469470
String errorMessage = "Datafile " + df.getId() + " is a harvested file that cannot be accessed in this Dataverse";
@@ -472,7 +473,7 @@ private Map<Long, DataFile> getDatafilesMap(ContainerRequestContext crc, String
472473
}
473474

474475
// This will throw a ForbiddenException if access isn't authorized:
475-
checkAuthorization(crc, df);
476+
checkAuthorization(req.getUser(), df);
476477

477478
datafilesMap.put(df.getId(), df);
478479
}
@@ -1015,10 +1016,10 @@ private Response downloadDatafiles(ContainerRequestContext crc, String body, boo
10151016
Set<Long> datasetIds = new HashSet<>();
10161017
Boolean guestbookResponseRequired = null;
10171018
for (int i = 0; i < fileIdParams.length; i++) {
1018-
DataFile df = findDataFileUserCanSeeOrDieWrapper(fileIdParams[i]);
1019+
DataFile df = findDataFileUserCanSeeOrDieWrapper(fileIdParams[i], req);
10191020
if (guestbookResponseRequired == null) {
10201021
// Only need to check this on the first file
1021-
guestbookResponseRequired = checkGuestbookRequiredResponse(crc, uriInfo, df, gbrids);
1022+
guestbookResponseRequired = checkGuestbookRequiredResponse(user, uriInfo, df, gbrids);
10221023
}
10231024
datafilesMap.put(df.getId(), df);
10241025
datasetIds.add(df.getOwner() != null ? df.getOwner().getId() : 0L);
@@ -1900,12 +1901,12 @@ public Response getUserPermissionsOnFile(@Context ContainerRequestContext crc, @
19001901
return ok(jsonObjectBuilder);
19011902
}
19021903

1903-
private boolean checkGuestbookRequiredResponse(ContainerRequestContext crc, UriInfo uriInfo, DataFile df, String gbrids) throws WebApplicationException {
1904+
private boolean checkGuestbookRequiredResponse(User user, UriInfo uriInfo, DataFile df, String gbrids) throws WebApplicationException {
19041905
// Check if guestbook response is required
19051906
boolean required = df.getOwner().hasEnabledGuestbook();
19061907
boolean wasWrittenInPost = false;
19071908
if (required) {
1908-
User requestor = getRequestor(crc);
1909+
User requestor = getRequestor(user);
19091910
if (requestor instanceof AuthenticatedUser && permissionService.userOn(requestor, df.getOwner()).has(Permission.EditDataset)) {
19101911
required = false;
19111912
}

0 commit comments

Comments
 (0)