Skip to content

Commit fc1e2b7

Browse files
committed
updates to dataset, collection, and access apis with new findXUSerCanSeeOrDie methods
1 parent 774fae4 commit fc1e2b7

4 files changed

Lines changed: 113 additions & 131 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,20 @@ protected Dataverse findDataverseOrDie( String dvIdtf ) throws WrappedResponse {
370370
}
371371
return dv;
372372
}
373+
/** Find a dataverse but filter according to the visibility from the locallyFAIRRoleAssignments
374+
*
375+
* @param dvIdtf - the dataverse identifier
376+
* @param req - the DataverseRequest
377+
* @return the dataverse if found and visible, otherwise throws WrappedResponse
378+
* @throws WrappedResponse if dataverse is not found (in findDatasetOrDie()) or not visible
379+
*/
380+
protected Dataverse findDataverseUserCanSeeOrDie(String dvIdtf, DataverseRequest req) throws WrappedResponse {
381+
Dataverse dataverse = findDataverseOrDie(dvIdtf);
382+
if (dataverse.isLocallyFAIR() && !permissionSvc.hasLocallyFAIRAccess(req, dataverse)) {
383+
throw new WrappedResponse(error( Response.Status.NOT_FOUND, "Can't find dataverse with identifier='" + dvIdtf + "'"));
384+
}
385+
return dataverse;
386+
}
373387

374388
protected Template findTemplateOrDie(Long templateId, Dataverse dataverse) throws WrappedResponse {
375389

@@ -554,6 +568,21 @@ protected DataFile findDataFileOrDie(String id) throws WrappedResponse {
554568
}
555569
}
556570
}
571+
572+
/** Find a datafile but filter according to the visibility from the locallyFAIRRoleAssignments
573+
*
574+
* @param id - the datafile identifier
575+
* @param req - the DataverseRequest
576+
* @return the datafile if found and visible, otherwise throws WrappedResponse
577+
* @throws WrappedResponse if datafile is not found (in findDatasetOrDie()) or not visible
578+
*/
579+
protected DataFile findDataFileUserCanSeeOrDie(String id, DataverseRequest req) throws WrappedResponse {
580+
DataFile dataFile = findDataFileOrDie(id);
581+
if (dataFile.isLocallyFAIR() && !permissionSvc.hasLocallyFAIRAccess(req, dataFile)) {
582+
throw new WrappedResponse(notFound(BundleUtil.getStringFromBundle("find.datafile.error.datafile.not.found.id", Collections.singletonList(id))));
583+
}
584+
return dataFile;
585+
}
557586

558587
protected DataverseRole findRoleOrDie(String id) throws WrappedResponse {
559588
DataverseRole role;

0 commit comments

Comments
 (0)