Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,13 @@ func (s *StepExecutionService) GetMyAssignments(userID, userEmail string, filter
query = query.Where("step_executions.status = ?", filter.Status)
}

// Apply due date filters (on workflow execution)
// Filter on effective due date: step's own due_date takes precedence over the
// workflow execution's due_date, mirroring getEffectiveDueDate in the UI.
if filter.DueBefore != nil {
query = query.Where("workflow_executions.due_date <= ?", filter.DueBefore)
query = query.Where("COALESCE(step_executions.due_date, workflow_executions.due_date) <= ?", filter.DueBefore)
}
if filter.DueAfter != nil {
query = query.Where("workflow_executions.due_date >= ?", filter.DueAfter)
query = query.Where("COALESCE(step_executions.due_date, workflow_executions.due_date) >= ?", filter.DueAfter)
}

// Apply workflow definition filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workflows
import (
"context"
"testing"
"time"

"github.com/compliance-framework/api/internal/service/relational"
"github.com/google/uuid"
Expand Down Expand Up @@ -870,3 +871,45 @@ func TestStepExecutionService_Integration(t *testing.T) {
require.NoError(t, err)
assert.Len(t, completedSteps, 2)
}

// TestGetMyAssignments_FiltersOnStepDueDate covers BCH-1156: when a step execution
// has its own due_date but the parent workflow_execution.due_date is NULL, a date
// range filter must still match using the step's due_date (the effective due date
// shown by the UI).
func TestGetMyAssignments_FiltersOnStepDueDate(t *testing.T) {
db := setupTestDB(t)
service := NewStepExecutionService(db, nil)

workflowDef := createTestWorkflowDefinition()
require.NoError(t, db.Create(workflowDef).Error)

instance := createTestWorkflowInstance(workflowDef.ID)
require.NoError(t, db.Create(instance).Error)

// Execution has no due_date — mirrors real data where due_date lives on the step
execution := createTestWorkflowExecution(instance.ID)
execution.Status = "in_progress"
require.NoError(t, db.Create(execution).Error)

stepDef := createTestWorkflowStepDefinition(workflowDef.ID)
require.NoError(t, db.Create(stepDef).Error)

may28 := time.Date(2026, 5, 28, 10, 0, 0, 0, time.UTC)
stepExec := createTestStepExecution(execution.ID, stepDef.ID)
stepExec.DueDate = &may28
stepExec.AssignedToType = "user"
stepExec.AssignedToID = "test-user-abc"
require.NoError(t, db.Create(stepExec).Error)

after := time.Date(2026, 5, 26, 0, 0, 0, 0, time.UTC)
before := time.Date(2026, 5, 28, 23, 59, 59, 0, time.UTC)

results, total, err := service.GetMyAssignments("test-user-abc", "", MyAssignmentsFilter{
DueAfter: &after,
DueBefore: &before,
}, 10, 0)

require.NoError(t, err)
assert.Equal(t, int64(1), total, "step with due_date on step_executions (not workflow_executions) must be returned")
assert.Len(t, results, 1)
}
Loading