Skip to content

Commit

Permalink
#4139 Allow author to download files while in review and other minor …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
sekmiller committed Nov 1, 2017
1 parent 4de7fcf commit cd16df2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/FilePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/PermissionServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

}
36 changes: 25 additions & 11 deletions src/main/webapp/file-download-button-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
<li><!-- Two Ravens -->
<h:commandLink rendered="#{!downloadPopupRequired}"
styleClass="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
action="#{fileDownloadService.startExploreDownloadLink(guestbookResponse, fileMetadata )}" target="_blank">
#{bundle['file.explore.twoRavens']}
</h:commandLink>
<p:commandLink rendered="#{downloadPopupRequired}"
action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'explore' )}"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
process="@this"
update="@widgetVar(downloadPopup)"
oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');">
Expand All @@ -70,14 +71,15 @@
</li>
<li><!-- WorldMap Explore -->
<h:commandLink rendered="#{!downloadPopupRequired}"
styleClass="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
styleClass="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"

action="#{fileDownloadService.startWorldMapDownloadLink(guestbookResponse, fileMetadata )}" target="_blank">
#{bundle['file.mapData.worldMap']}
</h:commandLink>
<p:commandLink rendered="#{downloadPopupRequired}"
styleClass="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{fileMetadata.dataFile.ingestInProgress}"
styleClass="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
disabled="#{fileMetadata.dataFile.ingestInProgress or lockedFromDownload}"
process="@this"
action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'worldMap' )}"
update="@widgetVar(downloadPopup)"
Expand All @@ -93,7 +95,7 @@
<h:commandLink rendered="#{!downloadPopupRequired}"
type="button"
styleClass="btn btn-default #{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
action="#{fileDownloadService.startExploreDownloadLink( guestbookResponse, fileMetadata )}" target="_blank">
<span class="glyphicon glyphicon-equalizer"/> <span class="ladda-label">#{bundle.explore}</span>
</h:commandLink>
Expand All @@ -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');">
<span class="glyphicon glyphicon-equalizer"/> #{bundle.explore}
</p:commandLink>
Expand All @@ -113,7 +115,7 @@
<h:commandLink pt:role="button" rendered="#{!downloadPopupRequired}"
type="button"
styleClass="btn btn-default #{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress) ? 'disabled' : ''}"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
title="Explore" action="#{fileDownloadService.startWorldMapDownloadLink(guestbookResponse, fileMetadata )}" target="_blank">
<span class="glyphicon glyphicon-equalizer"/> #{bundle.explore}
</h:commandLink>
Expand All @@ -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');">
<span class="glyphicon glyphicon-equalizer"/> #{bundle.explore}
</p:commandLink>
Expand All @@ -140,6 +142,7 @@
<p:commandLink rendered="#{ fileDownloadHelper.canDownloadFile(fileMetadata) and !(fileMetadata.dataFile.tabularData) and !(downloadPopupRequired) }"
type="button" styleClass="btn btn-default"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
actionListener="#{fileDownloadService.startFileDownload(guestbookResponse, fileMetadata, 'Download')}">
<!-- non-tabular data file: -->
<!-- no guest book/terms of use/etc. - straight to the download API url: -->
Expand All @@ -149,6 +152,7 @@
<p:commandLink rendered="#{ fileDownloadHelper.canDownloadFile(fileMetadata) and !(fileMetadata.dataFile.tabularData) and downloadPopupRequired }"
type="button" styleClass="btn btn-default"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
action="#{guestbookResponseService.modifyDatafile(guestbookResponse, fileMetadata)}"
update="@widgetVar(downloadPopup)" oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');">
<!-- guest book or terms of use, etc. enabled - open "download popup" first: -->
Expand Down Expand Up @@ -181,13 +185,15 @@
<li>
<p:commandLink rendered="#{!downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
actionListener="#{fileDownloadService.startFileDownload(guestbookResponse, fileMetadata, 'original')}">
<h:outputFormat value="#{bundle['file.downloadBtn.format.original']}">
<f:param value="#{fileMetadata.dataFile.originalFormatLabel}"/>
</h:outputFormat>
</p:commandLink>
<p:commandLink rendered="#{downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'original' )}"
update="@widgetVar(downloadPopup)"
oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');">
Expand All @@ -199,11 +205,13 @@
<li>
<p:commandLink rendered="#{!downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
actionListener="#{fileDownloadService.startFileDownload(guestbookResponse, fileMetadata, 'tab')}">
#{bundle['file.downloadBtn.format.tab']}
</p:commandLink>
<p:commandLink rendered="#{downloadPopupRequired}"
action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'tab' )}"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
update="@widgetVar(downloadPopup)"
oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');">
#{bundle['file.downloadBtn.format.tab']}
Expand All @@ -213,11 +221,13 @@
<li>
<p:commandLink rendered="#{!downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
actionListener="#{fileDownloadService.startFileDownload(guestbookResponse, fileMetadata, 'RData')}">
#{bundle['file.downloadBtn.format.rdata']}
</p:commandLink>
<p:commandLink rendered="#{downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'RData' )}"
update="@widgetVar(downloadPopup)"
oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');">
Expand All @@ -228,11 +238,13 @@
<li>
<p:commandLink rendered="#{!downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
actionListener="#{fileDownloadService.startFileDownload(guestbookResponse, fileMetadata, 'var')}">
#{bundle['file.downloadBtn.format.var']}
</p:commandLink>
<p:commandLink rendered="#{downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload) ? 'disabled' : ''}"
action="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse, fileMetadata, 'var' )}"
update="@widgetVar(downloadPopup)"
oncomplete="PF('downloadPopup').show();handleResizeDialog('downloadPopup');">
Expand All @@ -242,18 +254,20 @@
<li>
<p:commandLink id="fileDowloadDataSubsetButton" rendered="#{!(downloadPopupRequired)}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload or empty fileMetadata.dataFile.id) ? 'disabled' : ''}"
actionListener="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse,fileMetadata, 'subset')}"
update="@widgetVar(downloadDataSubsetPopup)"
oncomplete="PF('downloadDataSubsetPopup').show()"
value="Data Subset"
disabled="#{empty fileMetadata.dataFile.id}"/>
/>
<p:commandLink id="fileDowloadDataSubsetButtonPopupReq" rendered="#{downloadPopupRequired}"
process="@this"
disabled="#{(fileMetadata.dataFile.ingestInProgress or lockedFromDownload or empty fileMetadata.dataFile.id) ? 'disabled' : ''}"
actionListener="#{guestbookResponseService.modifyDatafileAndFormat(guestbookResponse,fileMetadata, 'subset')}"
update="@widgetVar(downloadPopup)"
oncomplete="PF('downloadPopup').show()"
value="Data Subset"
disabled="#{empty fileMetadata.dataFile.id}"/>
/>
</li>
<li class="dropdown-submenu pull-left">
<a tabindex="-1" href="javascript:void(0);">#{bundle['file.downloadBtn.format.citation']}</a>
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/file.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<ui:param name="guestbookResponseService" value="#{FilePage.guestbookResponseService}"/>
<ui:param name="fileDownloadService" value="#{FilePage.fileDownloadService}"/>
<ui:param name="isFilePg" value="true"/>
<ui:param name="lockedFromDownload" value="#{FilePage.lockedFromDownload}"/>
</ui:include>
</div>
<!-- END: Explore/Download/Request Button Block -->
Expand Down Expand Up @@ -444,6 +445,7 @@
<ui:param name="guestbookResponseService" value="#{FilePage.guestbookResponseService}"/>
<ui:param name="fileDownloadService" value="#{FilePage.fileDownloadService}"/>
<ui:param name="twoRavensHelper" value="#{FilePage.twoRavensHelper}"/>
<ui:param name="lockedFromDownload" value="#{FilePage.lockedFromDownload}"/>
</ui:include>
</p:dialog>
<p:dialog id="downloadDataSubsetPopup" styleClass="smallPopUp" header="#{bundle['file.download.subset.header']}" widgetVar="downloadDataSubsetPopup"
Expand Down
Loading

0 comments on commit cd16df2

Please sign in to comment.