From 52fe1929f85ff37bcebc40afe067c79f722097b3 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 28 Sep 2022 17:43:26 +0200 Subject: [PATCH] Fixing authorship refs #23851 --- .../gcat/persistence/ckan/CKANPackage.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 5ee97d1..97c8c7e 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -220,6 +220,30 @@ public class CKANPackage extends CKAN implements Moderated { return getAsString(jsonNode); } + /* + * Desired behaviuor + * + * - when a user with a role < Catalogue-Admin updates his/her own records the author information should remain unchanged also when it is specified; + * - when a user with a role <= Catalogue-Admin updates a record he/she must be allowed to modify author information, thus if author information is specified it should be used to modify the item. + * + * Reference https://support.d4science.org/issues/23851 + * + */ + public ObjectNode checkAuthor(ObjectNode objectNode, String authorName, String authorEmail) { + if(!updateOperation) { // this prevent to change the original author in case of update + objectNode.put(AUTHOR_KEY, authorName); + objectNode.put(AUTHOR_EMAIL_KEY, authorEmail); + }else { + Role role = ckanUser.getRole(); + if(role.ordinal() < Role.ADMIN.ordinal()) { + objectNode.remove(AUTHOR_KEY); + objectNode.remove(AUTHOR_EMAIL_KEY); + } + } + return objectNode; + } + + /** * @param json The json to check * @param allowPartialInfo used for patch method which provide only partial information (i.e. the info to patch) @@ -294,10 +318,7 @@ public class CKANPackage extends CKAN implements Moderated { String authorEmail = ckanUser.getEMail(); - if(!updateOperation) { // this prevent to change the original author in case of update - objectNode.put(AUTHOR_KEY, authorName); - objectNode.put(AUTHOR_EMAIL_KEY, authorEmail); - } + objectNode = checkAuthor(objectNode, authorName, authorEmail); if(!objectNode.has(MAINTAINER_KEY)) {