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.NotAllowedException;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.MultivaluedMap;
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.apache.http.MethodNotSupportedException;
|
import org.apache.http.MethodNotSupportedException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
@ -129,6 +130,17 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
|
|
||||||
protected ModerationThread moderationThread;
|
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() {
|
public CKANPackage() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -146,9 +158,17 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
ckanUser = CKANUserCache.getCurrrentCKANUser();
|
ckanUser = CKANUserCache.getCurrrentCKANUser();
|
||||||
|
|
||||||
updateOperation = false;
|
updateOperation = false;
|
||||||
|
keepModerationExtraProperties = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setKeepModerationExtraProperties(boolean keepModerationExtraProperties) {
|
||||||
|
if(ckanUser.getRole().ordinal()>=Role.MANAGER.ordinal() && keepModerationExtraProperties) {
|
||||||
|
this.keepModerationExtraProperties = keepModerationExtraProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected CKANOrganization checkGotOrganization(String gotOrganization) throws ForbiddenException {
|
protected CKANOrganization checkGotOrganization(String gotOrganization) throws ForbiddenException {
|
||||||
if(!configuration.getSupportedOrganizations().contains(gotOrganization)) {
|
if(!configuration.getSupportedOrganizations().contains(gotOrganization)) {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
|
@ -192,24 +212,28 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
|
|
||||||
// Removing all Content Moderation Keys
|
// Removing all Content Moderation Keys
|
||||||
if(jsonNode.has(EXTRAS_KEY)) {
|
if(jsonNode.has(EXTRAS_KEY)) {
|
||||||
ArrayNode extras = (ArrayNode) jsonNode.get(EXTRAS_KEY);
|
if(ckanUser.getRole().ordinal()>=Role.MANAGER.ordinal() && keepModerationExtraProperties) {
|
||||||
// It is not possible to remove the element of an array while iterating it.
|
logger.trace("The user is a {} which requested to keep Moderation extra properties.", ckanUser.getRole());
|
||||||
// We need to create a new array only with valie elements;
|
}else {
|
||||||
ArrayNode newExtras = mapper.createArrayNode();
|
ArrayNode extras = (ArrayNode) jsonNode.get(EXTRAS_KEY);
|
||||||
boolean foundOne = false;
|
// It is not possible to remove the element of an array while iterating it.
|
||||||
for(int i=0; i<extras.size(); i++) {
|
// We need to create a new array only with valid elements;
|
||||||
JsonNode extra = extras.get(i);
|
ArrayNode newExtras = mapper.createArrayNode();
|
||||||
if(extra.has(EXTRAS_KEY_KEY) &&
|
boolean foundOne = false;
|
||||||
extra.get(EXTRAS_KEY_KEY)!=null &&
|
for(int i=0; i<extras.size(); i++) {
|
||||||
extra.get(EXTRAS_KEY_KEY).asText().startsWith(Moderated.SYSTEM_CM_PREFIX)) {
|
JsonNode extra = extras.get(i);
|
||||||
foundOne = true;
|
if(extra.has(EXTRAS_KEY_KEY) &&
|
||||||
}else {
|
extra.get(EXTRAS_KEY_KEY)!=null &&
|
||||||
newExtras.add(extra.deepCopy());
|
extra.get(EXTRAS_KEY_KEY).asText().startsWith(Moderated.SYSTEM_CM_PREFIX)) {
|
||||||
|
foundOne = true;
|
||||||
|
}else {
|
||||||
|
newExtras.add(extra.deepCopy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(foundOne) {
|
||||||
|
((ObjectNode) jsonNode).replace(EXTRAS_KEY, newExtras);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(foundOne) {
|
|
||||||
((ObjectNode) jsonNode).replace(EXTRAS_KEY, newExtras);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jsonNode;
|
return jsonNode;
|
||||||
|
@ -806,6 +830,9 @@ public class CKANPackage extends CKAN implements Moderated {
|
||||||
try {
|
try {
|
||||||
readItem();
|
readItem();
|
||||||
checkModerationRead();
|
checkModerationRead();
|
||||||
|
// TODO check keepModerationExtraProperties
|
||||||
|
// uriInfo.getQueryParameters().get(KEEP);
|
||||||
|
|
||||||
return getAsCleanedString(result);
|
return getAsCleanedString(result);
|
||||||
} catch(WebApplicationException e) {
|
} catch(WebApplicationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue