Skip to content

Commit

Permalink
Fix wrong usage of setAuthenticatedUserId
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Dec 14, 2023
1 parent 39f0602 commit d998956
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void trigger(CommandContext commandContext, PlanItemInstanceEntity planIt
// Should be only one
for (TaskEntity taskEntity : taskEntities) {
if (!taskEntity.isDeleted()) {
TaskHelper.completeTask(taskEntity, Authentication.getAuthenticatedUserId(), cmmnEngineConfiguration);
TaskHelper.completeTask(taskEntity, taskEntity.getTempCompletedBy(), cmmnEngineConfiguration);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.logging.CmmnLoggingSessionConstants;
Expand Down Expand Up @@ -137,9 +136,10 @@ public Void execute(CommandContext commandContext) {
"Human task '" + taskLabel + "' completed", taskEntity, planItemInstanceEntity, cmmnEngineConfiguration.getObjectMapper());
}

if (StringUtils.isNotEmpty(userId)) {
Authentication.setAuthenticatedUserId(userId);
if (userId != null) {
taskEntity.setTempCompletedBy(userId);
}

CommandContextUtil.getAgenda(commandContext).planTriggerPlanItemInstanceOperation(planItemInstanceEntity);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.form.api.FormFieldHandler;
import org.flowable.form.api.FormInfo;
Expand Down Expand Up @@ -206,6 +205,10 @@ protected void completeTask(CommandContext commandContext, TaskEntity task, Map<
if (transientVariablesLocal != null) {
task.setTransientVariablesLocal(transientVariablesLocal);
}

if (userId != null) {
task.setTempCompletedBy(userId);
}

logUserTaskCompleted(task, cmmnEngineConfiguration);

Expand All @@ -215,9 +218,6 @@ protected void completeTask(CommandContext commandContext, TaskEntity task, Map<

cmmnEngineConfiguration.getListenerNotificationHelper().executeTaskListeners(task, TaskListener.EVENTNAME_COMPLETE);

if (StringUtils.isNotEmpty(userId)) {
Authentication.setAuthenticatedUserId(userId);
}
CommandContextUtil.getAgenda(commandContext).planTriggerPlanItemInstanceOperation(planItemInstanceEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public interface TaskEntity extends VariableScope, Task, DelegateTask, Entity, H
void setAssigneeValue(String assignee);

void setOwnerValue(String owner);

String getTempCompletedBy();

void setTempCompletedBy(String completedBy);

List<VariableInstanceEntity> getQueryVariables();
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class TaskEntityImpl extends AbstractTaskServiceVariableScopeEntity imple
// Non-persisted
protected String eventName;
protected String eventHandlerId;
protected String tempCompletedBy;
protected List<VariableInstanceEntity> queryVariables;
protected List<IdentityLinkEntity> queryIdentityLinks;
protected boolean forcedUpdate;
Expand Down Expand Up @@ -709,6 +710,16 @@ public String getEventHandlerId() {
public void setEventHandlerId(String eventHandlerId) {
this.eventHandlerId = eventHandlerId;
}

@Override
public String getTempCompletedBy() {
return tempCompletedBy;
}

@Override
public void setTempCompletedBy(String tempCompletedBy) {
this.tempCompletedBy = tempCompletedBy;
}

@Override
public void setExecutionId(String executionId) {
Expand Down

0 comments on commit d998956

Please sign in to comment.