Fixing authorship refs #23851

This commit is contained in:
Luca Frosini 2022-09-28 17:43:26 +02:00
parent f13b62872f
commit 52fe1929f8
1 changed files with 25 additions and 4 deletions

View File

@ -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)) {