Skip to content

Commit

Permalink
Merge pull request #6659 from IQSS/6587-deleted-files-shown-on-grant-…
Browse files Browse the repository at this point in the history
…permission

6587 deleted files shown on grant permission
  • Loading branch information
kcondon authored Feb 21, 2020
2 parents 18ef902 + c682249 commit 7227c38
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 148 deletions.
25 changes: 23 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/DataFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.NotBlank;

Expand Down Expand Up @@ -227,8 +228,24 @@ public DataFile(String contentType) {
this.fileMetadatas = new ArrayList<>();
initFileReplaceAttributes();
}



/*
Used in manage file permissions UI
to easily display those files that have been deleted in the current draft
or previous version which may have roles assigned or pending requests for access
*/

@Transient
private boolean deleted;

public boolean isDeleted() {
return deleted;
}

public void setDeleted(boolean deleted) {
this.deleted = deleted;
}

/**
* All constructors should use this method
* to initialize this file replace attributes
Expand Down Expand Up @@ -751,6 +768,10 @@ public String getDisplayName() {
return getLatestFileMetadata().getLabel();
}

public String getDirectoryLabel() {
return getLatestFileMetadata().getDirectoryLabel();
}

@Override
public String getCurrentName(){
return getLatestFileMetadata().getLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ public class ManageFilePermissionsPage implements java.io.Serializable {
Dataset dataset = new Dataset();
private final TreeMap<RoleAssignee,List<RoleAssignmentRow>> roleAssigneeMap = new TreeMap<>();
private final TreeMap<DataFile,List<RoleAssignmentRow>> fileMap = new TreeMap<>();
private final TreeMap<AuthenticatedUser,List<DataFile>> fileAccessRequestMap = new TreeMap<>();
private final TreeMap<AuthenticatedUser,List<DataFile>> fileAccessRequestMap = new TreeMap<>();
private boolean showDeleted = true;

public boolean isShowDeleted() {
return showDeleted;
}

public void setShowDeleted(boolean showDeleted) {
this.showDeleted = showDeleted;
}

public Dataset getDataset() {
return dataset;
Expand Down Expand Up @@ -130,20 +139,27 @@ private void initMaps() {
fileAccessRequestMap.clear();

for (DataFile file : dataset.getFiles()) {
// only include if the file is restricted (or it's draft version is restricted)

boolean fileIsDeleted = !((dataset.getLatestVersion().isDraft() && file.getFileMetadata().getDatasetVersion().isDraft())
|| (dataset.getLatestVersion().isReleased() && file.getFileMetadata().getDatasetVersion().equals(dataset.getLatestVersion())));
// only include if the file is restricted (or its draft version is restricted)
//Added a null check in case there are files that have no metadata records SEK
if (file.getFileMetadata() != null && (file.isRestricted() || file.getFileMetadata().isRestricted())) {
//for 6587 make sure that a file is in the current version befor adding to the fileMap SEK 2/11/2020
if (file.getFileMetadata() != null && (file.isRestricted() || file.getFileMetadata().isRestricted())
&& (!fileIsDeleted || isShowDeleted())) {
// we get the direct role assignments assigned to the file
List<RoleAssignment> ras = roleService.directRoleAssignments(file);
List<RoleAssignmentRow> raList = new ArrayList<>(ras.size());
for (RoleAssignment ra : ras) {
// for files, only show role assignments which can download
if (ra.getRole().permissions().contains(Permission.DownloadFile)) {
raList.add(new RoleAssignmentRow(ra, roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier(), true).getDisplayInfo()));
addFileToRoleAssignee(ra);
raList.add(new RoleAssignmentRow(ra, roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier(), true).getDisplayInfo(), fileIsDeleted));
addFileToRoleAssignee(ra, fileIsDeleted);
}
}

file.setDeleted(fileIsDeleted);

fileMap.put(file, raList);

// populate the file access requests map
Expand All @@ -166,15 +182,15 @@ public String getAuthProviderFriendlyName(String authProviderId){
return AuthenticationProvider.getFriendlyName(authProviderId);
}

private void addFileToRoleAssignee(RoleAssignment assignment) {
private void addFileToRoleAssignee(RoleAssignment assignment, boolean fileDeleted) {
RoleAssignee ra = roleAssigneeService.getRoleAssignee(assignment.getAssigneeIdentifier());
List<RoleAssignmentRow> assignments = roleAssigneeMap.get(ra);
if (assignments == null) {
assignments = new ArrayList<>();
roleAssigneeMap.put(ra, assignments);
}

assignments.add(new RoleAssignmentRow(assignment, ra.getDisplayInfo()));
assignments.add(new RoleAssignmentRow(assignment, ra.getDisplayInfo(), fileDeleted));
}

/*
Expand Down Expand Up @@ -299,13 +315,19 @@ public AuthenticatedUser getFileRequester() {


public void initAssignDialog(ActionEvent ae) {

showDeleted = false;
initMaps();

fileRequester = null;
selectedRoleAssignees = null;
selectedFiles.clear();
showUserGroupMessages();
}

public void initAssignDialogByFile(DataFile file) {
showDeleted = false;
initMaps();
fileRequester = null;
selectedRoleAssignees = null;
selectedFiles.clear();
Expand Down Expand Up @@ -466,11 +488,27 @@ public static class RoleAssignmentRow {

private final RoleAssigneeDisplayInfo assigneeDisplayInfo;
private final RoleAssignment ra;
//Used when a file to which there has been a role assignment added is deleted

private final boolean deleted;

public boolean isDeleted() {
return deleted;
}

public RoleAssignmentRow(RoleAssignment anRa, RoleAssigneeDisplayInfo disInf) {
this.ra = anRa;
this.assigneeDisplayInfo = disInf;
}
this.deleted = false;
}

public RoleAssignmentRow(RoleAssignment anRa, RoleAssigneeDisplayInfo disInf, boolean deleted) {

this.ra = anRa;
this.assigneeDisplayInfo = disInf;
this.deleted = deleted;

}


public RoleAssigneeDisplayInfo getAssigneeDisplayInfo() {
Expand All @@ -485,6 +523,7 @@ public DvObject getDefinitionPoint() {
public Long getId() {
return ra.getId();
}


}
}
1 change: 1 addition & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ dataverse.permissionsFiles.files.assignBtn=Assign Access
dataverse.permissionsFiles.files.invalidMsg=There are no restricted files in this dataset.
dataverse.permissionsFiles.files.requested=Requested Files
dataverse.permissionsFiles.files.selected=Selecting {0} of {1} {2}
dataverse.permissionsFiles.files.includeDeleted=Include Deleted Files
dataverse.permissionsFiles.viewRemoveDialog.header=File Access
dataverse.permissionsFiles.viewRemoveDialog.removeBtn=Remove Access
dataverse.permissionsFiles.viewRemoveDialog.removeBtn.confirmation=Are you sure you want to remove access to this file? Once access has been removed, the user or group will no longer be able to download this file.
Expand Down
Loading

0 comments on commit 7227c38

Please sign in to comment.