Skip to content

Commit e3b82e4

Browse files
authored
Merge pull request #11422 from IQSS/11415-app-tou
add API for getting application terms of use
2 parents ff42ebd + 26b9be7 commit e3b82e4

File tree

9 files changed

+145
-15
lines changed

9 files changed

+145
-15
lines changed

doc/release-notes/11415-app-tou.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Application Terms of Use Available via API
2+
3+
It's now possible to retrieve the Application Terms of Use (called General Terms of Use in the UI) via API. These are the terms users agree to when creating an account. See [the guides](https://dataverse-guide--11422.org.readthedocs.build/en/11422/api/native-api.html#get-application-terms-of-use-general-terms-of-use), #11415 and #11422.

doc/sphinx-guides/source/admin/metadatacustomization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ FieldType definitions
312312
| | permitted, only a subset of HTML |
313313
| | tags will be rendered in the UI. |
314314
| | See the |
315-
| | :ref:`supported-html-fields` |
315+
| | :ref:`supported-html-tags` |
316316
| | section of the Dataset + File |
317317
| | Management page in the User Guide. |
318318
+---------------+------------------------------------+

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5544,6 +5544,28 @@ The fully expanded example above (without environment variables) looks like this
55445544
55455545
curl "https://demo.dataverse.org/api/info/settings/:DatasetPublishPopupCustomText"
55465546
5547+
.. _api-get-app-tou:
5548+
5549+
Get Application Terms of Use (General Terms of Use)
5550+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5551+
5552+
In the UI, Application Terms of Use is called "General Terms of Use" and can be seen when you sign up for an account. The terms come from the database setting :ref:`:ApplicationTermsOfUse`. If you have enabled :ref:`i18n` you can pass a two-character language code (e.g. "en") as the ``lang`` parameter.
5553+
5554+
.. note:: See :ref:`curl-examples-and-environment-variables` if you are unfamiliar with the use of export below.
5555+
5556+
.. code-block:: bash
5557+
5558+
export SERVER_URL=https://demo.dataverse.org
5559+
export LANG=en
5560+
5561+
curl "$SERVER_URL/api/info/applicationTermsOfUse?lang=$LANG"
5562+
5563+
The fully expanded example above (without environment variables) looks like this:
5564+
5565+
.. code-block:: bash
5566+
5567+
curl "https://demo.dataverse.org/api/info/applicationTermsOfUse?lang=en"
5568+
55475569
Get API Terms of Use URL
55485570
~~~~~~~~~~~~~~~~~~~~~~~~
55495571

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3921,22 +3921,31 @@ If you don't want the datafiles to be validated on publish, set:
39213921

39223922
``curl -X PUT -d 'false' http://localhost:8080/api/admin/settings/:FileValidationOnPublishEnabled``
39233923

3924+
.. _:ApplicationTermsOfUse:
39243925

39253926
:ApplicationTermsOfUse
39263927
++++++++++++++++++++++
39273928

3928-
Upload an default language HTML file containing the Terms of Use to be displayed at sign up. Supported HTML tags are listed under the :doc:`/user/dataset-management` section of the User Guide.
3929+
Application Terms of Use (called "General Terms of Use" in the UI) are shown to the user when they sign up for an account. Some HTML tags are supported. For a list, see :ref:`supported-html-tags` in the User Guide.
39293930

3930-
``curl -X PUT -d@/tmp/apptou.html http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse``
3931+
You can set terms like this:
39313932

3932-
To upload a language specific Terms of Use file,
3933+
``curl -X PUT http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse --upload-file /tmp/apptou.html``
39333934

3934-
``curl -X PUT -d@/tmp/apptou_fr.html http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr``
3935+
To delete terms:
39353936

3936-
To delete language specific option,
3937+
``curl -X DELETE http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse``
3938+
3939+
If :ref:`i18n` is enabled, you can set the terms per language. To set terms for a specific language ("fr", for example):
3940+
3941+
``curl -X PUT http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr --upload-file /tmp/apptou_fr.html``
3942+
3943+
To delete terms for a specific language ("fr", for example):
39373944

39383945
``curl -X DELETE http://localhost:8080/api/admin/settings/:ApplicationTermsOfUse/lang/fr``
39393946

3947+
To retrieve the values, see :ref:`api-get-app-tou` in the API Guide.
3948+
39403949
:ApplicationPrivacyPolicyUrl
39413950
++++++++++++++++++++++++++++
39423951

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Adding a New Dataset
6464

6565
Note: You can add additional metadata once you have completed the initial dataset creation by going to clicking the Edit button and selecting Metadata from the dropdown menu.
6666

67-
.. _supported-html-fields:
67+
.. _supported-html-tags:
6868

