Skip to content

Commit

Permalink
Fix unqualified 'skip' auto-completion result
Browse files Browse the repository at this point in the history
When auto-completion expression returned 'skip' (as unqualified
string or QName), the stage was not properly recognized as empty,
and the approval process was started. Now the comparison is properly
done with QNameUtil.matchUri.

This resolves MID-5895.
  • Loading branch information
mederly committed Mar 30, 2020
1 parent 51200a1 commit 67e5586
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Expand Up @@ -32,6 +32,7 @@
import com.evolveum.midpoint.task.api.TaskExecutionStatus;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -204,8 +205,9 @@ public boolean isEmpty(PcpStartInstruction instruction,
}
// second pass: check the conditions
for (ApprovalStageDefinitionType stage : stages) {
if (!SchemaConstants.MODEL_APPROVAL_OUTCOME_SKIP.equals(
evaluateAutoCompleteExpression(instruction.getCase(), stage, instruction, stageComputeHelper, ctx, result))) {
String autoCompletionResult = evaluateAutoCompleteExpression(instruction.getCase(), stage, instruction,
stageComputeHelper, ctx, result);
if (!QNameUtil.matchUri(SchemaConstants.MODEL_APPROVAL_OUTCOME_SKIP, autoCompletionResult)) {
return false;
}
}
Expand Down
Expand Up @@ -73,6 +73,9 @@ public class TestAssignmentsAdvanced extends AbstractWfTestPolicy {
private static final File ROLE_ROLE27_FILE = new File(TEST_RESOURCE_DIR, "role-role27-modifications-and.xml");
private static final File ROLE_ROLE28_FILE = new File(TEST_RESOURCE_DIR, "role-role28-modifications-or.xml");
private static final File ROLE_ROLE29_FILE = new File(TEST_RESOURCE_DIR, "role-role29-modifications-no-items.xml");

private static final TestResource ROLE_SKIPPED_FILE = new TestResource(TEST_RESOURCE_DIR, "role-skipped.xml", "66134203-f023-4986-bb5c-a350941909eb");

private static final TestResource ROLE_IDEMPOTENT = new TestResource(TEST_RESOURCE_DIR, "role-idempotent.xml", "e2f2d977-887b-4ea1-99d8-a6a030a1a6c0");
private static final TestResource ROLE_WITH_IDEMPOTENT_METAROLE = new TestResource(TEST_RESOURCE_DIR, "role-with-idempotent-metarole.xml", "34855a80-3899-4ecf-bdb3-9fc008c4ff70");

Expand Down Expand Up @@ -127,6 +130,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
roleRole29Oid = repoAddObjectFromFile(ROLE_ROLE29_FILE, initResult).getOid();
repoAdd(ROLE_IDEMPOTENT, initResult);
repoAdd(ROLE_WITH_IDEMPOTENT_METAROLE, initResult);
repoAdd(ROLE_SKIPPED_FILE, initResult);

orgLeads2122Oid = repoAddObjectFromFile(ORG_LEADS2122_FILE, initResult).getOid();

Expand Down Expand Up @@ -1071,6 +1075,34 @@ public void test910AssignRoleWithIdempotentMetarole() throws Exception {
deleteCaseTree(rootCaseOid, result);
}

/**
* MID-5895
*/
@Test
public void test920AssignRoleWithComputedSkip() throws Exception {
given();
login(userAdministrator);
Task task = getTestTask();
OperationResult result = task.getResult();

when();
unassignAllRoles(userJackOid);

ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class)
.item(UserType.F_ASSIGNMENT)
.add(new AssignmentType(prismContext).targetRef(ROLE_SKIPPED_FILE.oid, RoleType.COMPLEX_TYPE))
.asObjectDeltaCast(userJackOid);

executeChanges(delta, null, task, result);

then();
String ref = result.findAsynchronousOperationReference();
assertNull("Present async operation reference", ref);

assertUser(userJackOid, "after")
.assertAssignments(1);
}

private void executeAssignRoles123ToJack(boolean immediate,
boolean approve1, boolean approve2, boolean approve3a, boolean approve3b, boolean securityDeputy) throws Exception {
Task task = getTestTask();
Expand Down
@@ -0,0 +1,31 @@
<!--
~ Copyright (c) 2020 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<role xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3" oid="66134203-f023-4986-bb5c-a350941909eb">
<name>skipped</name>
<assignment>
<policyRule>
<policyConstraints>
<assignment/>
</policyConstraints>
<policyActions>
<approval>
<approvalSchema>
<stage>
<approverRef oid="00000000-0000-0000-0000-000000000002" type="UserType" />
<automaticallyCompleted>
<script>
<code>'skip'</code> <!-- MID-5895 -->
</script>
</automaticallyCompleted>
</stage>
</approvalSchema>
</approval>
</policyActions>
</policyRule>
</assignment>
</role>

0 comments on commit 67e5586

Please sign in to comment.