From e44f9cce5eec67902590ed2c6ff148cc37456a5f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 8 Nov 2024 12:52:57 -0600 Subject: [PATCH] Issue 30571 has comment subaction (#30574) Adding a flag to know if the comment on workflow subaction is being part of the wf action --------- Co-authored-by: Will Ezell --- .../api/v1/workflow/WorkflowResource.java | 1 + .../workflows/actionlet/Actionlet.java | 5 + .../actionlet/CommentOnWorkflowActionlet.java | 1 + .../workflows/business/WorkflowAPIImpl.java | 3 + .../workflows/model/WorkflowAction.java | 18 +- .../postman/Workflow_Resource_Tests.json | 190 +++++++++++++++++- 6 files changed, 216 insertions(+), 2 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/workflow/WorkflowResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/workflow/WorkflowResource.java index 76d4471ab23e..8921c387f416 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/workflow/WorkflowResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/workflow/WorkflowResource.java @@ -689,6 +689,7 @@ public static WorkflowActionView convertToWorkflowActionView(final WorkflowActio workflowActionView.setShowOn(workflowAction.getShowOn()); workflowActionView.setActionInputs(createActionInputViews(workflowAction)); workflowActionView.setMetadata(workflowAction.getMetadata()); + workflowActionView.setCommentActionlet(workflowAction.hasCommentActionlet()); workflowActionView.setResetable(workflowAction.hasResetActionlet()); return workflowActionView; } diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/Actionlet.java b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/Actionlet.java index 60f520d55711..5e3bc4679296 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/Actionlet.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/Actionlet.java @@ -58,6 +58,11 @@ */ boolean onlyBatch() default false; + /** + * Set this to true if the actionlet is commentable + */ + boolean comment() default false; + /** * Set this to true if the sub actionlet is a reset content * @return diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/CommentOnWorkflowActionlet.java b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/CommentOnWorkflowActionlet.java index a08d6eef64a8..2b699d1bd931 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/CommentOnWorkflowActionlet.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/actionlet/CommentOnWorkflowActionlet.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; +@Actionlet(comment = true) public class CommentOnWorkflowActionlet extends WorkFlowActionlet { diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java index 381018a0901b..cbebf07c0965 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/business/WorkflowAPIImpl.java @@ -1657,6 +1657,7 @@ protected void fillActionInfo(final WorkflowAction action, boolean isPushPublish = false; boolean isMove = false; boolean isMoveHasPath = false; + boolean isComment = false; boolean isReset = false; for (final WorkflowActionClass actionClass : actionClasses) { @@ -1672,6 +1673,7 @@ protected void fillActionInfo(final WorkflowAction action, isDelete |= (null != actionlet) && actionlet.delete(); isDestroy |= (null != actionlet) && actionlet.destroy(); isPushPublish |= (null != actionlet) && actionlet.pushPublish(); + isComment |= (null != actionlet) && actionlet.comment(); isReset |= (null != actionlet) && actionlet.reset(); /* @@ -1699,6 +1701,7 @@ protected void fillActionInfo(final WorkflowAction action, action.setPushPublishActionlet(isPushPublish); action.setMoveActionlet(isMove); action.setMoveActionletHashPath(isMoveHasPath); + action.setCommentActionlet(isComment); action.setResetable(isReset); } diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/model/WorkflowAction.java b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/model/WorkflowAction.java index 24ec1dd1a46c..8259f01014aa 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/model/WorkflowAction.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/workflows/model/WorkflowAction.java @@ -77,10 +77,13 @@ public class WorkflowAction implements Permissionable, Serializable{ private boolean destroyActionlet; private boolean moveActionlet; private boolean moveActionletHasPath; + private boolean commentActionlet; + private Set showOn = Collections.emptySet(); private Map metadata = new HashMap<>(); private boolean resetable; + public WorkflowAction() { } @@ -259,6 +262,16 @@ public boolean hasMoveActionletHasPathActionlet() { return this.moveActionletHasPath; } + + /** + * Returns true if the action has comment sub action + * @return Boolean true if has a comment action + */ + @JsonProperty("hasCommentActionlet") + public boolean hasCommentActionlet() { + return this.commentActionlet; + } + /** * Returns true if the action has at least one action let that unpublish * @return Boolean true if has unpublish action @@ -339,6 +352,10 @@ public void setArchiveActionlet(final boolean archiveActionlet) { this.archiveActionlet = archiveActionlet; } + public void setCommentActionlet(final boolean isComment) { + this.commentActionlet = isComment; + } + public void setUnarchiveActionlet(final boolean unarchiveActionlet) { this.unarchiveActionlet = unarchiveActionlet; } @@ -580,5 +597,4 @@ public int hashCode() { return Objects.hash(id); } - } diff --git a/dotcms-postman/src/main/resources/postman/Workflow_Resource_Tests.json b/dotcms-postman/src/main/resources/postman/Workflow_Resource_Tests.json index fb6b0d8b57c6..181ce16938e5 100644 --- a/dotcms-postman/src/main/resources/postman/Workflow_Resource_Tests.json +++ b/dotcms-postman/src/main/resources/postman/Workflow_Resource_Tests.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "f71e0eaf-03a0-48a4-b053-9724ee897240", + "_postman_id": "551fc73a-c338-498a-9aeb-b4f19b1708f9", "name": "Workflow Resource Tests [/api/v1/workflows]", "description": "Test the necesary validations to every end point of the worlflow resource ", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", @@ -17962,6 +17962,194 @@ "response": [] } ] + }, + { + "name": "Commentable", + "item": [ + { + "name": "CreateContentPreconditions", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 \", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "", + "var jsonData = pm.response.json();", + "pm.collectionVariables.set(\"contentletIdentifier\", jsonData.entity.identifier);", + "pm.collectionVariables.set(\"contentletInode\", jsonData.entity.inode);", + "", + "" + ], + "type": "text/javascript", + "packages": {} + } + }, + { + "listen": "prerequest", + "script": { + "packages": {}, + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"contentlet\": {\n \"contentType\": \"webPageContent\",\n \"title\": \"Test Title\",\n \"body\": \"Test Body\",\n \"contentHost\": \"default\"\n }\n}" + }, + "url": { + "raw": "{{serverURL}}/api/v1/workflow/actions/default/fire/PUBLISH", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "workflow", + "actions", + "default", + "fire", + "PUBLISH" + ] + }, + "description": "Fire any action using the actionId\n\nOptional: If you pass ?inode={inode}, you don't need body here.\n\n@Path(\"/actions/{actionId}/fire\")" + }, + "response": [] + }, + { + "name": "CheckCommentable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.test(\"Response has expected properties\", function () {", + " const jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property(\"entity\");", + " pm.expect(jsonData).to.have.property(\"errors\");", + " pm.expect(jsonData).to.have.property(\"i18nMessagesMap\");", + " pm.expect(jsonData).to.have.property(\"messages\");", + " pm.expect(jsonData).to.have.property(\"pagination\");", + " pm.expect(jsonData).to.have.property(\"permissions\");", + "});", + "", + "pm.test(\"Entity is an array and contains items\", function () {", + " const entity = pm.response.json().entity;", + " pm.expect(entity).to.be.an(\"array\").that.is.not.empty;", + "});", + "", + "pm.test(\"Each entity item has expected properties\", function () {", + " const entity = pm.response.json().entity;", + " entity.forEach(item => {", + " pm.expect(item).to.have.property(\"actionInputs\").that.is.an(\"array\");", + " pm.expect(item).to.have.property(\"assignable\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"commentable\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"condition\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"hasArchiveActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasDeleteActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasDestroyActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasMoveActionletActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasMoveActionletHasPathActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasOnlyBatchActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasPublishActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasPushPublishActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasSaveActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasUnarchiveActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasUnpublishActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"hasCommentActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"icon\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"id\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"name\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"nextAssign\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"nextStep\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"nextStepCurrentStep\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"order\").that.is.a(\"number\");", + " pm.expect(item).to.have.property(\"owner\").that.is.null;", + " pm.expect(item).to.have.property(\"hasResetActionlet\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"roleHierarchyForAssign\").that.is.a(\"boolean\");", + " pm.expect(item).to.have.property(\"schemeId\").that.is.a(\"string\");", + " pm.expect(item).to.have.property(\"showOn\").that.is.an(\"array\");", + " ", + " const allowedShowOnValues = [\"NEW\", \"LISTING\", \"PUBLISHED\", \"UNLOCKED\", \"ARCHIVED\", \"UNPUBLISHED\", \"EDITING\", \"LOCKED\"];", + " item.showOn.forEach(status => {", + " pm.expect(allowedShowOnValues).to.include(status);", + " });", + " });", + "});", + "", + "pm.test(\"Errors array is empty\", function () {", + " const errors = pm.response.json().errors;", + " pm.expect(errors).to.be.an(\"array\").that.is.empty;", + "});", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "{{serverURL}}/api/v1/workflow/contentlet/{{contentletInode}}/actions?renderMode=EDITING", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "workflow", + "contentlet", + "{{contentletInode}}", + "actions" + ], + "query": [ + { + "key": "renderMode", + "value": "EDITING" + } + ] + } + }, + "response": [] + } + ] } ], "event": [