Merge ACS-3652_ScriptNodeValidation into ACS-3652_LinkToCategoryValidation.

This commit is contained in:
Tom Page
2022-10-18 19:19:29 +01:00
29 changed files with 103 additions and 73 deletions

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-automation-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<build>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<build>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -8,7 +8,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -14,7 +14,7 @@ function main()
maxResults: (args.maxResults !== null) ? parseInt(args.maxResults, 10) : DEFAULT_MAX_RESULTS,
pageSize: (args.pageSize !== null) ? parseInt(args.pageSize, 10) : DEFAULT_PAGE_SIZE,
startIndex: (args.startIndex !== null) ? parseInt(args.startIndex, 10) : 0,
facetFields: args.facetFields.replace( /(<([^>]+)>)/ig, ''),
facetFields: args.facetFields !== null ? args.facetFields.replace( /(<([^>]+)>)/ig, '') : null,
filters: args.filters,
encodedFilters: args.encodedFilters,
spell: (args.spellcheck !== null) ? (args.spellcheck == "true") : false

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -9,6 +9,6 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
</project>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<modules>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<organization>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -26,15 +26,14 @@
package org.alfresco.rest.rules;
import static java.util.stream.Collectors.toList;
import static org.alfresco.rest.actions.access.AccessRestrictionUtil.ERROR_MESSAGE_ACCESS_RESTRICTED;
import static org.alfresco.rest.actions.access.AccessRestrictionUtil.MAIL_ACTION;
import static org.alfresco.rest.rules.RulesTestsUtils.CHECKIN_ACTION;
import static org.alfresco.rest.rules.RulesTestsUtils.ID;
import static org.alfresco.rest.rules.RulesTestsUtils.INVERTED;
import static org.alfresco.rest.rules.RulesTestsUtils.IS_SHARED;
import static org.alfresco.rest.rules.RulesTestsUtils.RULE_NAME_DEFAULT;
import static org.alfresco.rest.rules.RulesTestsUtils.RULE_SCRIPT_ID;
import static org.alfresco.rest.rules.RulesTestsUtils.RULE_SCRIPT_PARAM_ID;
import static org.alfresco.rest.rules.RulesTestsUtils.TEMPLATE_PARAM;
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
import static org.alfresco.utility.constants.UserRole.SiteConsumer;
import static org.alfresco.utility.constants.UserRole.SiteContributor;
@@ -58,6 +57,7 @@ import java.util.stream.IntStream;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
import org.alfresco.rest.model.RestActionConstraintModel;
import org.alfresco.rest.model.RestActionDefinitionModel;
import org.alfresco.rest.model.RestCompositeConditionDefinitionModel;
import org.alfresco.rest.model.RestParameterDefinitionModel;
@@ -390,6 +390,23 @@ public class CreateRulesTests extends RestTest
.assertThat().field(IS_SHARED).isNull();
}
/**
* Check we can create a rule with check in action with empty description parameter.
*/
@Test(groups = {TestGroup.REST_API, TestGroup.RULES})
public void createRuleWithCheckInActionAndEmptyCheckInDescription()
{
final RestRuleModel ruleModel = rulesUtils.createRuleModelWithDefaultValues();
final RestActionBodyExecTemplateModel checkinAction = new RestActionBodyExecTemplateModel();
checkinAction.setActionDefinitionId(CHECKIN_ACTION);
checkinAction.setParams(Map.of("description", ""));
ruleModel.setActions(Arrays.asList(checkinAction));
restClient.authenticateUser(user).withPrivateAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
restClient.assertStatusCodeIs(CREATED);
}
/** Check that a normal user cannot create rules that use private actions. */
@Test
public void createRuleWithActions_userCannotUsePrivateAction()
@@ -411,7 +428,9 @@ public class CreateRulesTests extends RestTest
restClient.assertStatusCodeIs(CREATED);
}
/** Check that an administrator can create rules that use private actions. */
/**
* Check that an administrator can create rules with email (private) action with reference to an email template.
*/
@Test
public void createRuleWithActions_adminCanUseMailActionWithTemplate()
{
@@ -424,16 +443,20 @@ public class CreateRulesTests extends RestTest
params.put("from", sender.getEmailAddress());
params.put("to", recipient.getEmailAddress());
params.put("subject", "Test");
final RestActionDefinitionModel actionDef = restClient.authenticateUser(user).withCoreAPI().usingActions().getActionDefinitionById(RULE_SCRIPT_ID);
final RestParameterDefinitionModel
paramDef = actionDef.getParameterDefinitions().stream().filter(param -> param.getName().equals(RULE_SCRIPT_PARAM_ID)).findFirst().get();
final String templateScriptRef = paramDef.getParameterConstraintName();
params.put("template", templateScriptRef);
final RestActionDefinitionModel actionDef =
restClient.authenticateUser(user).withCoreAPI().usingActions().getActionDefinitionById(MAIL_ACTION);
final RestParameterDefinitionModel paramDef =
actionDef.getParameterDefinitions().stream().filter(param -> param.getName().equals(TEMPLATE_PARAM)).findFirst().get();
final String constraintName = paramDef.getParameterConstraintName();
final RestActionConstraintModel constraint =
restClient.authenticateUser(user).withCoreAPI().usingActions().getActionConstraintByName(constraintName);
String templateScriptRef = constraint.getConstraintValues().stream().findFirst().get().getValue();
params.put(TEMPLATE_PARAM, templateScriptRef);
mailAction.setParams(params);
ruleModel.setActions(Arrays.asList(mailAction));
restClient.authenticateUser(dataUser.getAdminUser()).withPrivateAPI().usingNode(ruleFolder).usingDefaultRuleSet()
.createSingleRule(rulesUtils.createRuleWithPrivateAction());
.createSingleRule(ruleModel);
restClient.assertStatusCodeIs(CREATED);
}
@@ -668,7 +691,7 @@ public class CreateRulesTests extends RestTest
params.put("to", recipient.getEmailAddress());
params.put("subject", "Test");
final String mailTemplate = "non-existing-node-id";
params.put("template", mailTemplate);
params.put(TEMPLATE_PARAM, mailTemplate);
mailAction.setParams(params);
ruleModel.setActions(Arrays.asList(mailAction));

