Fixed moderation bugs

This commit is contained in:
Luca Frosini 2021-12-15 18:03:51 +01:00
parent dda7bf6234
commit bdb930092f
2 changed files with 42 additions and 11 deletions

View File

@ -255,7 +255,15 @@ public class CKANPackage extends CKAN implements Moderated {
if(objectNode.has(PRIVATE_KEY)) {
boolean privatePackage = objectNode.get(PRIVATE_KEY).asBoolean();
if(privatePackage) {
objectNode.put(SEARCHABLE_KEY, true);
/*
* This version is not properly managed by CKAN.
* It is converted to:
* searchable: "true"
* which is incidentally considered as true value even is not correct.
* We need to provide a string with T as capitol letters to make it working
* objectNode.put(SEARCHABLE_KEY, true);
*/
objectNode.put(SEARCHABLE_KEY, "True");
}
}
@ -796,6 +804,12 @@ public class CKANPackage extends CKAN implements Moderated {
try {
JsonNode jsonNode = validateJson(json);
/*
* Going to read the item from CKAN just to check the item status.
* I need to reset the result first because the current contains
* the extras as sent by the client which are not trusted
*/
this.result = null;
readItem();
jsonNode = checkModerationUpdate(jsonNode);
@ -1010,7 +1024,7 @@ public class CKANPackage extends CKAN implements Moderated {
// The item was published before activating the moderation.
// The item is considered as approved and the item representation must be updated
setToApproved(result);
String ret = sendPostRequest(ITEM_PATCH, getAsString(result));
String ret = sendPostRequest(ITEM_UPDATE, getAsString(result));
try {
result = mapper.readTree(ret);
}catch (Exception e) {
@ -1237,7 +1251,15 @@ public class CKANPackage extends CKAN implements Moderated {
addExtraField(jsonNode, Moderated.SYSTEM_CM_ITEM_VISIBILITY, cmItemVisibility.getValue());
((ObjectNode) jsonNode).put(PRIVATE_KEY, true);
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, false);
/*
* This version is not properly managed by CKAN.
* It is converted to:
* searchable: "false"
* which is considered as true value.
* We need to provide a string with F as capitol letters to make it working
* ((ObjectNode) jsonNode).put(SEARCHABLE_KEY, false);
*/
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, "False");
}
}
@ -1268,8 +1290,13 @@ public class CKANPackage extends CKAN implements Moderated {
}
((ObjectNode) jsonNode).put(PRIVATE_KEY, cmItemVisibility == CMItemVisibility.RESTRICTED ? true :false);
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, true);
boolean privateItem = cmItemVisibility == CMItemVisibility.RESTRICTED ? true :false;
((ObjectNode) jsonNode).put(PRIVATE_KEY, privateItem);
if(privateItem) {
((ObjectNode) jsonNode).put(SEARCHABLE_KEY, "True");
}else {
((ObjectNode) jsonNode).remove(SEARCHABLE_KEY);
}
}
private void postItemCreated() throws Exception {
@ -1317,7 +1344,7 @@ public class CKANPackage extends CKAN implements Moderated {
throw new MethodNotSupportedException("Only catalogue moderator can approve a pending item.");
}
setToApproved(result);
String ret = sendPostRequest(ITEM_PATCH, getAsString(result));
String ret = sendPostRequest(ITEM_UPDATE, getAsString(result));
result = mapper.readTree(ret);
moderationThread.setItemCoordinates(itemID, name);

View File

@ -585,7 +585,11 @@ public class CKANPackageTest extends ContextTest {
JsonNode readItemObjectNode = mapper.readTree(readItem);
String updatedNotes = "A research of Luca Frosini made during the PhD";
((ObjectNode) readItemObjectNode).put(NOTES_KEY, updatedNotes);
ckanPackage.update(mapper.writeValueAsString(readItemObjectNode));
String ret = ckanPackage.update(mapper.writeValueAsString(readItemObjectNode));
logger.debug("Updated {}", ret);
ckanPackage = new CKANPackage();
ckanPackage.setName(ITEM_NAME_VALUE);
ckanPackage.message("I hope now it can be approved.");
@ -630,16 +634,16 @@ public class CKANPackageTest extends ContextTest {
// logger.debug("{}", res);
}
@Ignore
// @Test
// @Ignore
@Test
public void deleteAllItemsInAllOrganizations() {
CKANPackage ckanPackage = new CKANPackage();
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<String,String>();
mvm.add(GCatConstants.OWN_ONLY_QUERY_PARAMETER, "false");
UriInfo uriInfo = getUriInfo(mvm);
ckanPackage.setUriInfo(uriInfo);
// String res = ckanPackage.deleteAll(true);
// logger.debug("{}", res);
String res = ckanPackage.deleteAll(true);
logger.debug("{}", res);
}
@Test