From cd16df271cd0275ffa9ec93e10d385442d3963f2 Mon Sep 17 00:00:00 2001 From: Stephen Kraffmiller Date: Wed, 1 Nov 2017 10:15:49 -0400 Subject: [PATCH] #4139 Allow author to download files while in review and other minor changes --- src/main/java/Bundle.properties | 2 ++ .../edu/harvard/iq/dataverse/DatasetPage.java | 11 ++++++ .../edu/harvard/iq/dataverse/FilePage.java | 13 +++++++ .../iq/dataverse/PermissionServiceBean.java | 23 ++++++++++++ .../file-download-button-fragment.xhtml | 36 +++++++++++++------ src/main/webapp/file.xhtml | 2 ++ src/main/webapp/filesFragment.xhtml | 11 +++--- 7 files changed, 82 insertions(+), 16 deletions(-) diff --git a/src/main/java/Bundle.properties b/src/main/java/Bundle.properties index 18c82c4f37a..a4e3fa63c58 100755 --- a/src/main/java/Bundle.properties +++ b/src/main/java/Bundle.properties @@ -1185,6 +1185,8 @@ dataset.message.uploadFiles=Upload Dataset Files - You can drag and drop files f dataset.message.editMetadata=Edit Dataset Metadata - Add more metadata about this dataset to help others easily find it. dataset.message.editTerms=Edit Dataset Terms - Update this dataset's terms of use. dataset.message.locked.editNotAllowedInReview=Dataset cannot be edited due to In Review dataset lock. +dataset.message.locked.downloadNotAllowedInReview=Dataset file(s) may not be downloaded due to In Review dataset lock. +dataset.message.locked.downloadNotAllowed=Dataset file(s) may not be downloaded due to dataset lock. dataset.message.locked.editNotAllowed=Dataset cannot be edited due to dataset lock. dataset.message.createSuccess=This dataset has been created. dataset.message.linkSuccess= {0} has been successfully linked to {1}. diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java index dcc224bbf8c..17e9a5abb0c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java @@ -2676,6 +2676,17 @@ public boolean isLockedFromEdits() { } return false; } + + public boolean isLockedFromDownload(){ + + try { + permissionService.checkDownloadFileLock(dataset, dvRequestService.getDataverseRequest(), new CreateDatasetCommand(dataset, dvRequestService.getDataverseRequest())); + } catch (IllegalCommandException ex) { + return true; + } + return false; + + } public void setLocked(boolean locked) { // empty method, so that we can use DatasetPage.locked in a hidden diff --git a/src/main/java/edu/harvard/iq/dataverse/FilePage.java b/src/main/java/edu/harvard/iq/dataverse/FilePage.java index fb1cb5207c8..1c902d33f92 100644 --- a/src/main/java/edu/harvard/iq/dataverse/FilePage.java +++ b/src/main/java/edu/harvard/iq/dataverse/FilePage.java @@ -15,6 +15,7 @@ import edu.harvard.iq.dataverse.engine.command.Command; import edu.harvard.iq.dataverse.engine.command.exception.CommandException; import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException; +import edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand; import edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand; import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand; import edu.harvard.iq.dataverse.export.ExportException; @@ -708,6 +709,18 @@ public boolean isLockedFromEdits() { } return false; } + + public boolean isLockedFromDownload(){ + Dataset testDataset = fileMetadata.getDataFile().getOwner(); + try { + permissionService.checkDownloadFileLock(testDataset, dvRequestService.getDataverseRequest(), new CreateDatasetCommand(testDataset, dvRequestService.getDataverseRequest())); + } catch (IllegalCommandException ex) { + return true; + } + System.out.print("returning false from is locked from Download...."); + return false; + + } public String getPublicDownloadUrl() { try { diff --git a/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java index 6431b16488a..3a00be24b78 100644 --- a/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java @@ -27,6 +27,7 @@ import static edu.harvard.iq.dataverse.engine.command.CommandHelper.CH; import edu.harvard.iq.dataverse.engine.command.DataverseRequest; import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException; +import edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand; import edu.harvard.iq.dataverse.engine.command.impl.PublishDatasetCommand; import edu.harvard.iq.dataverse.util.BundleUtil; import java.util.Arrays; @@ -563,5 +564,27 @@ public void checkEditDatasetLock(Dataset dataset, DataverseRequest dataverseRequ } } } + + public void checkDownloadFileLock(Dataset dataset, DataverseRequest dataverseRequest, Command command) throws IllegalCommandException { + if (dataset.isLocked()) { + if (dataset.isLockedFor(DatasetLock.Reason.InReview)) { + // The "InReview" lock is not really a lock for curators or contributors. They can still download. + if (!isUserAllowedOn(dataverseRequest.getUser(), new CreateDatasetCommand(dataset, dataverseRequest, true), dataset)) { + throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.message.locked.downloadNotAllowedInReview"), command); + } + } + if (dataset.isLockedFor(DatasetLock.Reason.Ingest)) { + throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.message.locked.downloadNotAllowed"), command); + } + // TODO: Do we need to check for "Workflow"? Should the message be more specific? + if (dataset.isLockedFor(DatasetLock.Reason.Workflow)) { + throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.message.locked.downloadNotAllowed"), command); + } + // TODO: Do we need to check for "DcmUpload"? Should the message be more specific? + if (dataset.isLockedFor(DatasetLock.Reason.DcmUpload)) { + throw new IllegalCommandException(BundleUtil.getStringFromBundle("dataset.message.locked.downloadNotAllowed"), command); + } + } + } } diff --git a/src/main/webapp/file-download-button-fragment.xhtml b/src/main/webapp/file-download-button-fragment.xhtml index db760786aab..072cb82a603 100644 --- a/src/main/webapp/file-download-button-fragment.xhtml +++ b/src/main/webapp/file-download-button-fragment.xhtml @@ -56,12 +56,13 @@
  • #{bundle['file.explore.twoRavens']} @@ -70,14 +71,15 @@
  • #{bundle['file.mapData.worldMap']} #{bundle.explore} @@ -102,7 +104,7 @@ process="@this" action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'explore' )}" update="@widgetVar(downloadPopup)" - disabled="#{fileMetadata.dataFile.ingestInProgress}" + disabled="#{fileMetadata.dataFile.ingestInProgress or lockedFromDownload}" oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');"> #{bundle.explore} @@ -113,7 +115,7 @@ #{bundle.explore} @@ -122,7 +124,7 @@ process="@this" action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'worldMap' )}" update="@widgetVar(downloadPopup)" - disabled="#{fileMetadata.dataFile.ingestInProgress}" + disabled="#{fileMetadata.dataFile.ingestInProgress or lockedFromDownload}" oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');"> #{bundle.explore} @@ -140,6 +142,7 @@ @@ -149,6 +152,7 @@ @@ -181,6 +185,7 @@
  • @@ -188,6 +193,7 @@ @@ -199,11 +205,13 @@
  • #{bundle['file.downloadBtn.format.tab']} #{bundle['file.downloadBtn.format.tab']} @@ -213,11 +221,13 @@
  • #{bundle['file.downloadBtn.format.rdata']} @@ -228,11 +238,13 @@
  • #{bundle['file.downloadBtn.format.var']} @@ -242,18 +254,20 @@
  • + /> + />