Documentation
¶
Index ¶
- Variables
- func GetApproverUserNames(ctx context.Context, approvers []model.WorkflowApprover, ...) ([]string, error)
- func GetNotificationRecipients(ctx context.Context, workflow model.Workflow, transition Transition, ...) ([]string, error)
- func NewApproverNoLongerEligibleError(userID string) error
- func NewInsufficientApproverCountError(currentCount, requiredCount int) error
- func NewInsufficientApproversError(required, actual int) error
- func NewInvalidEventActorError(userID string, expectedRole string) error
- func NewTransitionError(transition Transition) error
- type ApprovalMechanism
- type ApprovalSummary
- type InsufficientApproversError
- type KeyActions
- type KeyConfigurationActions
- type Lifecycle
- func (l *Lifecycle) ApplyTransition(ctx context.Context, transition Transition) error
- func (l *Lifecycle) AvailableBusinessUserTransitions(ctx context.Context) []Transition
- func (l *Lifecycle) CanExpire() bool
- func (l *Lifecycle) CanTransition(transition Transition) bool
- func (l *Lifecycle) CheckInsufficientApprovers(eligibleApprovers []*model.WorkflowApprover) bool
- func (l *Lifecycle) Expire(ctx context.Context) error
- func (l *Lifecycle) GetAllApprovers(ctx context.Context) ([]*model.WorkflowApprover, error)
- func (l *Lifecycle) GetApprovalSummary(ctx context.Context) (*ApprovalSummary, error)
- func (l *Lifecycle) ValidateActor(ctx context.Context, transition Transition) error
- func (l *Lifecycle) ValidateAndApplyTransition(ctx context.Context, transition Transition) error
- type ParametersResourceType
- type SystemActions
- type Transition
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidEventActor = errors.New("invalid event actor") ErrInsufficientApproverCount = errors.New("insufficient approvers to transition to next state") ErrApproverNoLongerEligible = errors.New("approver is no longer in the admin group and has not voted yet") ErrTransitionExecution = errors.New("failed to execute transition") ErrWorkflowExecution = errors.New("failed to execute workflow action") ErrUpdateWorkflowState = errors.New("failed to update workflow state") ErrCheckApprovers = errors.New("failed to check approvers") ErrAutomatedTransition = errors.New( "automated transition cannot be triggered by user input", ) ErrInvalidWorkflowState = errors.New("invalid workflow state") ErrInvalidWorkflowType = errors.New("invalid workflow type") ErrCheckApproverDecision = errors.New("failed to check approver decision") ErrListApprovers = errors.New("failed to list approvers") ErrInvalidVotingTransition = errors.New("invalid voting transition") ErrWorkflowGroupNotSufficientMembers = errors.New("insufficient eligible approvers in admin group") ErrUserRemovedFromApproverGroup = errors.New("user is no longer a member of the workflow approver groups") )
var Transitions = []Transition{ TransitionCreate, TransitionRevoke, TransitionReject, TransitionExpire, TransitionApprove, TransitionConfirm, TransitionExecute, TransitionFail, }
Functions ¶
func GetApproverUserNames ¶
func GetApproverUserNames( ctx context.Context, approvers []model.WorkflowApprover, idm identitymanagement.IdentityManagement, ) ([]string, error)
func GetNotificationRecipients ¶
func GetNotificationRecipients( ctx context.Context, workflow model.Workflow, transition Transition, idm identitymanagement.IdentityManagement, ) ([]string, error)
GetNotificationRecipients returns the usernames to notify for a workflow transition.
func NewApproverNoLongerEligibleError ¶ added in v0.9.0
NewApproverNoLongerEligibleError creates an error when an approver is no longer in the admin group and has not voted yet.
func NewInsufficientApproverCountError ¶
NewInsufficientApproverCountError creates an error when there are not enough approvers to transition to the next state.
func NewInsufficientApproversError ¶ added in v0.9.0
NewInsufficientApproversError creates a structured error with approver counts
func NewInvalidEventActorError ¶
NewInvalidEventActorError creates an error when the user is not the expected actor of the event.
func NewTransitionError ¶
func NewTransitionError(transition Transition) error
NewTransitionError creates an error when a transition fails.
Types ¶
type ApprovalMechanism ¶
type ApprovalMechanism string
const (
ApprovalMechanismTargetScore ApprovalMechanism = "TARGET_SCORE"
)
type ApprovalSummary ¶
type ApprovalSummary struct {
Mechanism ApprovalMechanism
Approvals int
Rejections int
Pending int
TargetScore int
}
type InsufficientApproversError ¶ added in v0.9.0
InsufficientApproversError is a structured error that carries approver count context
func (*InsufficientApproversError) Error ¶ added in v0.9.0
func (e *InsufficientApproversError) Error() string
func (*InsufficientApproversError) Unwrap ¶ added in v0.9.0
func (e *InsufficientApproversError) Unwrap() error
type KeyActions ¶
type KeyConfigurationActions ¶
type Lifecycle ¶
type Lifecycle struct {
Workflow *model.Workflow
StateMachine *fsm.FSM
ActorID string
Repository repo.Repo
KeyActions KeyActions
KeyConfigurationActions KeyConfigurationActions
SystemActions SystemActions
MinimumApproverCount int
EligibleApproverIDs map[string]bool // Optional: if set, only these approvers count for voting
ActorApproverGroupIDs []uuid.UUID // Optional: if set, validates actor is still in approver groups
}
func NewLifecycle ¶
func NewLifecycle(workflow *model.Workflow, keyActions KeyActions, keyConfigurationActions KeyConfigurationActions, systemActions SystemActions, repo repo.Repo, actorID string, minimumApproverCount int, ) *Lifecycle
NewLifecycle creates a new Lifecycle object for the given workflow with a state machine that defines the possible transitions.
func (*Lifecycle) ApplyTransition ¶
func (l *Lifecycle) ApplyTransition(ctx context.Context, transition Transition) error
ApplyTransition applies a transition without actor validation. Use only when the caller has already established authority through other means and actor validation must be skipped (e.g. auto-reject after vote).
func (*Lifecycle) AvailableBusinessUserTransitions ¶
func (l *Lifecycle) AvailableBusinessUserTransitions(ctx context.Context) []Transition
AvailableBusinessUserTransitions returns the list of transitions that can be performed by business users (i.e., non-automated transitions) after the creation of the workflow.
func (*Lifecycle) CanTransition ¶
func (l *Lifecycle) CanTransition(transition Transition) bool
CanTransition checks if the workflow can transition to the given state
func (*Lifecycle) CheckInsufficientApprovers ¶ added in v0.9.0
func (l *Lifecycle) CheckInsufficientApprovers( eligibleApprovers []*model.WorkflowApprover, ) bool
CheckInsufficientApprovers determines if eligible approvers can meet threshold. Takes pre-fetched eligible list (no external calls) - pure business logic.
func (*Lifecycle) GetAllApprovers ¶ added in v0.9.0
func (*Lifecycle) GetApprovalSummary ¶
func (l *Lifecycle) GetApprovalSummary(ctx context.Context) (*ApprovalSummary, error)
func (*Lifecycle) ValidateActor ¶
func (l *Lifecycle) ValidateActor(ctx context.Context, transition Transition) error
ValidateActor validates the actor of the event
func (*Lifecycle) ValidateAndApplyTransition ¶ added in v0.9.0
func (l *Lifecycle) ValidateAndApplyTransition(ctx context.Context, transition Transition) error
ValidateAndApplyTransition wraps the execution of a transition in the state machine triggered by user input
type ParametersResourceType ¶
type ParametersResourceType string
ParametersResourceType is stored as an opaque varchar.
const ( ParametersResourceTypeKey ParametersResourceType = "KEY" ParametersResourceTypeKeyConfiguration ParametersResourceType = "KEY_CONFIGURATION" )
func (ParametersResourceType) String ¶
func (t ParametersResourceType) String() string
type SystemActions ¶
type Transition ¶
type Transition string
Transition is a state-machine event name.
const ( TransitionCreate Transition = "CREATE" TransitionRevoke Transition = "REVOKE" TransitionReject Transition = "REJECT" TransitionExpire Transition = "EXPIRE" TransitionApprove Transition = "APPROVE" TransitionConfirm Transition = "CONFIRM" TransitionExecute Transition = "EXECUTE" TransitionFail Transition = "FAIL" )
func (Transition) String ¶
func (t Transition) String() string