69-
Supported HTML Fields
70-
---------------------
69+
Supported HTML Tags
70+
-------------------
7171

7272
We currently only support the following HTML tags for any of our textbox metadata fields (i.e., Description) : <a>, <b>, <blockquote>,
7373
<br>, <code>, <del>, <dd>, <dl>, <dt>, <em>, <hr>, <h1>-<h3>, <i>, <img>, <kbd>, <li>, <ol>, <p>, <pre>, <s>, <sup>, <sub>,

src/main/java/edu/harvard/iq/dataverse/api/Info.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
import jakarta.json.JsonValue;
2727
import jakarta.ws.rs.GET;
2828
import jakarta.ws.rs.Path;
29-
import jakarta.ws.rs.PathParam;
29+
import jakarta.ws.rs.QueryParam;
3030
import jakarta.ws.rs.core.MediaType;
3131
import jakarta.ws.rs.core.Response;
3232
import org.eclipse.microprofile.openapi.annotations.Operation;
33+
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
34+
import org.eclipse.microprofile.openapi.annotations.media.Schema;
35+
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
3336
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
3437
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
3538

@@ -78,6 +81,19 @@ public Response getServer() {
7881
return ok(JvmSettings.FQDN.lookup());
7982
}
8083

84+
@GET
85+
@Path("applicationTermsOfUse")
86+
@APIResponse(responseCode = "200",
87+
description = "Application Terms of Use (General Terms of Use) that must be agreed to at signup.")
88+
public Response getApplicationTermsOfUse(
89+
@Parameter(description = "Two-character language code.",
90+
required = false,
91+
example = "en",
92+
schema = @Schema(type = SchemaType.STRING))
93+
@QueryParam("lang") String lang) {
94+
return ok(systemConfig.getApplicationTermsOfUse(lang));
95+
}
96+
8197
@GET
8298
@Path("apiTermsOfUse")
8399
public Response getTermsOfUse() {

src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,24 @@ public boolean isThumbnailGenerationDisabledForPDF() {
428428
}
429429

430430
public String getApplicationTermsOfUse() {
431-
String language = BundleUtil.getCurrentLocale().getLanguage();
431+
return getApplicationTermsOfUse(null);
432+
}
433+
434+
public String getApplicationTermsOfUse(String languageIn) {
435+
String language = null;
436+
if (languageIn != null) {
437+
language = languageIn;
438+
} else {
439+
language = BundleUtil.getCurrentLocale().getLanguage();
440+
}
432441
String saneDefaultForAppTermsOfUse = BundleUtil.getStringFromBundle("system.app.terms");
433-
// Get the value for the defaultLocale. IT will either be used as the return
442+
// Get the value for the defaultLocale. It will either be used as the return
434443
// value, or as a better default than the saneDefaultForAppTermsOfUse if there
435444
// is no language-specific value
436445
String appTermsOfUse = settingsService.getValueForKey(SettingsServiceBean.Key.ApplicationTermsOfUse, saneDefaultForAppTermsOfUse);
437-
//Now get the language-specific value if it exists
446+
// Now get the language-specific value if it exists
438447
if (language != null && !language.equalsIgnoreCase(BundleUtil.getDefaultLocale().getLanguage())) {
439-
appTermsOfUse = settingsService.getValueForKey(SettingsServiceBean.Key.ApplicationTermsOfUse, language, appTermsOfUse);
448+
appTermsOfUse = settingsService.getValueForKey(SettingsServiceBean.Key.ApplicationTermsOfUse, language, appTermsOfUse);
440449
}
441450
return appTermsOfUse;
442451
}

src/test/java/edu/harvard/iq/dataverse/api/InfoIT.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static io.restassured.RestAssured.given;
44
import io.restassured.response.Response;
55
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
6+
import edu.harvard.iq.dataverse.util.BundleUtil;
67
import org.junit.jupiter.api.AfterAll;
78
import org.junit.jupiter.api.BeforeAll;
89
import org.junit.jupiter.api.Test;
@@ -13,6 +14,7 @@
1314
import java.nio.file.Paths;
1415
import static org.hamcrest.CoreMatchers.equalTo;
1516
import static org.hamcrest.CoreMatchers.notNullValue;
17+
import org.junit.jupiter.api.Disabled;
1618
import org.skyscreamer.jsonassert.JSONAssert;
1719

1820
public class InfoIT {
@@ -21,6 +23,8 @@ public class InfoIT {
2123
public static void setUpClass() {
2224
UtilIT.deleteSetting(SettingsServiceBean.Key.MaxEmbargoDurationInMonths);
2325
UtilIT.deleteSetting(SettingsServiceBean.Key.DatasetPublishPopupCustomText);
26+
UtilIT.deleteSetting(SettingsServiceBean.Key.ApplicationTermsOfUse);
27+
UtilIT.deleteSetting(SettingsServiceBean.Key.ApplicationTermsOfUse, "fr");
2428
}
2529

2630
@AfterAll
@@ -58,7 +62,52 @@ public void testGetServer() {
5862
}
5963

6064
@Test
61-
public void testGetTermsOfUse() {
65+
public void testGetAppTermsOfUse() {
66+
Response getTermsUnset = UtilIT.getAppTermsOfUse();
67+
getTermsUnset.prettyPrint();
68+
getTermsUnset.then().assertThat().statusCode(OK.getStatusCode())
69+
.body("data.message", equalTo(BundleUtil.getStringFromBundle("system.app.terms")));
70+
71+
String terms = "Be excellent to each other.";
72+
73+
Response setTerms = UtilIT.setSetting(SettingsServiceBean.Key.ApplicationTermsOfUse, terms);
74+
setTerms.prettyPrint();
75+
setTerms.then().assertThat().statusCode(OK.getStatusCode());
76+
77+
Response getTermsSet = UtilIT.getAppTermsOfUse();
78+
getTermsSet.prettyPrint();
79+
getTermsSet.then().assertThat().statusCode(OK.getStatusCode())
80+
.body("data.message", equalTo(terms));
81+
82+
Response getTermsEn = UtilIT.getAppTermsOfUse("en");
83+
getTermsEn.prettyPrint();
84+
getTermsEn.then().assertThat().statusCode(OK.getStatusCode())
85+
.body("data.message", equalTo(terms));
86+
}
87+
88+
/**
89+
* Disabled because internationalization isn't set up.
90+
*/
91+
@Disabled
92+
@Test
93+
public void testGetAppTermsOfUseFrench() {
94+
Response getTermsUnsetFr = UtilIT.getAppTermsOfUse("fr");
95+
getTermsUnsetFr.prettyPrint();
96+
getTermsUnsetFr.then().assertThat().statusCode(OK.getStatusCode())
97+
.body("data.message", equalTo(BundleUtil.getStringFromBundle("system.app.terms")));
98+
99+
Response setTermsFr = UtilIT.setSetting(SettingsServiceBean.Key.ApplicationTermsOfUse, "Appelez-moi.", "fr");
100+
setTermsFr.prettyPrint();
101+
setTermsFr.then().assertThat().statusCode(OK.getStatusCode());
102+
103+
Response getTermsFr = UtilIT.getAppTermsOfUse("fr");
104+
getTermsFr.prettyPrint();
105+
getTermsFr.then().assertThat().statusCode(OK.getStatusCode())
106+
.body("data.message", equalTo("Appelez-moi."));
107+
}
108+
109+
@Test
110+
public void testGetApiTermsOfUse() {
62111
Response response = given().urlEncodingEnabled(false)
63112
.get("/api/info/apiTermsOfUse");
64113
response.prettyPrint();

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,11 @@ static Response deleteSetting(SettingsServiceBean.Key settingKey) {
23982398
return response;
23992399
}
24002400

2401+
static Response deleteSetting(SettingsServiceBean.Key settingKey, String language) {
2402+
Response response = given().when().delete("/api/admin/settings/" + settingKey + "/lang/" + language);
2403+
return response;
2404+
}
2405+
24012406
/**
24022407
* @param settingKey Include the colon like :BagItLocalPath
24032408
*/
@@ -2416,6 +2421,11 @@ static Response setSetting(SettingsServiceBean.Key settingKey, String value) {
24162421
return response;
24172422
}
24182423

2424+
static Response setSetting(SettingsServiceBean.Key settingKey, String value, String language) {
2425+
Response response = given().body(value).when().put("/api/admin/settings/" + settingKey + "/lang/" + language);
2426+
return response;
2427+
}
2428+
24192429
/**
24202430
* @param settingKey Include the colon like :BagItLocalPath
24212431
*/
@@ -2861,6 +2871,18 @@ static Response downloadFromUrl(String url) {
28612871
return given().get(url);
28622872
}
28632873

2874+
static Response getAppTermsOfUse() {
2875+
return getAppTermsOfUse(null);
2876+
}
2877+
2878+
static Response getAppTermsOfUse(String lang) {
2879+
String optionalLang = "";
2880+
if (lang != null) {
2881+
optionalLang = "?lang=" + lang;
2882+
}
2883+
return given().get("/api/info/applicationTermsOfUse" + optionalLang);
2884+
}
2885+
28642886
static Response metricsDataversesToMonth(String yyyymm, String queryParams) {
28652887
String optionalYyyyMm = "";
28662888
if (yyyymm != null) {

0 commit comments

Comments
 (0)