Skip to content

Commit f8002ff

Browse files
committed
add userCanSee to file GETs
1 parent fc1e2b7 commit f8002ff

1 file changed

Lines changed: 35 additions & 35 deletions

File tree

  • src/main/java/edu/harvard/iq/dataverse/api

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ private Response getFileDataResponse(final DataverseRequest req,
573573
boolean returnOwners,
574574
UriInfo uriInfo,
575575
HttpHeaders headers) throws WrappedResponse {
576-
final DataFile dataFile = execCommand(new GetDataFileCommand(req, findDataFileOrDie(fileIdOrPersistentId)));
576+
final DataFile dataFile = execCommand(new GetDataFileCommand(req, findDataFileUserCanSeeOrDie(fileIdOrPersistentId, req)));
577577
FileMetadata fileMetadata = execCommand(handleVersion(datasetVersionId, new Datasets.DsVersionHandler<>() {
578578
@Override
579579
public Command<FileMetadata> handleLatest() {
@@ -626,15 +626,15 @@ public Response getFileMetadata(@Context ContainerRequestContext crc, @PathParam
626626
}
627627
final DataFile df;
628628
try {
629-
df = execCommand(new GetDataFileCommand(req, findDataFileOrDie(fileIdOrPersistentId)));
629+
df = execCommand(new GetDataFileCommand(req, findDataFileUserCanSeeOrDie(fileIdOrPersistentId, req)));
630630
} catch (Exception e) {
631631
return error(BAD_REQUEST, "Error attempting get the requested data file.");
632632
}
633633
FileMetadata fm;
634634

635635
if(null != getDraft && getDraft) {
636636
try {
637-
fm = execCommand(new GetDraftFileMetadataIfAvailableCommand(req, findDataFileOrDie(fileIdOrPersistentId)));
637+
fm = execCommand(new GetDraftFileMetadataIfAvailableCommand(req, findDataFileUserCanSeeOrDie(fileIdOrPersistentId, req)));
638638
} catch (WrappedResponse w) {
639639
return error(BAD_REQUEST, "An error occurred getting a draft version, you may not have permission to access unpublished data on this dataset." );
640640
}
@@ -754,37 +754,37 @@ public Response reingest(@Context ContainerRequestContext crc, @PathParam("id")
754754
}
755755

756756
boolean ingestLock = dataset.isLockedFor(DatasetLock.Reason.Ingest);
757-
757+
758758
if (ingestLock) {
759759
return error(FORBIDDEN, "Dataset already locked with an Ingest lock");
760760
}
761-
761+
762762
if (!FileUtil.canIngestAsTabular(dataFile)) {
763763
return error(BAD_REQUEST, "Tabular ingest is not supported for this file type (id: "+id+", type: "+dataFile.getContentType()+")");
764764
}
765-
765+
766766
dataFile.SetIngestScheduled();
767-
767+
768768
if (dataFile.getIngestRequest() == null) {
769769
dataFile.setIngestRequest(new IngestRequest(dataFile));
770770
}
771771

772772
dataFile.getIngestRequest().setForceTypeCheck(true);
773-
773+
774774
// update the datafile, to save the newIngest request in the database:
775775
dataFile = fileService.save(dataFile);
776-
777-
// queue the data ingest job for asynchronous execution:
776+
777+
// queue the data ingest job for asynchronous execution:
778778
String status = ingestService.startIngestJobs(dataset.getId(), new ArrayList<>(Arrays.asList(dataFile)), u);
779-
779+
780780
if (!StringUtil.isEmpty(status)) {
781-
// This most likely indicates some sort of a problem (for example,
781+
// This most likely indicates some sort of a problem (for example,
782782
// the ingest job was not put on the JMS queue because of the size
783783
// of the file). But we are still returning the OK status - because
784-
// from the point of view of the API, it's a success - we have
785-
// successfully gone through the process of trying to schedule the
784+
// from the point of view of the API, it's a success - we have
785+
// successfully gone through the process of trying to schedule the
786786
// ingest job...
787-
787+
788788
return ok(status);
789789
}
790790
return ok("Datafile " + id + " queued for ingest");
@@ -854,28 +854,28 @@ private void exportDatasetMetadata(SettingsServiceBean settingsServiceBean, Data
854854
logger.log(Level.WARNING, "Dataset publication finalization: exception while exporting:{0}", ex.getMessage());
855855
}
856856
}
857-
857+
858858
/**
859859
* API endpoint to retrieve a URL for a file-level external tool.
860-
*
860+
*
861861
* This endpoint allows clients to get a URL for accessing an external tool
862862
* that operates at the file level. The URL includes necessary authentication tokens and
863863
* parameters based on the user's permissions and the tool's configuration.
864-
*
864+
*
865865
* The endpoint accepts JSON input with optional parameters:
866866
* - preview: boolean flag to indicate if the tool should run in preview mode (suppressing header metadata like name/PID that would already be on the file page)
867867
* - locale: string specifying the locale for internationalization
868-
*
868+
*
869869
* The response includes:
870870
* - toolUrl: the URL to access the external tool
871871
* - toolName: the display name of the external tool
872872
* - fileId: the ID of the file
873873
* - preview: whether the URL is for preview mode
874-
*
874+
*
875875
* Authentication is required, and appropriate permissions are checked before generating the URL.
876876
* For restricted files (including files in draft/deaccessioned datasets, embargoed files, or
877877
* files with expired retention periods), the user must have DownloadFile permission.
878-
*
878+
*
879879
* @param crc The container request context for authentication
880880
* @param fileId The ID of the file
881881
* @param externalToolId The ID of the external tool
@@ -908,7 +908,7 @@ public Response getExternalToolUrl(@Context ContainerRequestContext crc, @PathPa
908908
return error(Response.Status.BAD_REQUEST, "Invalid JSON format in request body.");
909909
}
910910
}
911-
911+
912912
try {
913913
// Find the file
914914
DataFile dataFile;
@@ -932,13 +932,13 @@ public Response getExternalToolUrl(@Context ContainerRequestContext crc, @PathPa
932932
// Check if the tool's content type matches the file's content type
933933
String toolContentType = externalTool.getContentType();
934934
String fileContentType = dataFile.getContentType();
935-
if (toolContentType != null && !toolContentType.isEmpty() &&
935+
if (toolContentType != null && !toolContentType.isEmpty() &&
936936
!toolContentType.equals(fileContentType)) {
937-
return error(BAD_REQUEST,
938-
"External tool content type (" + toolContentType +
937+
return error(BAD_REQUEST,
938+
"External tool content type (" + toolContentType +
939939
") does not match file content type (" + fileContentType + ").");
940940
}
941-
941+
942942
if (!externalToolService.meetsRequirements(externalTool, dataFile)) {
943943
return error(BAD_REQUEST, "External tool requirements not met for this file.");
944944
}
@@ -995,8 +995,8 @@ public Response getExternalToolUrl(@Context ContainerRequestContext crc, @PathPa
995995
"An error occurred while generating the external tool URL.");
996996
}
997997
}
998-
999-
// This method provides a callback for an external tool to retrieve it's
998+
999+
// This method provides a callback for an external tool to retrieve its
10001000
// parameters/api URLs. If the request is authenticated, e.g. by it being
10011001
// signed, the api URLs will be signed. If a guest request is made, the URLs
10021002
// will be plain/unsigned.
@@ -1027,7 +1027,7 @@ public Response getExternalToolFMParams(@Context ContainerRequestContext crc, @P
10271027
eth = new ExternalToolHandler(externalTool, target.getDataFile(), apiToken, target, locale);
10281028
return ok(eth.createPostBody(eth.getParams(JsonUtil.getJsonObject(externalTool.getToolParameters())), JsonUtil.getJsonArray(externalTool.getAllowedApiCalls())));
10291029
}
1030-
1030+
10311031
@GET
10321032
@Path("fixityAlgorithm")
10331033
public Response getFixityAlgorithm() {
@@ -1039,7 +1039,7 @@ public Response getFixityAlgorithm() {
10391039
@Path("{id}/downloadCount")
10401040
public Response getFileDownloadCount(@Context ContainerRequestContext crc, @PathParam("id") String dataFileId) {
10411041
return response(req -> {
1042-
DataFile dataFile = execCommand(new GetDataFileCommand(req, findDataFileOrDie(dataFileId)));
1042+
DataFile dataFile = execCommand(new GetDataFileCommand(req, findDataFileUserCanSeeOrDie(dataFileId, req)));
10431043
return ok(guestbookResponseService.getDownloadCountByDataFileId(dataFile.getId()).toString());
10441044
}, getRequestUser(crc));
10451045
}
@@ -1049,13 +1049,13 @@ public Response getFileDownloadCount(@Context ContainerRequestContext crc, @Path
10491049
@Path("{id}/dataTables")
10501050
public Response getFileDataTables(@Context ContainerRequestContext crc, @PathParam("id") String dataFileId) {
10511051
DataFile dataFile;
1052+
DataverseRequest dataverseRequest = createDataverseRequest(getRequestUser(crc));
10521053
try {
1053-
dataFile = findDataFileOrDie(dataFileId);
1054+
dataFile = findDataFileUserCanSeeOrDie(dataFileId, dataverseRequest);
10541055
} catch (WrappedResponse e) {
10551056
return notFound("File not found for given id.");
10561057
}
10571058
if (dataFile.isRestricted() || FileUtil.isActivelyEmbargoed(dataFile)) {
1058-
DataverseRequest dataverseRequest = createDataverseRequest(getRequestUser(crc));
10591059
boolean hasPermissionToDownloadFile = permissionSvc.requestOn(dataverseRequest, dataFile).has(Permission.DownloadFile);
10601060
if (!hasPermissionToDownloadFile) {
10611061
return forbidden("Insufficient permissions to access the requested information.");
@@ -1132,7 +1132,7 @@ public Response setFileTabularTags(@Context ContainerRequestContext crc, @PathPa
11321132
@Path("{id}/hasBeenDeleted")
11331133
public Response getHasBeenDeleted(@Context ContainerRequestContext crc, @PathParam("id") String dataFileId) {
11341134
return response(req -> {
1135-
DataFile dataFile = execCommand(new GetDataFileCommand(req, findDataFileOrDie(dataFileId)));
1135+
DataFile dataFile = execCommand(new GetDataFileCommand(req, findDataFileUserCanSeeOrDie(dataFileId, req)));
11361136
return ok(dataFileServiceBean.hasBeenDeleted(dataFile));
11371137
}, getRequestUser(crc));
11381138
}
@@ -1149,7 +1149,7 @@ public Response getHasBeenDeleted(@Context ContainerRequestContext crc, @PathPar
11491149
public Response getFileCitationByVersion(@Context ContainerRequestContext crc, @PathParam("id") String fileIdOrPersistentId, @PathParam("dsVersionString") String versionNumber, @QueryParam("includeDeaccessioned") boolean includeDeaccessioned) {
11501150
try {
11511151
DataverseRequest req = createDataverseRequest(getRequestUser(crc));
1152-
final DataFile df = execCommand(new GetDataFileCommand(req, findDataFileOrDie(fileIdOrPersistentId)));
1152+
final DataFile df = execCommand(new GetDataFileCommand(req, findDataFileUserCanSeeOrDie(fileIdOrPersistentId, req)));
11531153
Dataset ds = df.getOwner();
11541154
DatasetVersion dsv = findDatasetVersionOrDie(req, versionNumber, ds, includeDeaccessioned, true);
11551155
if (dsv == null) {
@@ -1179,7 +1179,7 @@ public Response getFileVersionsList(@Context ContainerRequestContext crc,
11791179
@QueryParam("offset") Integer offset) {
11801180
try {
11811181
DataverseRequest req = createDataverseRequest(getRequestUser(crc));
1182-
final DataFile df = execCommand(new GetDataFileCommand(req, findDataFileOrDie(fileIdOrPersistentId)));
1182+
final DataFile df = execCommand(new GetDataFileCommand(req, findDataFileUserCanSeeOrDie(fileIdOrPersistentId, req)));
11831183
FileMetadata fm = df.getFileMetadata();
11841184
if (fm == null) {
11851185
return notFound(BundleUtil.getStringFromBundle("files.api.fileNotFound"));

0 commit comments

Comments
 (0)