From e452c93fe7d5261d316fee60aa642e42528c0010 Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Thu, 19 Feb 2026 09:28:02 -0400 Subject: [PATCH 1/2] Refactor task redirection logic to improve clarity and ensure correct handling of user assignments and element destinations --- src/components/task.vue | 65 +++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/src/components/task.vue b/src/components/task.vue index fa3a84c0..b1904ec4 100644 --- a/src/components/task.vue +++ b/src/components/task.vue @@ -912,42 +912,49 @@ export default { * @param {Object} data - The event data containing the tokenId of the task. */ async handleRedirectToTask(data) { - if ( - (data?.params[0]?.tokenId && - this.task.user?.id === data.params[0]?.userId) || - this.task.elementDestination?.type === 'taskSource' - ) { - this.loadingTask = true; - // Check if interstitial tasks are allowed for this task. - if (this.task && !(this.task.allow_interstitial || this.isSameUser(this.task, data))) { - // The getDestinationUrl() function is called asynchronously to retrieve the URL - window.location.href = await this.getDestinationUrl(); - return; - } - this.nodeId = data.params[0].nodeId; - this.taskId = data.params[0].tokenId; - - // Force a redirect to ensure the correct task is loaded immediately for ConversationalForm. - // This prevents async reloads that may cause inconsistencies specific to ConversationalForm. - if (this.renderComponent === "ConversationalForm") { - window.location.href = `/tasks/${this.taskId}/edit`; + const tokenId = data?.params[0]?.tokenId; + const newTaskUserId = data?.params[0]?.userId; // User assigned to the new task (from the backend) + const nodeId = data?.params[0]?.nodeId; + const currentUserId = this.userId; // Current user (who sees the page) = window.ProcessMaker.user.id + const elementDestType = this.task?.elementDestination?.type; + // Redirect if the new task is assigned to the current user, or if it is taskSource + const isNewTaskForCurrentUser = tokenId && (newTaskUserId === currentUserId || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource'))); + const isTaskSource = elementDestType === 'taskSource'; + const shouldHandle = isNewTaskForCurrentUser || isTaskSource; + + if (shouldHandle) { + this.loadingTask = true; + // Check if interstitial tasks are allowed for this task. + if (this.task && !(this.task.allow_interstitial || this.isSameUser(data))) { + window.location.href = await this.getDestinationUrl(); + return; + } + this.nodeId = nodeId; + this.taskId = tokenId; + + // Force a redirect to ensure the correct task is loaded immediately for ConversationalForm. + if (this.renderComponent === "ConversationalForm") { + window.location.href = `/tasks/${this.taskId}/edit`; + } + + this.reload(); } - - this.reload(); - } }, /** - * Checks if the current task and the redirect data belong to the same user. - * and the destination is taskSource. + * Checks if the redirect applies to the current user. + * - userId of event = user assigned to the new task + * - It is considered a match if: new task assigned to the current user, or taskSource/displayNextAssignedTask with user null * - * @param {Object} currentTask - The current task object. * @param {Object} redirectData - The redirect data object. */ - isSameUser(currentTask, redirectData) { - const userIdMatch = currentTask.user?.id === redirectData.params[0].userId; - const typeMatch = currentTask.elementDestination?.type === null - || currentTask.elementDestination?.type === 'taskSource'; + isSameUser(redirectData) { + const newTaskUserId = redirectData?.params?.[0]?.userId; + const currentUserId = this.userId; + const elementDestType = this.task?.elementDestination?.type; + const userIdMatch = newTaskUserId === currentUserId + || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource')); + const typeMatch = elementDestType === null || elementDestType === 'taskSource' || elementDestType === 'displayNextAssignedTask'; return userIdMatch && typeMatch; }, From b7d6ad462202291a2cd56696bf1a167505e0c1ed Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Thu, 19 Feb 2026 12:15:18 -0400 Subject: [PATCH 2/2] fix test with userid --- src/components/task.vue | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/task.vue b/src/components/task.vue index b1904ec4..59b9bfdc 100644 --- a/src/components/task.vue +++ b/src/components/task.vue @@ -913,9 +913,10 @@ export default { */ async handleRedirectToTask(data) { const tokenId = data?.params[0]?.tokenId; - const newTaskUserId = data?.params[0]?.userId; // User assigned to the new task (from the backend) - const nodeId = data?.params[0]?.nodeId; - const currentUserId = this.userId; // Current user (who sees the page) = window.ProcessMaker.user.id + const newTaskUserId = data?.params[0]?.userId; // User assigned to the new task (from the backend) + const nodeId = data?.params[0]?.nodeId; + // Current user: prop > window.ProcessMaker.user > task assignee (when viewing assigned task) + const currentUserId = this.userId ?? window.ProcessMaker?.user?.id ?? this.task?.user?.id; const elementDestType = this.task?.elementDestination?.type; // Redirect if the new task is assigned to the current user, or if it is taskSource const isNewTaskForCurrentUser = tokenId && (newTaskUserId === currentUserId || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource'))); @@ -948,9 +949,9 @@ export default { * * @param {Object} redirectData - The redirect data object. */ - isSameUser(redirectData) { + isSameUser(redirectData) { const newTaskUserId = redirectData?.params?.[0]?.userId; - const currentUserId = this.userId; + const currentUserId = this.userId ?? window.ProcessMaker?.user?.id ?? this.task?.user?.id; const elementDestType = this.task?.elementDestination?.type; const userIdMatch = newTaskUserId === currentUserId || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource'));