Skip to content

Commit

Permalink
#8191 update ui and bundle, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Nov 30, 2021
1 parent 12fba42 commit a849d6c
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/main/java/edu/harvard/iq/dataverse/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private DatasetVersion createNewDatasetVersion(Template template, FileMetadata f
TermsOfUseAndAccess terms = new TermsOfUseAndAccess();
terms.setDatasetVersion(dsv);
terms.setLicense(TermsOfUseAndAccess.License.CC0);
terms.setFileAccessRequest(true);
dsv.setTermsOfUseAndAccess(terms);
}

Expand Down
15 changes: 14 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ public void setRsyncScript(String rsyncScript) {
public String getRsyncScriptFilename() {
return rsyncScriptFilename;
}

private Boolean hasRestrictedFiles = null;

public Boolean isHasRestrictedFiles(){
//cache in page to limit processing
if (hasRestrictedFiles != null){
return hasRestrictedFiles;
} else {
hasRestrictedFiles = workingVersion.isHasRestrictedFile();
return hasRestrictedFiles;
}
}

private String thumbnailString = null;

Expand Down Expand Up @@ -2054,7 +2066,8 @@ private String init(boolean initFull) {
previewTools = externalToolService.findFileToolsByType(ExternalTool.Type.PREVIEW);
datasetExploreTools = externalToolService.findDatasetToolsByType(ExternalTool.Type.EXPLORE);
rowsPerPage = 10;

hasRestrictedFiles = workingVersion.isHasRestrictedFile();

return null;
}

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ public boolean isHasNonPackageFile(){
// The presence of any non-package file means that HTTP Upload was used (no mixing allowed) so we just check the first file.
return !this.fileMetadatas.get(0).getDataFile().getContentType().equals(DataFileServiceBean.MIME_TYPE_PACKAGE_FILE);
}

public boolean isHasRestrictedFile(){
if (this.fileMetadatas.isEmpty()){;
return false;
}
return this.fileMetadatas.stream().anyMatch(fm -> (fm.isRestricted()));
}

public void updateDefaultValuesFromTemplate(Template template) {
if (!template.getDatasetFields().isEmpty()) {
Expand Down Expand Up @@ -636,6 +643,11 @@ public void initDefaultValues() {
TermsOfUseAndAccess terms = new TermsOfUseAndAccess();
terms.setDatasetVersion(this);
terms.setLicense(TermsOfUseAndAccess.License.CC0);
/*
Added for https://github.com/IQSS/dataverse/issues/8191
set File Access Request to true
*/
terms.setFileAccessRequest(true);
this.setTermsOfUseAndAccess(terms);

}
Expand Down Expand Up @@ -1665,7 +1677,23 @@ public Set<ConstraintViolation> validate() {
}
}
}


TermsOfUseAndAccess toua = this.termsOfUseAndAccess;
//Only need to test Terms of Use and Access if there are restricted files
if (toua != null && this.isHasRestrictedFile()) {
Set<ConstraintViolation<TermsOfUseAndAccess>> constraintViolations = validator.validate(toua);
if (constraintViolations.size() > 0) {
ConstraintViolation<TermsOfUseAndAccess> violation = constraintViolations.iterator().next();
String message = "Constraint violation found in Terms of Use and Access. "
+ "If Request Access to restricted files is disabled then Terms of Access must be provided.";
logger.info(message);
this.termsOfUseAndAccess.setValidationMessage(message);
returnSet.add(violation);
}
}


return returnSet;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/edu/harvard/iq/dataverse/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public Template cloneNewTemplate(Template source) {
} else {
terms = new TermsOfUseAndAccess();
terms.setLicense(TermsOfUseAndAccess.defaultLicense);
terms.setFileAccessRequest(true);
}
newTemplate.setTermsOfUseAndAccess(terms);
return newTemplate;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/TermsOfUseAndAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

/**
*
*
* @author skraffmi
*/
@Entity
@ValidateTermsOfUseAndAccess
public class TermsOfUseAndAccess implements Serializable {

@Id
Expand Down Expand Up @@ -275,6 +277,17 @@ public enum License {
NONE, CC0
}

@Transient
private String validationMessage;

public String getValidationMessage() {
return validationMessage;
}

public void setValidationMessage(String validationMessage) {
this.validationMessage = validationMessage;
}

/**
* @todo What does the GUI use for a default license? What does the "native"
* API use? See also https://github.com/IQSS/dataverse/issues/1385
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,46 @@ public void initialize(ValidateTermsOfUseAndAccess constraintAnnotation) {

@Override
public boolean isValid(TermsOfUseAndAccess value, ConstraintValidatorContext context) {
//if both null invalid
//if(value.getTemplate() == null && value.getDatasetVersion() == null) return false;
//must allow access requests or have terms of access filled in.

//if both not null invalid
//return !(value.getTemplate() != null && value.getDatasetVersion() != null);
return true;
boolean valid = value.isFileAccessRequest() == true || (value.getTermsOfAccess() != null && !value.getTermsOfAccess().isEmpty()) ;
if (!valid) {
try {


if ( context != null) {
context.buildConstraintViolationWithTemplate( "If Request Access is false then Terms of Access must be provided.").addConstraintViolation();
}

String message = "Constraint violation found in Terms of Use and Access. "
+ " If Request Access to restricted files is set to false then Terms of Access must be provided.";

value.setValidationMessage(message);
} catch (NullPointerException e) {
return false;
}
return false;
}


return valid;
}

public static boolean isTOUAValid(TermsOfUseAndAccess value, ConstraintValidatorContext context){

boolean valid = value.isFileAccessRequest() == true || (value.getTermsOfAccess() != null && !value.getTermsOfAccess().isEmpty());
if (!valid) {

if (context != null) {
context.buildConstraintViolationWithTemplate("If Request Access is false then Terms of Access must be provided.").addConstraintViolation();
}

String message = "Constraint violation found in Terms of Use and Access. "
+ " If Request Access to restricted files is set to false then Terms of Access must be provided.";

value.setValidationMessage(message);
}
return valid;
}

}
4 changes: 2 additions & 2 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2124,8 +2124,8 @@ citationFrame.banner.countdownMessage.seconds=seconds

#file-edit-popup-fragment.xhtml #editFilesFragment.xhtml
dataset.access.accessHeader=Restrict Files and Add Dataset Terms of Access
dataset.access.description=Restricting limits access to published files. You can add or edit Terms of Access for the dataset, and allow people to Request Access to restricted files.

dataset.access.description=Restricting limits access to published files. Providing information about access to restricted files is <b>required</b>. By default people who want to use these files can request access to them. You can provide Terms of Access instead by unchecking the box and adding them. These settings can be changed when you edit the dataset. Learn about restricting files and dataset access in the <a href="{0}/{1}/user/dataset-management.html#restricted-files-terms-of-use" title="Dataverse User Guide" target="_blank">User Guide</a>.
dataset.access.description.line.2=One of the following methods for communicating access must be active, and applies to all restricted files in this dataset.
#datasetFieldForEditFragment.xhtml
dataset.AddReplication=Add "Replication Data for" to Title
dataset.replicationDataFor=Replication Data for:
Expand Down
36 changes: 24 additions & 12 deletions src/main/webapp/dataset-license-terms.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,38 @@
</div>
</ui:fragment>
<ui:fragment rendered="#{!empty editMode}">
<div class="form-group">
<label for="metadata_TermsAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess']}
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess.title']}"></span>
</label>
<div class="col-sm-9">
<p:inputTextarea value="#{termsOfUseAndAccess.termsOfAccess}" rows="5" styleClass="form-control" />
</div>
</div>
<div class="form-group" jsf:rendered="#{!settingsWrapper.publicInstall}">
<p class="help-block">
<h:outputFormat value=" #{bundle['dataset.access.description']}" escape="false">
<f:param value="#{systemConfig.guidesBaseUrl}"/>
<f:param value="#{systemConfig.guidesVersion}"/>
</h:outputFormat>
</p>
<p class="help-block">
#{bundle['dataset.access.description.line.2']}
</p>
</div>
<div class="form-group" jsf:rendered="#{!settingsWrapper.publicInstall}">
<label for="metadata_RequestAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess']}
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.title']}"></span>
</label>
<div class="col-sm-9">
<p:selectBooleanCheckbox id="requestAccess" itemLabel="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.enableBtn']}" value="#{termsOfUseAndAccess.fileAccessRequest}"/>
<p:selectBooleanCheckbox id="requestAccess" itemLabel="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.enableBtn']}"
value="#{termsOfUseAndAccess.fileAccessRequest}" disabled="#{!DatasetPage.isHasRestrictedFiles()}"/>
</div>
</div>
<div class="form-group">
<label for="metadata_TermsAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess']}
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess.title']}"></span>
</label>
<div class="col-sm-9">
<p:inputTextarea value="#{termsOfUseAndAccess.termsOfAccess}" rows="5" styleClass="form-control" disabled="#{!DatasetPage.isHasRestrictedFiles()}" />
</div>
</div>
</ui:fragment>

<!-- Additional Information -->
Expand Down Expand Up @@ -370,7 +382,7 @@
data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.addInfo.dataAccessPlace.title']}"></span>
</label>
<div class="col-sm-9">
<p:inputTextarea value="#{termsOfUseAndAccess.dataAccessPlace}" rows="5" cols="60" styleClass="form-control" />
<p:inputTextarea value="#{termsOfUseAndAccess.dataAccessPlace}" rows="5" cols="60" styleClass="form-control" disabled="#{!DatasetPage.isHasRestrictedFiles()}" />
</div>
</div>
<div class="form-group">
Expand Down
45 changes: 29 additions & 16 deletions src/main/webapp/editFilesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -593,36 +593,49 @@
<p:dialog id="editFileAccessPopup" header="#{bundle['dataset.access.accessHeader']}" widgetVar="editFileAccessPopup" modal="true">
<p:focus context="editFileAccessPopup"/>
<p class="help-block">
#{bundle['dataset.access.description']}
</p>
<div class="form-horizontal">
<h:outputFormat value=" #{bundle['dataset.access.description']}" escape="false">
<f:param value="#{systemConfig.guidesBaseUrl}"/>
<f:param value="#{systemConfig.guidesVersion}"/>
</h:outputFormat>
</p>
<p class="help-block">
#{bundle['dataset.access.description.line.2']}
</p>
<p class="help-block">
<div class="form-group">
<label for="metadata_TermsAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess']}
<label for="metadata_RequestAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess']}
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess.title']}"></span>
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.title']}"></span>
</label>
<div class="col-sm-9">
<p:inputTextarea styleClass="form-control"
value="#{EditDatafilesPage.termsOfAccess}" autoResize="false" rows="5"/>
<p:selectBooleanCheckbox widgetVar="editFileRequestAccessBox" id="editFileRequestAccessBox" itemLabel="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.enableBtn']}"
value="#{EditDatafilesPage.fileAccessRequest}">
<p:ajax event="change" update="saveTOAButton" />
</p:selectBooleanCheckbox>
</div>
</div>

<div class="form-group">
<label for="metadata_RequestAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess']}
<label for="metadata_TermsAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess']}
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.title']}"></span>
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.termsOfsAccess.title']}"></span>
</label>
<div class="col-sm-9">
<p:selectBooleanCheckbox id="editFileRequestAccess" itemLabel="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.enableBtn']}"
value="#{EditDatafilesPage.fileAccessRequest}"/>
<p:inputTextarea styleClass="form-control" id="inputTermsOfAccessText"
value="#{EditDatafilesPage.termsOfAccess}" autoResize="false" rows="5">
<p:ajax event="keyup" update="saveTOAButton" />
</p:inputTextarea>
</div>
</div>
</div>
</p>
<div class="button-block">
<p:commandButton styleClass="btn btn-default" value="#{bundle.continue}"
<p:commandButton styleClass="btn btn-default" value="#{bundle.saveChanges}"
onclick="PF('editFileAccessPopup').hide()"
action="#{EditDatafilesPage.restrictFiles(true)}"
id="saveTOAButton"
disabled="#{empty EditDatafilesPage.termsOfAccess and !EditDatafilesPage.fileAccessRequest}"
update="filesTable,:messagePanel"
oncomplete="javascript:bind_bsui_components();" />
<button class="btn btn-link" onclick="PF('editFileAccessPopup').hide()" type="button">
Expand Down Expand Up @@ -940,7 +953,7 @@
#{bundle.close}
</button>
</div>
</p:dialog>
</p:dialog>
<script src="/resources/js/dropins.js" id="dropboxjs" data-app-key="#{EditDatafilesPage.dropBoxKey}"/>
<script>
//<![CDATA[
Expand Down
19 changes: 14 additions & 5 deletions src/main/webapp/file-edit-popup-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</div>
<div class="form-group">
<label for="requestAccess" class="col-sm-3 control-label">
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess']}
#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess']}
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto right" data-original-title="#{bundle['file.dataFilesTab.terms.list.termsOfAccess.requestAccess.title']}"></span>
</label>
Expand All @@ -54,14 +54,23 @@
</div>
</div>
</div>

<div class="ui-message ui-message-error ui-widget ui-corner-all" aria-live="polite" jsf:rendered="#{!empty termsOfUseAndAccess.validationMessage}">
<span class="ui-message-error-detail">#{termsOfUseAndAccess.validationMessage}</span>
</div>
<div class="button-block">
<p:commandButton styleClass="btn btn-default" value="#{bundle.saveChanges}"
onclick="PF('accessPopup').hide();"
<p:commandLink id="restrictFileButton" styleClass="btn btn-default" value="#{bundle.saveChanges}"
onclick="return false;"
action="#{bean[restrictFileAction](true)}"
update=":messagePanel" />
<button class="btn btn-link" onclick="PF('accessPopup').hide();" type="button">
#{bundle.cancel}
</button>
</button>
<p:commandLink id="restrictFileButtonREdux" styleClass="btn btn-default" value="#{bundle.saveChanges}- belrgh"
onclick="if (!testFilesSelected()) return false;"
action="#{bean[restrictFileAction](true)}"
update=":messagePanel" />

</div>
</p:dialog>

Expand Down Expand Up @@ -170,6 +179,6 @@
#{bundle.close}
</button>
</div>
</p:dialog>
</p:dialog>

</ui:composition>

0 comments on commit a849d6c

Please sign in to comment.