View File

@@ -51,12 +51,11 @@ import org.alfresco.utility.data.DataUserAIS;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RulesTestsUtils implements InitializingBean
public class RulesTestsUtils
{
static final String RULE_NAME_DEFAULT = "ruleName";
static final String RULE_DESCRIPTION_DEFAULT = "rule description";
@@ -67,6 +66,7 @@ public class RulesTestsUtils implements InitializingBean
static final String RULE_SCRIPT_ID = "script";
static final String RULE_SCRIPT_PARAM_ID = "script-ref";
static final String RULE_ERROR_SCRIPT_LABEL = "Start Pooled Review and Approve Workflow";
public static final String CHECKIN_ACTION = "check-in";
static final String INBOUND = "inbound";
static final String UPDATE = "update";
static final String OUTBOUND = "outbound";
@@ -77,6 +77,7 @@ public class RulesTestsUtils implements InitializingBean
static final String IS_SHARED = "isShared";
static final String AUDIO_ASPECT = "audio:audio";
static final String LOCKABLE_ASPECT = "cm:lockable";
public static final String TEMPLATE_PARAM = "template";
@Autowired
private RestWrapper restClient;
@@ -87,30 +88,15 @@ public class RulesTestsUtils implements InitializingBean
@Autowired
private DataContent dataContent;
private SiteModel site;
/** Public site used by these helper methods. This is populated by the getter and should not be accessed directly. */
private SiteModel publicSite;
/** Script node used by these helper methods. This is populated by the getter and should not be accessed directly. */
private String reviewAndApproveWorkflowNode;
/** Destination folder for copy action used by these helper methods. This is populated by the getter and should not be accessed directly. */
private FolderModel copyDestinationFolder;
/** Destination folder for check out action used by these helper methods. This is populated by the getter and should not be accessed directly. */
private FolderModel checkOutDestinationFolder;
/**
* Initialise the util class.
*/
@Override
public void afterPropertiesSet()
{
UserModel admin = dataUser.getAdminUser();
// Obtain the node ref for the review and approve workflow.
String reviewAndApprove = findConstraintValue(admin, RULE_SCRIPT_ID, RULE_SCRIPT_PARAM_ID, RULE_ERROR_SCRIPT_LABEL);
reviewAndApproveWorkflowNode = reviewAndApprove;
// Create a couple of public folders to be used as action destinations.
site = dataSite.usingUser(admin).createPublicRandomSite();
copyDestinationFolder = dataContent.usingUser(admin).usingSite(site).createFolder();
checkOutDestinationFolder = dataContent.usingUser(admin).usingSite(site).createFolder();
}
/**
* Get the constraint value for a given action parameter label.
*
@@ -134,11 +120,6 @@ public class RulesTestsUtils implements InitializingBean
return constraintDataModel.getValue();
}
public RestRuleModel createRuleModelWithModifiedValues()
{
return createRuleModelWithModifiedValues(List.of(createAddAudioAspectAction()));
}
/**
* Get the review and approve workflow node (throwing an exception if this utility class has not been initialised).
*
@@ -146,19 +127,49 @@ public class RulesTestsUtils implements InitializingBean
*/
public String getReviewAndApproveWorkflowNode()
{
if (reviewAndApproveWorkflowNode == null)
{
UserModel admin = dataUser.getAdminUser();
reviewAndApproveWorkflowNode = findConstraintValue(admin, RULE_SCRIPT_ID, RULE_SCRIPT_PARAM_ID, RULE_ERROR_SCRIPT_LABEL);
}
return reviewAndApproveWorkflowNode;
}
public SiteModel getPublicSite()
{
if (publicSite == null)
{
UserModel admin = dataUser.getAdminUser();
publicSite = dataSite.usingUser(admin).createPublicRandomSite();
}
return publicSite;
}
public FolderModel getCopyDestinationFolder()
{
if (copyDestinationFolder == null)
{
UserModel admin = dataUser.getAdminUser();
copyDestinationFolder = dataContent.usingUser(admin).usingSite(getPublicSite()).createFolder();
}
return copyDestinationFolder;
}
public FolderModel getCheckOutDestinationFolder()
{
if (checkOutDestinationFolder == null)
{
UserModel admin = dataUser.getAdminUser();
checkOutDestinationFolder = dataContent.usingUser(admin).usingSite(getPublicSite()).createFolder();
}
return checkOutDestinationFolder;
}
public RestRuleModel createRuleModelWithModifiedValues()
{
return createRuleModelWithModifiedValues(List.of(createAddAudioAspectAction()));
}
/**
* Create a rule model filled with custom constant values.
*
@@ -258,10 +269,10 @@ public class RulesTestsUtils implements InitializingBean
public RestRuleModel createRuleWithVariousActions()
{
final Map<String, Serializable> copyParams =
Map.of("destination-folder", copyDestinationFolder.getNodeRef(), "deep-copy", true);
Map.of("destination-folder", getCopyDestinationFolder().getNodeRef(), "deep-copy", true);
final RestActionBodyExecTemplateModel copyAction = createCustomActionModel("copy", copyParams);
final Map<String, Serializable> checkOutParams =
Map.of("destination-folder", checkOutDestinationFolder.getNodeRef(), "assoc-name", "cm:checkout",
Map.of("destination-folder", getCheckOutDestinationFolder().getNodeRef(), "assoc-name", "cm:checkout",
"assoc-type", "cm:contains");
final RestActionBodyExecTemplateModel checkOutAction = createCustomActionModel("check-out", checkOutParams);
// The counter action takes no parameters, so check we can omit the "params" entry.

View File

@@ -9,7 +9,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<developers>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<properties>

View File

@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Alfresco Community Repo Parent</name>
@@ -109,8 +109,8 @@
<dependency.jakarta-json-path.version>2.7.0</dependency.jakarta-json-path.version>
<dependency.jakarta-rpc-api.version>1.1.4</dependency.jakarta-rpc-api.version>
<alfresco.googledrive.version>3.2.3-A3</alfresco.googledrive.version>
<alfresco.aos-module.version>1.4.1</alfresco.aos-module.version>
<alfresco.googledrive.version>3.3.0-A1</alfresco.googledrive.version>
<alfresco.aos-module.version>1.5.0-A7</alfresco.aos-module.version>
<alfresco.api-explorer.version>7.3.0-A1</alfresco.api-explorer.version> <!-- Also in alfresco-enterprise-share -->
<alfresco.maven-plugin.version>2.2.0</alfresco.maven-plugin.version>

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<dependencies>

View File

@@ -33,11 +33,11 @@ import static org.alfresco.rest.api.actions.ActionValidator.ALL_ACTIONS;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.action.CompositeActionImpl;
@@ -82,7 +82,7 @@ public class RestRuleActionModelMapper implements RestModelMapper<Action, org.al
final Map<String, Serializable> convertedParams = actionModel.getParameterValues()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> parameterConverter.convertParamFromServiceModel(e.getValue())));
.collect(HashMap::new, (m, v) -> m.put(v.getKey(), parameterConverter.convertParamFromServiceModel(v.getValue())), HashMap::putAll);
convertedParams.remove(ACTION_CONTEXT_PARAM_NAME);
builder.params(convertedParams);
}

View File

@@ -27,7 +27,6 @@
package org.alfresco.rest.api.impl.validator.actions;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -49,8 +48,6 @@ import org.apache.commons.collections.MapUtils;
public class ActionParameterDefinitionValidator implements ActionValidator
{
private static final boolean IS_ENABLED = true;
private static final String BASE_PACKAGE = "org/alfresco/repo/action/executer";
private static final String NAME = "NAME";
static final String INVALID_PARAMETER_VALUE =
"Action parameter: %s has invalid value (%s). Look up possible values for constraint name %s";
@@ -60,7 +57,6 @@ public class ActionParameterDefinitionValidator implements ActionValidator
"Action parameters should not be null or empty for this action. See Action Definition for action of: %s";
static final String INVALID_ACTION_DEFINITION = "Invalid action definition requested %s";
private final List<String> actionDefinitionIds = new ArrayList<>();
private final Actions actions;
public ActionParameterDefinitionValidator(Actions actions)

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId>
<version>17.168-SNAPSHOT</version>
<version>17.175-SNAPSHOT</version>
</parent>
<dependencies>