Allowing Catalogue-Managers to keep Moderation Extra Properties
This commit is contained in:
parent
e6856b7653
commit
9b7a08d66b
|
@ -17,6 +17,7 @@ import javax.ws.rs.InternalServerErrorException;
|
|||
import javax.ws.rs.NotAllowedException;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.http.MethodNotSupportedException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
|
@ -129,6 +130,17 @@ public class CKANPackage extends CKAN implements Moderated {
|
|||
|
||||
protected ModerationThread moderationThread;
|
||||
|
||||
/**
|
||||
* By default extra properties used for moderation are removed
|
||||
* from the item representation.
|
||||
* So that, the default value of this field is false.
|
||||
*
|
||||
* A Catalogue-Manager can request to keep such properties
|
||||
* for debugging purposes.
|
||||
*
|
||||
*/
|
||||
protected boolean keepModerationExtraProperties;
|
||||
|
||||
public CKANPackage() {
|
||||
super();
|
||||
|
||||
|
@ -146,6 +158,14 @@ public class CKANPackage extends CKAN implements Moderated {
|
|||
ckanUser = CKANUserCache.getCurrrentCKANUser();
|
||||
|
||||
updateOperation = false;
|
||||
keepModerationExtraProperties = true;
|
||||
|
||||
}
|
||||
|
||||
public void setKeepModerationExtraProperties(boolean keepModerationExtraProperties) {
|
||||
if(ckanUser.getRole().ordinal()>=Role.MANAGER.ordinal() && keepModerationExtraProperties) {
|
||||
this.keepModerationExtraProperties = keepModerationExtraProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -192,9 +212,12 @@ public class CKANPackage extends CKAN implements Moderated {
|
|||
|
||||
// Removing all Content Moderation Keys
|
||||
if(jsonNode.has(EXTRAS_KEY)) {
|
||||
if(ckanUser.getRole().ordinal()>=Role.MANAGER.ordinal() && keepModerationExtraProperties) {
|
||||
logger.trace("The user is a {} which requested to keep Moderation extra properties.", ckanUser.getRole());
|
||||
}else {
|
||||
ArrayNode extras = (ArrayNode) jsonNode.get(EXTRAS_KEY);
|
||||
// It is not possible to remove the element of an array while iterating it.
|
||||
// We need to create a new array only with valie elements;
|
||||
// We need to create a new array only with valid elements;
|
||||
ArrayNode newExtras = mapper.createArrayNode();
|
||||
boolean foundOne = false;
|
||||
for(int i=0; i<extras.size(); i++) {
|
||||
|
@ -212,6 +235,7 @@ public class CKANPackage extends CKAN implements Moderated {
|
|||
((ObjectNode) jsonNode).replace(EXTRAS_KEY, newExtras);
|
||||
}
|
||||
}
|
||||
}
|
||||
return jsonNode;
|
||||
}
|
||||
|
||||
|
@ -806,6 +830,9 @@ public class CKANPackage extends CKAN implements Moderated {
|
|||
try {
|
||||
readItem();
|
||||
checkModerationRead();
|
||||
// TODO check keepModerationExtraProperties
|
||||
// uriInfo.getQueryParameters().get(KEEP);
|
||||
|
||||
return getAsCleanedString(result);
|
||||
} catch(WebApplicationException e) {
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue