Skip to content

Commit 2af7c0e

Browse files
authored
Merge pull request #3967 from IQSS/3776-public-only
3776 public only
2 parents 22090e2 + ab96ab6 commit 2af7c0e

33 files changed

Lines changed: 830 additions & 131 deletions

doc/sphinx-guides/source/api/native-api.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Add a file to an existing Dataset. Description and tags are optional::
212212

213213
A more detailed "add" example using curl::
214214

215-
curl -H "X-Dataverse-key:$API_TOKEN" -X POST -F 'file=@data.tsv' -F 'jsonData={"description":"My description.","categories":["Data"]}' "https://example.dataverse.edu/api/datasets/:persistentId/add?persistentId=$PERSISTENT_ID"
215+
curl -H "X-Dataverse-key:$API_TOKEN" -X POST -F 'file=@data.tsv' -F 'jsonData={"description":"My description.","categories":["Data"], "restrict":"true"}' "https://example.dataverse.edu/api/datasets/:persistentId/add?persistentId=$PERSISTENT_ID"
216216

217217
Example python code to add a file. This may be run by changing these parameters in the sample code:
218218

@@ -303,6 +303,16 @@ Files
303303

304304
.. note:: Please note that files can be added via the native API but the operation is performed on the parent object, which is a dataset. Please see the "Datasets" endpoint above for more information.
305305

306+
Restrict or unrestrict an existing file where ``id`` is the database id of the file to restrict::
307+
308+
PUT http://$SERVER/api/files/{id}/restrict
309+
310+
Note that some Dataverse installations do not allow the ability to restrict files.
311+
312+
A more detailed "restrict" example using curl::
313+
314+
curl -H "X-Dataverse-key:$API_TOKEN" -X PUT -d true http://$SERVER/api/files/{id}/restrict
315+
306316
Replace an existing file where ``id`` is the database id of the file to replace. Note that metadata such as description and tags are not carried over from the file being replaced::
307317

308318
POST http://$SERVER/api/files/{id}/replace?key=$apiKey

doc/sphinx-guides/source/installation/config.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ Then run the create command:
222222

223223
``./asadmin $ASADMIN_OPTS create-jvm-options "\-Ddataverse.files.storage-driver-id=swift"``
224224

225+
You also have the option to set a custom container name separator. It is initialized to ``_``, but you can change it by running the create command:
226+
227+
``./asadmin $ASADMIN_OPTS create-jvm-options "\-Ddataverse.files.swift-folder-path-separator=-"``
228+
225229
.. _Branding Your Installation:
226230

227231
Branding Your Installation
@@ -891,6 +895,15 @@ Set the name of the cloud environment you've integrated with your Dataverse inst
891895

892896
``curl -X PUT -d 'Massachusetts Open Cloud (MOC)' http://localhost:8080/api/admin/settings/:CloudEnvironmentName``
893897

898+
:PublicInstall
899+
+++++++++++++++++++++
900+
901+
Setting an installation to public will remove the ability to restrict data files or datasets. This functionality of Dataverse will be disabled from your installation.
902+
903+
This is useful for specific cases where an installation's files are stored in public access. Because files stored this way do not obey Dataverse's file restrictions, users would still be able to access the files even when they're restricted. In these cases it's best to use :PublicInstall to disable the feature altogether.
904+
905+
``curl -X PUT -d true http://localhost:8080/api/admin/settings/:PublicInstall``
906+
894907
:DataCaptureModuleUrl
895908
+++++++++++++++++++++
896909

doc/sphinx-guides/source/user/dataset-management.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ File Handling + Uploading
4949

5050
To upload new files to a dataset, click the "Edit" button at the top of the dataset page and from the dropdown list select "Files (Upload)" or click the "Upload Files" button above the files table in the Files tab. From either option you will be brought to the Upload Files page for that dataset.
5151

