MVELLifeCycleManager implements LifeCycleManager { void evalCommand(final Operation operation, final List<OperationCommand> commands, final Task task, final User user, final OrganizationalEntity targetEntity, List<String> groupIds, OrganizationalEntity...entities) throws PermissionDeniedException { boolean statusMatched = false; final TaskData taskData = task.getTaskData(); for (OperationCommand command : commands) { if (command.getStatus() != null) { for (Status status : command.getStatus()) { if (task.getTaskData().getStatus() == status) { statusMatched = true; if (!isAllowed(command, task, user, groupIds)) { String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId(); throw new PermissionDeniedException(errorMessage); } commands(command, task, user, targetEntity, entities); } else { logger.debug("No match on status for task {} :status {} != {}", task.getId(), task.getTaskData().getStatus(), status); } } } if (command.getPreviousStatus() != null) { for (Status status : command.getPreviousStatus()) { if (taskData.getPreviousStatus() == status) { statusMatched = true; if (!isAllowed(command, task, user, groupIds)) { String errorMessage = "User '" + user + "' does not have permissions to execute operation '" + operation + "' on task id " + task.getId(); throw new PermissionDeniedException(errorMessage); } commands(command, task, user, targetEntity, entities); } else { logger.debug("No match on previous status for task {} :status {} != {}", task.getId(), task.getTaskData().getStatus(), status); } } } if (!command.isGroupTargetEntityAllowed() && targetEntity instanceof Group) { String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to 'target entity cannot be group'"; throw new PermissionDeniedException(errorMessage); } } if (!statusMatched) { String errorMessage = "User '" + user + "' was unable to execute operation '" + operation + "' on task id " + task.getId() + " due to a no 'current status' match"; throw new PermissionDeniedException(errorMessage); } } MVELLifeCycleManager();  MVELLifeCycleManager(TaskContext context, TaskPersistenceContext persistenceContext, TaskContentService contentService,
    		TaskEventSupport taskEventSupport); void setPersistenceContext(TaskPersistenceContext persistenceContext); void setTaskEventSupport(TaskEventSupport taskEventSupport); void setTaskContentService(TaskContentService taskContentService); void taskOperation(final Operation operation, final long taskId, final String userId,
            final String targetEntityId, final Map<String, Object> data,
            List<String> groupIds, OrganizationalEntity...entities); static Map<Operation, List<OperationCommand>> initMVELOperations(); static String toString(Reader reader); static Object eval(Reader reader); static Object eval(Reader reader, Map<String, Object> vars); static Object eval(String str, Map<String, Object> vars); static Status assignOwnerAndStatus(InternalTaskData taskData, List<OrganizationalEntity> potentialOwners);  }
@Test(expected = PermissionDeniedException.class) public void testClaimIsAllowedExcludedOwner() { User testUser = new UserImpl("BB8"); List<String> testGroupIds = new ArrayList<>(); testGroupIds.add("testGroup1"); String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Created } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')]}),"; str += "name = 'This is my task name' })"; InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str)); Operation operation = Operation.Claim; List<OperationCommand> operationCommands = new ArrayList<>(); OperationCommand operationCommand = new OperationCommand(); List<Allowed> allowed = new ArrayList<>(); allowed.add(Allowed.PotentialOwner); operationCommand.setAllowed(allowed); List<Status> status = new ArrayList<>(); status.add(Status.Created); operationCommand.setStatus(status); operationCommands.add(operationCommand); MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager(); taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null); }
@Test public void testDelegateIsAllowedExcludedOwnerBusinessAdministrator() { User testUser = new UserImpl("BB8"); List<String> testGroupIds = new ArrayList<>(); testGroupIds.add("testGroup1"); String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Ready } ), "; str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')], businessAdministrators = [new User('BB8')]}),"; str += "name = 'This is my task name' })"; InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str)); Operation operation = Operation.Delegate; List<OperationCommand> operationCommands = new ArrayList<>(); OperationCommand operationCommand = new OperationCommand(); List<Allowed> allowed = new ArrayList<>(); allowed.add(Allowed.PotentialOwner); allowed.add(Allowed.BusinessAdministrator); operationCommand.setAllowed(allowed); List<Status> status = new ArrayList<>(); status.add(Status.Ready); operationCommand.setStatus(status); operationCommands.add(operationCommand); MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager(); taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null); }