From 7948836af880fcef83d58f659a7c5f8b2577eeec Mon Sep 17 00:00:00 2001 From: Steven Winship <39765413+stevenwinship@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:56:20 -0400 Subject: [PATCH 1/5] Update the conditions to display image_url --- .../iq/dataverse/ThumbnailServiceWrapper.java | 21 +++++++++++-------- .../harvard/iq/dataverse/api/SearchIT.java | 8 +++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java b/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java index 542cf39cfbe..12805de0348 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java +++ b/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java @@ -5,6 +5,7 @@ */ package edu.harvard.iq.dataverse; +import edu.harvard.iq.dataverse.authorization.Permission; import edu.harvard.iq.dataverse.dataaccess.DataAccess; import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter; import edu.harvard.iq.dataverse.dataaccess.StorageIO; @@ -20,7 +21,6 @@ import jakarta.ejb.EJB; import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; import jakarta.inject.Named; /** @@ -33,9 +33,8 @@ public class ThumbnailServiceWrapper implements java.io.Serializable { private static final Logger logger = Logger.getLogger(ThumbnailServiceWrapper.class.getCanonicalName()); - - @Inject - PermissionsWrapper permissionsWrapper; + @EJB + PermissionServiceBean permissionService; @EJB DataverseServiceBean dataverseService; @EJB @@ -49,14 +48,18 @@ public class ThumbnailServiceWrapper implements java.io.Serializable { private Map dvobjectViewMap = new HashMap<>(); private Map hasThumbMap = new HashMap<>(); + private boolean hasDownloadFilePermission(DvObject dvo) { + return permissionService.on(dvo).has(Permission.DownloadFile) ; + } public String getFileCardImageAsUrl(SolrSearchResult result) { DataFile dataFile = result != null && result.getEntity() != null ? ((DataFile) result.getEntity()) : null; - if (dataFile == null || result.isHarvested() + if (dataFile == null + || result.isHarvested() || !isThumbnailAvailable(dataFile) - || dataFile.isRestricted() - || !dataFile.isReleased() + || (dataFile.isRestricted() && !hasDownloadFilePermission(dataFile)) || FileUtil.isActivelyEmbargoed(dataFile) - || FileUtil.isRetentionExpired(dataFile)) { + || FileUtil.isRetentionExpired(dataFile)) + { return null; } return SystemConfig.getDataverseSiteUrlStatic() + "/api/access/datafile/" + dataFile.getId() + "?imageThumb=true"; @@ -105,7 +108,7 @@ public String getFileCardImageAsBase64Url(SolrSearchResult result) { } if ((!((DataFile)result.getEntity()).isRestricted() - || permissionsWrapper.hasDownloadFilePermission(result.getEntity())) + || hasDownloadFilePermission(result.getEntity())) && isThumbnailAvailable((DataFile) result.getEntity())) { cardImageUrl = ImageThumbConverter.getImageThumbnailAsBase64( diff --git a/src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java b/src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java index 3a2b684c421..b03c23cd1e2 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java @@ -1308,8 +1308,8 @@ public void testSearchFilesAndUrlImages() { .statusCode(200); pathToFile = "src/main/webapp/resources/js/mydata.js"; Response uploadFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken); - uploadImage.prettyPrint(); - uploadImage.then().assertThat() + uploadFile.prettyPrint(); + uploadFile.then().assertThat() .statusCode(200); Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); @@ -1337,7 +1337,7 @@ public void testSearchFilesAndUrlImages() { .statusCode(OK.getStatusCode()) .body("data.items[0].type", CoreMatchers.is("dataverse")) .body("data.items[0].url", CoreMatchers.containsString("/dataverse/")) - .body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("url_image"))); + .body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("image_url"))); searchResp = UtilIT.search("mydata", apiToken); searchResp.prettyPrint(); @@ -1345,6 +1345,6 @@ public void testSearchFilesAndUrlImages() { .statusCode(OK.getStatusCode()) .body("data.items[0].type", CoreMatchers.is("file")) .body("data.items[0].url", CoreMatchers.containsString("/datafile/")) - .body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("url_image"))); + .body("data.items[0]", CoreMatchers.not(CoreMatchers.hasItem("image_url"))); } } From d52aa58b287994602f7342c92118dad6a085fe55 Mon Sep 17 00:00:00 2001 From: Steven Winship <39765413+stevenwinship@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:01:57 -0400 Subject: [PATCH 2/5] Update the conditions to display image_url --- .../java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java b/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java index 12805de0348..46736da73d4 100644 --- a/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java +++ b/src/main/java/edu/harvard/iq/dataverse/ThumbnailServiceWrapper.java @@ -58,8 +58,7 @@ public String getFileCardImageAsUrl(SolrSearchResult result) { || !isThumbnailAvailable(dataFile) || (dataFile.isRestricted() && !hasDownloadFilePermission(dataFile)) || FileUtil.isActivelyEmbargoed(dataFile) - || FileUtil.isRetentionExpired(dataFile)) - { + || FileUtil.isRetentionExpired(dataFile)) { return null; } return SystemConfig.getDataverseSiteUrlStatic() + "/api/access/datafile/" + dataFile.getId() + "?imageThumb=true"; From 700c39fe8cfb93e69c20ce3ed44f617b7d2ba8b3 Mon Sep 17 00:00:00 2001 From: Steven Winship <39765413+stevenwinship@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:34:08 -0400 Subject: [PATCH 3/5] add release note --- .../10886-update-to-conditions-to-display-image_url.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/release-notes/10886-update-to-conditions-to-display-image_url.md diff --git a/doc/release-notes/10886-update-to-conditions-to-display-image_url.md b/doc/release-notes/10886-update-to-conditions-to-display-image_url.md new file mode 100644 index 00000000000..03bd8299d45 --- /dev/null +++ b/doc/release-notes/10886-update-to-conditions-to-display-image_url.md @@ -0,0 +1,6 @@ +Search API (/api/search) responses for Datafiles include image_url for the thumbnail if each of the following are true: +1. The DataFile is not Harvested +2. A Thumbnail is available for the Datafile +3. If the Datafile is Restricted then the caller must have Download File Permission for the Datafile +4. The Datafile is NOT actively embargoed +5. The Datafile's retention is NOT expired From 48dead84d3ce2d7b093eb1b1c6e39e475cd9aa9a Mon Sep 17 00:00:00 2001 From: Steven Winship <39765413+stevenwinship@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:35:11 -0400 Subject: [PATCH 4/5] add release note --- .../10886-update-to-conditions-to-display-image_url.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/release-notes/10886-update-to-conditions-to-display-image_url.md b/doc/release-notes/10886-update-to-conditions-to-display-image_url.md index 03bd8299d45..a7adda11840 100644 --- a/doc/release-notes/10886-update-to-conditions-to-display-image_url.md +++ b/doc/release-notes/10886-update-to-conditions-to-display-image_url.md @@ -3,4 +3,4 @@ Search API (/api/search) responses for Datafiles include image_url for the thumb 2. A Thumbnail is available for the Datafile 3. If the Datafile is Restricted then the caller must have Download File Permission for the Datafile 4. The Datafile is NOT actively embargoed -5. The Datafile's retention is NOT expired +5. The Datafile's retention has NOT expired From cb6e44f0d58f72aea6bae7476d85fa79ca2b31b7 Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Wed, 2 Oct 2024 15:15:25 -0400 Subject: [PATCH 5/5] tweak release note #10875 --- .../10886-update-to-conditions-to-display-image_url.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/release-notes/10886-update-to-conditions-to-display-image_url.md b/doc/release-notes/10886-update-to-conditions-to-display-image_url.md index a7adda11840..6dfe8eb9f2d 100644 --- a/doc/release-notes/10886-update-to-conditions-to-display-image_url.md +++ b/doc/release-notes/10886-update-to-conditions-to-display-image_url.md @@ -3,4 +3,6 @@ Search API (/api/search) responses for Datafiles include image_url for the thumb 2. A Thumbnail is available for the Datafile 3. If the Datafile is Restricted then the caller must have Download File Permission for the Datafile 4. The Datafile is NOT actively embargoed -5. The Datafile's retention has NOT expired +5. The Datafile's retention period has NOT expired + +See also #10875 and #10886.