52-
Once you have uploaded files, you will be able to edit file metadata, restrict access to files, and/or add tags. Click "Save Changes" to complete the upload. If you uploaded a file by mistake, you can delete it before saving by clicking the checkbox to select the file, and then clicking the "Delete" button above the Files Table.
52+
Once you have uploaded files, you will be able to edit file metadata, restrict access to files [#f1]_ , and/or add tags. Click "Save Changes" to complete the upload. If you uploaded a file by mistake, you can delete it before saving by clicking the checkbox to select the file, and then clicking the "Delete" button above the Files Table.
5353

5454
File upload limit size varies based on Dataverse installation. The file upload size limit can be found in the text above where files are uploaded in the application. If you have further questions, contact support for that installation by clicking on the Support link at the top of the application.
5555

56-
The file types listed below are supported by additional functionality, which can include downloading in different formats, subsets, file-level metadata preservation, file-level data citation; and exploration through data visualization and analysis.
56+
The file types listed in the following sections are supported by additional functionality, which can include downloading in different formats, subsets, file-level metadata preservation, file-level data citation; and exploration through data visualization and analysis.
57+
58+
.. [#f1] Some Dataverse installations do not allow this feature.
5759
5860
Tabular Data Files
5961
------------------
@@ -156,7 +158,7 @@ Go to the dataset you would like to edit, where you will see the listing of file
156158

157159
You will not have to leave the dataset page to complete these action, except for editing file metadata, which will bring you to the Edit Files page. There you will have to click the "Save Changes" button to apply your edits and return to the dataset page.
158160

159-
If you restrict files, you will also prompted with a popup asking you to fill out the Terms of Access for the files. If Terms of Access already exist, you will be asked to confirm them.
161+
If you restrict files, you will also prompted with a popup asking you to fill out the Terms of Access for the files. If Terms of Access already exist, you will be asked to confirm them. Note that some Dataverse installations do not allow for file restrictions.
160162

161163
File Tags
162164
---------
@@ -202,6 +204,8 @@ Restricted Files + Terms of Access
202204

203205
If you restrict any files in your dataset, you will be prompted by a pop-up to enter Terms of Access for the data. This can also be edited in the Terms tab or selecting Terms in the "Edit" dropdown button in the dataset. You may also allow users to request access for your restricted files by enabling "Request Access". To add more information about the Terms of Access, click on "Additional Information \[+]".
204206

207+
**Note:** Some Dataverse installations do not allow for file restriction.
208+
205209
Guestbook
206210
---------
207211

@@ -224,7 +228,7 @@ The panel below that is "Roles", where you can find all the roles set up in your
224228
File-Level
225229
----------
226230

227-
If you have restricted specific files the file-level permissions is where you will need to go to grant users/groups access to
231+
If you have restricted specific files, the file-level permissions is where you will need to go to grant users/groups access to
228232
specific restricted files. Dataset file permissions are located under Permissions in the Edit button on a dataset page.
229233
The file permissions page has two sections: Users/Groups and Files.
230234

src/main/java/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ dataset.message.deleteFailure=This dataset draft could not be deleted.
12111211
dataset.message.deaccessionFailure=This dataset could not be deaccessioned.
12121212
dataset.message.createFailure=The dataset could not be created.
12131213
dataset.message.termsFailure=The dataset terms could not be updated.
1214+
dataset.message.publicInstall=File Access - Files are stored on a publicly accessible storage server.
12141215
dataset.metadata.publicationDate=Publication Date
12151216
dataset.metadata.publicationDate.tip=The publication date of a dataset.
12161217
dataset.metadata.persistentId=Dataset Persistent ID

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ public boolean isRestricted() {
534534
return restricted;
535535
}
536536

537+
537538
public void setRestricted(boolean restricted) {
538539
this.restricted = restricted;
539540
}

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

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
66
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
77
import edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser;
8+
import edu.harvard.iq.dataverse.dataaccess.DataFileIO;
89
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
10+
import edu.harvard.iq.dataverse.dataaccess.SwiftAccessIO;
911
import edu.harvard.iq.dataverse.dataset.DatasetThumbnail;
1012
import edu.harvard.iq.dataverse.datavariable.VariableServiceBean;
1113
import edu.harvard.iq.dataverse.engine.command.Command;
@@ -76,6 +78,7 @@
7678
import java.util.logging.Level;
7779
import edu.harvard.iq.dataverse.datasetutility.TwoRavensHelper;
7880
import edu.harvard.iq.dataverse.datasetutility.WorldMapPermissionHelper;
81+
import edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand;
7982

8083
import javax.faces.event.AjaxBehaviorEvent;
8184

@@ -389,21 +392,41 @@ public String getDataverseSiteUrl() {
389392
public void setDataverseSiteUrl(String dataverseSiteUrl) {
390393
this.dataverseSiteUrl = dataverseSiteUrl;
391394
}
392-
//TODO:
393-
//Consolidate this & FilePage in static function in the SwiftAccessIO
394395

395-
public String getSwiftContainerName(){
396-
String swiftContainerName = null;
397-
String swiftFolderPathSeparator = "-";
398-
if (persistentId != null) {
399-
dataset = datasetService.findByGlobalId(persistentId);
400-
String authorityNoSlashes = dataset.getAuthority().replace(dataset.getDoiSeparator(), swiftFolderPathSeparator);
401-
swiftContainerName = dataset.getProtocol() + swiftFolderPathSeparator + authorityNoSlashes.replace(".", swiftFolderPathSeparator)
402-
+ swiftFolderPathSeparator + dataset.getIdentifier();
403-
logger.fine("Swift container name: " + swiftContainerName);
396+
public DataFile getInitialDataFile(){
397+
Long datasetVersion = workingVersion.getId();
398+
if (datasetVersion != null) {
399+
int unlimited = 0;
400+
int maxResults = unlimited;
401+
List<FileMetadata> metadatas = datafileService.findFileMetadataByDatasetVersionId(datasetVersion, maxResults, fileSortField, fileSortOrder);
402+
logger.fine("metadatas " + metadatas);
403+
if (metadatas != null && metadatas.size() > 0) {
404+
return metadatas.get(0).getDataFile();
405+
}
404406
}
407+
return null;
408+
}
409+
410+
public String getSwiftContainerName(){
411+
412+
String swiftContainerName;
413+
try {
414+
DataFileIO dataFileIO = getInitialDataFile().getDataFileIO();
415+
try {
416+
SwiftAccessIO swiftIO = (SwiftAccessIO)dataFileIO;
417+
swiftIO.open();
418+
swiftContainerName = swiftIO.getSwiftContainerName();
419+
logger.info("Swift container name: " + swiftContainerName);
420+
return swiftContainerName;
405421

406-
return swiftContainerName;
422+
} catch (Exception e) {
423+
e.printStackTrace();
424+
}
425+
}
426+
catch (Exception e){
427+
e.printStackTrace();
428+
}
429+
return "";
407430
}
408431

409432
public void setSwiftContainerName(String name){
@@ -415,20 +438,14 @@ public void setSwiftContainerName(String name){
415438
//SF
416439
public Boolean isSwiftStorage(){
417440
Boolean swiftBool = false;
418-
//dataset = datasetService.findByGlobalId(persistentId);
419-
Long datasetVersion = workingVersion.getId();
420-
if (datasetVersion != null) {
421-
int unlimited = 0;
422-
int maxResults = unlimited;
423-
List<FileMetadata> metadatas = datafileService.findFileMetadataByDatasetVersionId(datasetVersion, maxResults, fileSortField, fileSortOrder);
424-
logger.fine("metadatas " + metadatas);
425-
if (metadatas != null && metadatas.size() > 0) {
426-
if ("swift".equals(System.getProperty("dataverse.files.storage-driver-id"))
427-
&& metadatas.get(0).getDataFile().getStorageIdentifier().startsWith("swift://")) {
428-
swiftBool = true;
429-
}
441+
//containers without datafiles will not be stored in swift storage, so no compute
442+
if (getInitialDataFile() != null){
443+
if ("swift".equals(System.getProperty("dataverse.files.storage-driver-id"))
444+
&& getInitialDataFile().getStorageIdentifier().startsWith("swift://")) {
445+
swiftBool = true;
430446
}
431447
}
448+
432449
return swiftBool;
433450
}
434451

@@ -1309,6 +1326,10 @@ private String init(boolean initFull) {
13091326
workingVersion = dataset.getCreateVersion();
13101327
updateDatasetFieldInputLevels();
13111328
}
1329+
1330+
if (settingsService.isTrueForKey(SettingsServiceBean.Key.PublicInstall, false)){
1331+
JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.message.publicInstall"));
1332+
}
13121333

13131334
resetVersionUI();
13141335

@@ -2107,7 +2128,7 @@ public String testSelectedFilesForRestrict(){
21072128
}
21082129

21092130

2110-
public String restrictSelectedFiles(boolean restricted){
2131+
public String restrictSelectedFiles(boolean restricted) throws CommandException{
21112132

21122133
RequestContext requestContext = RequestContext.getCurrentInstance();
21132134
if (selectedFiles.isEmpty()) {
@@ -2147,8 +2168,8 @@ public String restrictSelectedFiles(boolean restricted){
21472168
return returnToDraftVersion();
21482169
}
21492170

2150-
public void restrictFiles(boolean restricted) {
2151-
2171+
public void restrictFiles(boolean restricted) throws CommandException {
2172+
21522173
//if (previouslyRestrictedFiles == null) {
21532174
// we don't need to buther with this "previously restricted" business
21542175
// when in Create mode... because all the files are new, so none could
@@ -2165,7 +2186,8 @@ public void restrictFiles(boolean restricted) {
21652186
previouslyRestrictedFiles.add(fmd);
21662187
}
21672188
}
2168-
2189+
2190+
Command cmd;
21692191
String fileNames = null;
21702192
for (FileMetadata fmw : workingVersion.getFileMetadatas()) {
21712193
for (FileMetadata fmd : this.getSelectedFiles()) {
@@ -2182,13 +2204,17 @@ public void restrictFiles(boolean restricted) {
21822204
}
21832205
}
21842206
if (fmd.getDataFile().equals(fmw.getDataFile())) {
2185-
fmw.setRestricted(restricted);
2186-
if (workingVersion.isDraft() && !fmw.getDataFile().isReleased()) {
2187-
// We do not really need to check that the working version is
2188-
// a draft here - it must be a draft, if we've gotten this
2189-
// far. But just in case. -- L.A. 4.2.1
2190-
fmw.getDataFile().setRestricted(restricted);
2191-
}
2207+
cmd = new RestrictFileCommand(fmw.getDataFile(), dvRequestService.getDataverseRequest(), restricted);
2208+
commandEngine.submit(cmd);
2209+
2210+
2211+
// fmw.setRestricted(restricted);
2212+
// if (workingVersion.isDraft() && !fmw.getDataFile().isReleased()) {
2213+
// // We do not really need to check that the working version is
2214+
// // a draft here - it must be a draft, if we've gotten this
2215+
// // far. But just in case. -- L.A. 4.2.1
2216+
// fmw.getDataFile().setRestricted(restricted);
2217+
// }
21922218
}
21932219
}
21942220
}

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import edu.harvard.iq.dataverse.dataset.DatasetThumbnail;
1111
import edu.harvard.iq.dataverse.engine.command.Command;
1212
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
13+
import edu.harvard.iq.dataverse.engine.command.exception.CommandExecutionException;
1314
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDataFileCommand;
15+
import edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand;
1416
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand;
1517
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand;
1618
import edu.harvard.iq.dataverse.ingest.IngestRequest;
@@ -557,10 +559,18 @@ public String init() {
557559
if (mode == FileEditMode.UPLOAD) {
558560
JH.addMessage(FacesMessage.SEVERITY_INFO, getBundleString("dataset.message.uploadFiles"));
559561
}
562+
563+
if (settingsService.isTrueForKey(SettingsServiceBean.Key.PublicInstall, false)){
564+
JH.addMessage(FacesMessage.SEVERITY_WARN, getBundleString("dataset.message.publicInstall"));
565+
}
566+
560567
return null;
568+
561569
}
562570

563571

572+
573+
564574
private void msg(String s){
565575
System.out.println(s);
566576
}
@@ -697,10 +707,11 @@ public boolean isShowAccessPopup() {
697707
}
698708

699709
public void setShowAccessPopup(boolean showAccessPopup) {} // dummy set method
700-
701-
public void restrictFiles(boolean restricted) {
710+
711+
public void restrictFiles(boolean restricted) throws CommandException{
712+
702713
// since we are restricted files, first set the previously restricted file list, so we can compare for
703-
// determinin whether to show the access popup
714+
// determining whether to show the access popup
704715
previouslyRestrictedFiles = new ArrayList();
705716
for (FileMetadata fmd : workingVersion.getFileMetadatas()) {
706717
if (fmd.isRestricted()) {
@@ -720,13 +731,17 @@ public void restrictFiles(boolean restricted) {
720731
fileNames = fileNames.concat(", " + fmd.getLabel());
721732
}
722733
}
723-
fmd.setRestricted(restricted);
724-
if (workingVersion.isDraft() && !fmd.getDataFile().isReleased()) {
725-
// We do not really need to check that the working version is
726-
// a draft here - it must be a draft, if we've gotten this
727-
// far. But just in case. -- L.A. 4.2.1
728-
fmd.getDataFile().setRestricted(restricted);
729-
}
734+
//fmd.setRestricted(restricted);
735+
Command cmd;
736+
cmd = new RestrictFileCommand(fmd.getDataFile(), dvRequestService.getDataverseRequest(), restricted);
737+
commandEngine.submit(cmd);
738+
739+
// if (workingVersion.isDraft() && !fmd.getDataFile().isReleased()) {
740+
// // We do not really need to check that the working version is
741+
// // a draft here - it must be a draft, if we've gotten this
742+
// // far. But just in case. -- L.A. 4.2.1
743+
// fmd.getDataFile().setRestricted(restricted);
744+
// }
730745
}
731746
if (fileNames != null) {
732747
String successMessage = getBundleString("file.restricted.success");
@@ -1165,7 +1180,7 @@ public String save() {
11651180
StringBuilder saveError = new StringBuilder();
11661181

11671182
for (FileMetadata fileMetadata : fileMetadatas) {
1168-
1183+
11691184
if (fileMetadata.getDataFile().getCreateDate() == null) {
11701185
fileMetadata.getDataFile().setCreateDate(updateTime);
11711186
fileMetadata.getDataFile().setCreator((AuthenticatedUser) session.getUser());

0 commit comments

Comments
 (0)