From 85af55f8f1a6dfe0165a28d425cdcc6f51f6ea2d Mon Sep 17 00:00:00 2001 From: Steven Winship <39765413+stevenwinship@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:45:06 -0400 Subject: [PATCH] change how hierarchy works --- .../10981-published-datasets-should-contain-files.md | 8 +++++--- doc/sphinx-guides/source/api/native-api.rst | 2 +- src/main/java/edu/harvard/iq/dataverse/Dataverse.java | 9 +++++++++ .../engine/command/impl/PublishDatasetCommand.java | 9 +++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/doc/release-notes/10981-published-datasets-should-contain-files.md b/doc/release-notes/10981-published-datasets-should-contain-files.md index 74c932f853a..964e7ff1937 100644 --- a/doc/release-notes/10981-published-datasets-should-contain-files.md +++ b/doc/release-notes/10981-published-datasets-should-contain-files.md @@ -1,7 +1,9 @@ ## Feature: Prevent publishing Datasets without files -A new attribute was added to Collections in order to control the publishing of Datasets without files. Once set, the publishing of a Dataset within a Collection or Collection's hierarchy, without files, will be blocked for all non superusers. -In order to configure a Collection to block publishing a superuser must set the attribute "requireFilesToPublishDataset" to true. -Any Collection created under a Collection with this attribute will also be bound by this blocking. Setting this attribute on the Root Dataverse will essentially block the publishing of Datasets without files for the entire installation. +A new attribute was added to Collections in order to control the publishing of Datasets without files. +Once set to "True", the publishing of a Dataset within a Collection, without files, will be blocked for all non superusers. +In order to configure a Collection to block publishing a superuser must set the attribute "requireFilesToPublishDataset" to "True". +The collection's hierarchy will be checked if the collection's "requireFilesToPublishDataset" attribute is not set explicitly to "True" or "False". + ```shell curl -X PUT -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/dataverses/$ID/attribute/requireFilesToPublishDataset?value=true" ``` diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index d174d4a87cd..8d73dd9dd24 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -1005,7 +1005,7 @@ The following attributes are supported: * ``description`` Description * ``affiliation`` Affiliation * ``filePIDsEnabled`` ("true" or "false") Restricted to use by superusers and only when the :ref:`:AllowEnablingFilePIDsPerCollection <:AllowEnablingFilePIDsPerCollection>` setting is true. Enables or disables registration of file-level PIDs in datasets within the collection (overriding the instance-wide setting). -* ``requireFilesToPublishDataset`` ("true" or "false") Dataset needs files in order to be published. Restricted to use by superusers. If any TRUE found in the ownership tree publishing will be blocked. Publishing by a superusers will not be blocked. +* ``requireFilesToPublishDataset`` ("true" or "false") Restricted to use by superusers. Defines if Dataset needs files in order to be published. If not set the determination will be made through inheritance by checking the owners of this collection. Publishing by a superusers will not be blocked. .. _collection-storage-quotas: diff --git a/src/main/java/edu/harvard/iq/dataverse/Dataverse.java b/src/main/java/edu/harvard/iq/dataverse/Dataverse.java index 3bbf02fd611..5b6fbdee6ba 100644 --- a/src/main/java/edu/harvard/iq/dataverse/Dataverse.java +++ b/src/main/java/edu/harvard/iq/dataverse/Dataverse.java @@ -605,6 +605,15 @@ public void setCitationDatasetFieldTypes(List citationDatasetF @Column(nullable = true) private Boolean requireFilesToPublishDataset; + /** + * Specifies whether the existance of files in a dataset is required when publishing + * @return {@code Boolean.TRUE} if explicitly enabled, {@code Boolean.FALSE} if explicitly disabled. + * {@code null} indicates that the behavior is not explicitly defined, in which + * case the behavior should follow the explicit configuration of the first + * direct ancestor collection. + * @Note: If present, this configuration therefore by default applies to all + * the sub-collections, unless explicitly overwritten there. + */ public Boolean getRequireFilesToPublishDataset() { return requireFilesToPublishDataset; } diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java index dfe2bb44b20..50800f72271 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java @@ -230,11 +230,12 @@ private void verifyCommandArguments(CommandContext ctxt) throws IllegalCommandEx } private boolean requiresFilesToPublishDataset() { if (!getUser().isSuperuser()) { - List owners = getDataset().getOwner().getOwners(); - for(Dataverse owner : owners) { - if (owner.getRequireFilesToPublishDataset() != null && owner.getRequireFilesToPublishDataset()) { - return true; + Dataverse parent = getDataset().getOwner(); + while (parent != null) { + if (parent.getRequireFilesToPublishDataset() != null) { + return parent.getRequireFilesToPublishDataset(); } + parent = parent.getOwner(); } } return false;