Skip to content

Commit 2039ae0

Browse files
committed
refactored LF check in dataset page
1 parent 8cfa31b commit 2039ae0

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/main/java/edu/harvard/iq/dataverse/DatasetPage.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,8 +2112,15 @@ private String init(boolean initFull) {
21122112
}
21132113

21142114
// Check permisisons
2115-
if (!(workingVersion.isReleased() || workingVersion.isDeaccessioned()) && !this.canViewUnpublishedDataset()) {
2116-
return permissionsWrapper.notAuthorized();
2115+
Set<String> locallyFAIRraIds = dataset.getOwner().getLocallyFAIRRoleAssigneeIdentifiers();
2116+
boolean releasedAndCanView = workingVersion.isReleased() && locallyFAIRraIds.isEmpty() || permissionsWrapper
2117+
.hasLocallyFAIRAccess(dvRequestService.getDataverseRequest(), locallyFAIRraIds);
2118+
if (!(releasedAndCanView || workingVersion.isDeaccessioned()) && !this.canViewUnpublishedDataset()) {
2119+
if (locallyFAIRraIds.isEmpty()) {
2120+
return permissionsWrapper.notAuthorized();
2121+
} else {
2122+
return permissionsWrapper.notFound();
2123+
}
21172124
}
21182125

21192126
if (retrieveDatasetVersionResponse != null && !retrieveDatasetVersionResponse.wasRequestedVersionRetrieved()) {

src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,5 +1070,36 @@ public List<RoleAssignment> getEffectiveRoleAssignments(AuthenticatedUser user,
10701070
return Stream.concat(directAssignments, groupAssignments)
10711071
.collect(Collectors.toList());
10721072
}
1073+
1074+
/**
1075+
* Determines if a user can view a dataset version based on its release status
1076+
* and the supplied Locally FAIR role assignees.
1077+
*
1078+
* @param DataversRequest The request containing the user and Ip info (for IPgroups)
1079+
* @param Set<String> locallyFairAssignees a non-null but possibly empty set of locally FAIR role assignees
1080+
* @return true if the user has locally FAIR access
1081+
*/
1082+
public boolean isALocallyFAIRAssignee(DataverseRequest req, Set<String> locallyFairAssignees) {
1083+
1084+
// If no locally FAIR restrictions, it's publicly viewable
1085+
if (locallyFairAssignees.isEmpty()) {
1086+
return false;
1087+
}
1088+
1089+
// Check if user is in the locally FAIR assignee list
1090+
Set<RoleAssignee> userAndGroups = new HashSet<>(groupService.groupsFor(req));
1091+
User user = req.getUser();
1092+
if (user.isAuthenticated()) {
1093+
userAndGroups.add(user);
1094+
}
1095+
1096+
for (RoleAssignee ra : userAndGroups) {
1097+
if (locallyFairAssignees.contains(ra.getIdentifier())) {
1098+
return true;
1099+
}
1100+
}
1101+
1102+
return false;
1103+
}
10731104
}
10741105

src/main/java/edu/harvard/iq/dataverse/PermissionsWrapper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.harvard.iq.dataverse.engine.command.impl.*;
1414
import java.util.HashMap;
1515
import java.util.Map;
16+
import java.util.Set;
1617
import java.util.logging.Logger;
1718
import jakarta.ejb.EJB;
1819
import jakarta.faces.view.ViewScoped;
@@ -55,6 +56,7 @@ public class PermissionsWrapper implements java.io.Serializable {
5556
private final Map<Long, Boolean> fileDownloadPermissionMap = new HashMap<>(); // { DvObject.id : Boolean }
5657
private final Map<String, Boolean> datasetPermissionMap = new HashMap<>(); // { Permission human_name : Boolean }
5758

59+
Boolean hasLocallyFAIRAccess;
5860
/**
5961
* Check if the current Dataset can Issue Commands
6062
*
@@ -297,4 +299,12 @@ public String notAuthorized(){
297299
public String notFound() {
298300
return navigationWrapper.notFound();
299301
}
302+
303+
// The locallyFAIRraIds should not change within a given view (they are set in the parent Dataverse of whatever object the view is for)
304+
public boolean hasLocallyFAIRAccess(DataverseRequest req, Set<String> locallyFAIRraIds) {
305+
if(hasLocallyFAIRAccess == null ) {
306+
hasLocallyFAIRAccess = permissionService.isALocallyFAIRAssignee(req, locallyFAIRraIds);
307+
}
308+
return hasLocallyFAIRAccess;
309+
}
300310
}

0 commit comments

Comments
 (0)