Files
archie/internal/daemon/workflow_org.go
T
sam f2b8681611 refactor(workflow): stop assuming a human decides
An approval, ask or park can be resolved by an operator, a rule, a
classifier or automatically, so the vocabulary stops naming a person:

- step type human.approve -> workflow.approve
- park class needs_human -> needs_decision (ParkNeedsDecision)
- event kinds human_* -> operator_*
- alert kind task.needs_human -> task.needs_decision
- status grouping "needs you" -> "needs attention"

0061 rewrites the stored values, including the approval step type in the
workflow-definitions resource and each task's pinned definition, with the
digest recomputed so resumed tasks still match.
2026-10-25 17:31:16 +11:00

39 lines
1.5 KiB
Go

package daemon
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/org"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// workflowContext forwards a task's identity so the State Store selects its
// org's definitions. An identity assigned elsewhere cannot supply the pin.
func (d *Daemon) workflowContext(ctx context.Context, task *workflow.Task) (context.Context, error) {
owner := task.Org
if owner == "" {
owner = org.DefaultOrgID
}
if d.Principals == nil {
principal, forwarded := access.PrincipalFromContext(ctx)
if owner != org.DefaultOrgID || org.OrgFromContext(ctx) != owner || (forwarded && principal.Org != "" && principal.Org != owner) {
return nil, pinFailure{taskstate.ParkNeedsDecision, fmt.Errorf("workflow org %s: principal unavailable", owner)}
}
return ctx, nil
}
principal, err := d.Principals.PrincipalFor(ctx, d.publisherIdentity(task.Identity))
if err != nil {
return nil, pinFailure{taskstate.ParkTransient, fmt.Errorf("workflow principal: %w", err)}
}
if principal.Org == "" {
principal.Org = org.DefaultOrgID
}
if principal.Org != owner {
return nil, pinFailure{taskstate.ParkNeedsDecision, fmt.Errorf("workflow identity belongs to org %s, task belongs to %s", principal.Org, owner)}
}
return org.WithOrg(access.WithPrincipal(ctx, principal), owner), nil
}