Skip to content

Commit fdcdba2

Browse files
authored
Merge pull request #11693 from IQSS/revert-11636-11465-api-fetch-download-size-file-count
Revert #11636 "Bug: block guest from calling api"
2 parents 88b3f0b + eb1ee7e commit fdcdba2

File tree

7 files changed

+7
-148
lines changed

7 files changed

+7
-148
lines changed

doc/release-notes/11465-api-fetch-download-size-file-count.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,6 @@ The returned file counts are based on different criteria:
18401840
- Per tabular tag name
18411841
- Per access status (Possible values: Public, Restricted, EmbargoedThenRestricted, EmbargoedThenPublic, RetentionPeriodExpired)
18421842

1843-
Note: Authentication is required. This call will return a 403/Forbidden response for Guest users.
1844-
18451843
.. code-block:: bash
18461844
18471845
export SERVER_URL=https://demo.dataverse.org
@@ -2823,7 +2821,6 @@ Get the size of Downloading all the files of a Dataset Version
28232821
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28242822

28252823
Shows the combined size in bytes of all the files available for download from version ``versionId`` of dataset ``id``.
2826-
Note: Authentication is required. This call will return a 403/Forbidden response for Guest users.
28272824

28282825
.. code-block:: bash
28292826

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,6 @@ public Response getVersionFileCounts(@Context ContainerRequestContext crc,
574574
@QueryParam("includeDeaccessioned") boolean includeDeaccessioned,
575575
@Context UriInfo uriInfo,
576576
@Context HttpHeaders headers) {
577-
try {
578-
getRequestAuthenticatedUserOrDie(crc);
579-
} catch (WrappedResponse e) {
580-
return forbidden(BundleUtil.getStringFromBundle("datasets.api.version.files.invalid.auth"));
581-
}
582577
return response(req -> {
583578
FileSearchCriteria fileSearchCriteria;
584579
try {
@@ -3548,11 +3543,7 @@ public Response getDownloadSize(@Context ContainerRequestContext crc,
35483543
@QueryParam("includeDeaccessioned") boolean includeDeaccessioned,
35493544
@Context UriInfo uriInfo,
35503545
@Context HttpHeaders headers) {
3551-
try {
3552-
getRequestAuthenticatedUserOrDie(crc);
3553-
} catch (WrappedResponse e) {
3554-
return forbidden(BundleUtil.getStringFromBundle("datasets.api.version.files.invalid.auth"));
3555-
}
3546+
35563547
return response(req -> {
35573548
FileSearchCriteria fileSearchCriteria;
35583549
try {

src/main/java/propertyFiles/Bundle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,6 @@ datasets.api.curationstatuscreatetime=Status Set Time
28342834
datasets.api.curationstatussetter=Status Set By
28352835
datasets.api.version.files.invalid.order.criteria=Invalid order criteria: {0}
28362836
datasets.api.version.files.invalid.access.status=Invalid access status: {0}
2837-
datasets.api.version.files.invalid.auth=Only authenticated users can access this information.
28382837
datasets.api.deaccessionDataset.invalid.version.identifier.error=Only {0} or a specific version can be deaccessioned
28392838
datasets.api.deaccessionDataset.invalid.forward.url=Invalid deaccession forward URL: {0}
28402839
datasets.api.globusdownloaddisabled=File transfer from Dataverse via Globus is not available for this dataset.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5617,10 +5617,10 @@ public void getVersionFileCounts() throws IOException, InterruptedException {
56175617
// Test that the dataset file counts for a deaccessioned dataset cannot be accessed by a guest
56185618
// By latest published version
56195619
Response getDatasetVersionResponse = UtilIT.getVersionFileCounts(datasetId, DS_VERSION_LATEST_PUBLISHED, null, null, null, null, null, true, null);
5620-
getDatasetVersionResponse.then().assertThat().statusCode(FORBIDDEN.getStatusCode());
5620+
getDatasetVersionResponse.then().assertThat().statusCode(NOT_FOUND.getStatusCode());
56215621
// By specific version 1.0
56225622
getDatasetVersionResponse = UtilIT.getVersionFileCounts(datasetId, "1.0", null, null, null, null, null, true, null);
5623-
getDatasetVersionResponse.then().assertThat().statusCode(FORBIDDEN.getStatusCode());
5623+
getDatasetVersionResponse.then().assertThat().statusCode(NOT_FOUND.getStatusCode());
56245624
}
56255625

56265626
@Test
@@ -5856,10 +5856,10 @@ public void getDownloadSize() throws IOException, InterruptedException {
58565856
// Test that the dataset file counts for a deaccessioned dataset cannot be accessed by a guest
58575857
// By latest published version
58585858
Response getVersionFileCountsGuestUserResponse = UtilIT.getDownloadSize(datasetId, DS_VERSION_LATEST_PUBLISHED, null, null, null, null, null, DatasetVersionFilesServiceBean.FileDownloadSizeMode.All.toString(), true, null);
5859-
getVersionFileCountsGuestUserResponse.then().assertThat().statusCode(FORBIDDEN.getStatusCode());
5859+
getVersionFileCountsGuestUserResponse.then().assertThat().statusCode(NOT_FOUND.getStatusCode());
58605860
// By specific version 1.0
58615861
getVersionFileCountsGuestUserResponse = UtilIT.getDownloadSize(datasetId, "1.0", null, null, null, null, null, DatasetVersionFilesServiceBean.FileDownloadSizeMode.All.toString(), true, null);
5862-
getVersionFileCountsGuestUserResponse.then().assertThat().statusCode(FORBIDDEN.getStatusCode());
5862+
getVersionFileCountsGuestUserResponse.then().assertThat().statusCode(NOT_FOUND.getStatusCode());
58635863
}
58645864

58655865
@Test

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

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,90 +1440,13 @@ public void testDataSizeInDataverse() throws InterruptedException {
14401440

14411441
magicControlString = MessageFormat.format(BundleUtil.getStringFromBundle("datasets.api.datasize.download"), magicSizeNumber);
14421442

1443-
Response datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId.toString(), apiTokenRando, null, null, null);
1443+
Response datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId.toString());
14441444
datasetDownloadSizeResponse.prettyPrint();
14451445

14461446
assertEquals(magicControlString, JsonPath.from(datasetDownloadSizeResponse.body().asString()).getString("data.message"));
14471447

14481448
}
14491449

1450-
@Test
1451-
public void testDeaccessionedDatasetGetDownloadSize() {
1452-
// Create user
1453-
String apiToken = createUserGetToken();
1454-
// Create Dataverse
1455-
String dataverseAlias = createDataverseGetAlias(apiToken);
1456-
// Create Dataset
1457-
String datasetId1 = createDatasetGetId(dataverseAlias, apiToken).toString();
1458-
String datasetId2 = createDatasetGetId(dataverseAlias, apiToken).toString();
1459-
String pathToFile = "scripts/search/data/binary/trees.png";
1460-
Response addResponse = UtilIT.uploadFileViaNative(datasetId1, pathToFile, apiToken);
1461-
1462-
// Publish
1463-
UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken);
1464-
UtilIT.publishDatasetViaNativeApi(datasetId1, "major", apiToken);
1465-
UtilIT.publishDatasetViaNativeApi(datasetId2, "major", apiToken);
1466-
1467-
// Test get sizes from Published Dataset with no files
1468-
Response datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId2, apiToken, null, Boolean.TRUE, null);
1469-
datasetDownloadSizeResponse.prettyPrint();
1470-
datasetDownloadSizeResponse.then().assertThat()
1471-
.body("data.message", containsString("0 bytes"))
1472-
.body("data.storageSize", equalTo(0))
1473-
.statusCode(OK.getStatusCode());
1474-
// Test get files count from Published Dataset with no files
1475-
Response datasetFilesCountResponse = UtilIT.findDatasetFilesCount(datasetId2, apiToken, null, Boolean.TRUE);
1476-
datasetFilesCountResponse.prettyPrint();
1477-
datasetFilesCountResponse.then().assertThat()
1478-
.body("data.total", equalTo(0))
1479-
.statusCode(OK.getStatusCode());
1480-
1481-
// Deaccession the Dataset
1482-
UtilIT.deaccessionDataset(datasetId1, "1.0", "reason", null, apiToken).prettyPrint();
1483-
UtilIT.deaccessionDataset(datasetId2, "1.0", "reason", null, apiToken).prettyPrint();
1484-
1485-
// Test get sizes from Deaccessioned Dataset with files (Auth user)
1486-
datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId1, apiToken, null, Boolean.TRUE, "Archival");
1487-
datasetDownloadSizeResponse.prettyPrint();
1488-
datasetDownloadSizeResponse.then().assertThat()
1489-
.body("data.message", containsString("8,361 bytes"))
1490-
.body("data.storageSize", equalTo(8361))
1491-
.statusCode(OK.getStatusCode());
1492-
// Test get sizes from Deaccessioned Dataset with files (Guest user)
1493-
datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId1, null, null, Boolean.TRUE, "Archival");
1494-
datasetDownloadSizeResponse.prettyPrint();
1495-
datasetDownloadSizeResponse.then().assertThat()
1496-
.statusCode(FORBIDDEN.getStatusCode())
1497-
.body("message", equalTo(BundleUtil.getStringFromBundle("datasets.api.version.files.invalid.auth")));
1498-
1499-
// Test get sizes from Deaccessioned Dataset with no files (Auth user)
1500-
datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId2, apiToken, null, Boolean.TRUE, "Archival");
1501-
datasetDownloadSizeResponse.prettyPrint();
1502-
datasetDownloadSizeResponse.then().assertThat()
1503-
.body("data.message", containsString("0 bytes"))
1504-
.body("data.storageSize", equalTo(0))
1505-
.statusCode(OK.getStatusCode());
1506-
// Test get sizes from Deaccessioned Dataset with no files (Guest user)
1507-
datasetDownloadSizeResponse = UtilIT.findDatasetDownloadSize(datasetId2, null, null, Boolean.TRUE, "Archival");
1508-
datasetDownloadSizeResponse.prettyPrint();
1509-
datasetDownloadSizeResponse.then().assertThat()
1510-
.statusCode(FORBIDDEN.getStatusCode())
1511-
.body("message", equalTo(BundleUtil.getStringFromBundle("datasets.api.version.files.invalid.auth")));
1512-
1513-
// Test get files count from Deaccessioned Dataset with no files (Auth user)
1514-
datasetFilesCountResponse = UtilIT.findDatasetFilesCount(datasetId2, apiToken, null, Boolean.TRUE);
1515-
datasetFilesCountResponse.prettyPrint();
1516-
datasetFilesCountResponse.then().assertThat()
1517-
.body("data.total", equalTo(0))
1518-
.statusCode(OK.getStatusCode());
1519-
// Test get files count from Deaccessioned Dataset with no files (Guest user)
1520-
datasetFilesCountResponse = UtilIT.findDatasetFilesCount(datasetId2, null, null, Boolean.TRUE);
1521-
datasetFilesCountResponse.prettyPrint();
1522-
datasetFilesCountResponse.then().assertThat()
1523-
.statusCode(FORBIDDEN.getStatusCode())
1524-
.body("message", equalTo(BundleUtil.getStringFromBundle("datasets.api.version.files.invalid.auth")));
1525-
}
1526-
15271450
@Test
15281451
public void GetFileVersionDifferences() {
15291452
// Create superuser and regular user

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

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,54 +3732,7 @@ static Response findDatasetDownloadSize(String datasetId, String version, Strin
37323732
.header(API_TOKEN_HTTP_HEADER, apiToken)
37333733
.get("/api/datasets/" + datasetId + "/versions/" + version + "/downloadsize");
37343734
}
3735-
3736-
static Response findDatasetDownloadSize(String datasetId, String apiToken, String version, Boolean includeDeaccessioned, String mode) {
3737-
String id = datasetId;
3738-
if (version == null) {
3739-
version = ":latest-published";
3740-
}
3741-
RequestSpecification requestSpecification = given();
3742-
3743-
if (datasetId.startsWith("doi:")) {
3744-
id = ":persistentId";
3745-
requestSpecification.queryParam("persistentId", datasetId);
3746-
}
3747-
if (includeDeaccessioned != null) {
3748-
requestSpecification.queryParam("includeDeaccessioned", includeDeaccessioned);
3749-
}
3750-
if (mode != null) {
3751-
requestSpecification.queryParam("mode", mode);
3752-
}
3753-
3754-
if (apiToken != null) {
3755-
requestSpecification.header(UtilIT.API_TOKEN_HTTP_HEADER, apiToken);
3756-
}
3757-
return requestSpecification
3758-
.get("/api/datasets/" + id + "/versions/" + version + "/downloadsize");
3759-
}
3760-
3761-
static Response findDatasetFilesCount(String datasetId, String apiToken, String version, Boolean includeDeaccessioned) {
3762-
String id = datasetId;
3763-
if (version == null) {
3764-
version = ":latest-published";
3765-
}
3766-
RequestSpecification requestSpecification = given();
3767-
3768-
if (datasetId.startsWith("doi:")) {
3769-
id = ":persistentId";
3770-
requestSpecification.queryParam("persistentId", datasetId);
3771-
}
3772-
if (includeDeaccessioned != null) {
3773-
requestSpecification.queryParam("includeDeaccessioned", includeDeaccessioned);
3774-
}
3775-
3776-
if (apiToken != null) {
3777-
requestSpecification.header(UtilIT.API_TOKEN_HTTP_HEADER, apiToken);
3778-
}
3779-
return requestSpecification
3780-
.get("/api/datasets/" + id + "/versions/" + version + "/files/counts");
3781-
}
3782-
3735+
37833736
static Response addBannerMessage(String pathToJsonFile) {
37843737
String jsonIn = getDatasetJson(pathToJsonFile);
37853738

0 commit comments

Comments
 (0)