flowable / flowable-engine

A compact and highly efficient workflow and Business Process Management (BPM) platform for developers, system admins and business users.
https://www.flowable.org
Apache License 2.0
7.59k stars 2.54k forks source link

The DefaultIdentityLinkIterceptor.java creates duplicate identityLinks on ProcessInstance #3900

Open billerby opened 1 month ago

billerby commented 1 month ago

Describe the bug The DefaultIdentityLinkIterceptor.handleCompleteTask method creates a new PARTICIPANT IdentityLink on the ProcessInstance the tasks belongs to every time a task completes.

Expected behavior There should be a check if such an IdentityLink already exists before creating it. This is done in some of the other methods in the class by calling the addUserIdentityLinkToParent which does such a check.

Noticed that we had a lot of duplicates in the IdentityLink-tables for processes with a lot of tasks.

Code

        public void handleCompleteTask(TaskEntity task) {
                if (Authentication.getAuthenticatedUserId() != null && task.getProcessInstanceId() != null) {
                    ExecutionEntity processInstanceEntity = CommandContextUtil.getExecutionEntityManager().findById(task.getProcessInstanceId());
                    IdentityLinkUtil.createProcessInstanceIdentityLink(processInstanceEntity,
                            Authentication.getAuthenticatedUserId(), null, IdentityLinkType.PARTICIPANT);
                }
            }

Additional context This is present on the main branch.