Documentation
¶
Index ¶
- Variables
- func FilterEditableFormData(formData map[string]any, permissions map[string]approval.Permission) map[string]any
- func MergeFormData(instance *approval.Instance, formData map[string]any, ...)
- type ActionLogParams
- type FlowDefinitionService
- type NodeService
- func (s *NodeService) CheckCCNodeCompletion(ctx context.Context, db orm.DB, instanceID string, records []approval.CCRecord) error
- func (s *NodeService) HandleNodeCompletion(ctx context.Context, db orm.DB, instance *approval.Instance, ...) ([]approval.DomainEvent, error)
- func (s *NodeService) TriggerNodeCC(ctx context.Context, db orm.DB, instance *approval.Instance, ...) error
- type TaskContext
- type TaskContextLoadOptions
- type TaskService
- func (*TaskService) ActivateNextSequentialTask(ctx context.Context, db orm.DB, instance *approval.Instance, ...) error
- func (*TaskService) CanRemoveAssigneeTask(ctx context.Context, db orm.DB, eng *engine.FlowEngine, ...) (bool, error)
- func (*TaskService) CancelInstanceTasks(ctx context.Context, db orm.DB, instanceID string) error
- func (*TaskService) CancelRemainingTasks(ctx context.Context, db orm.DB, instanceID, nodeID string) error
- func (*TaskService) FinishTask(ctx context.Context, db orm.DB, task *approval.Task, ...) error
- func (*TaskService) InsertActionLog(ctx context.Context, db orm.DB, instanceID string, task *approval.Task, ...) error
- func (*TaskService) IsAuthorizedForNodeOperation(ctx context.Context, db orm.DB, task approval.Task, operatorID string) bool
- func (*TaskService) IsInstanceParticipant(ctx context.Context, db orm.DB, instanceID, userID string) (bool, error)
- func (s *TaskService) LoadTaskContextForNodeOperation(ctx context.Context, db orm.DB, taskID string, options TaskContextLoadOptions) (*TaskContext, error)
- func (s *TaskService) PrepareOperation(ctx context.Context, db orm.DB, taskID, operatorID string, ...) (*TaskContext, error)
- type ValidationService
- func (s *ValidationService) CheckInitiationPermission(ctx context.Context, db orm.DB, flowID, applicantID string, ...) (bool, error)
- func (*ValidationService) ValidateFormData(schema *approval.FormDefinition, formData map[string]any) error
- func (*ValidationService) ValidateOpinion(node *approval.FlowNode, opinion string) error
- func (*ValidationService) ValidateRollbackTarget(ctx context.Context, db orm.DB, instance *approval.Instance, ...) error
Constants ¶
This section is empty.
Variables ¶
var Module = fx.Module( "vef:approval:service", fx.Provide( NewFlowDefinitionService, NewTaskService, NewNodeService, NewValidationService, ), )
Module provides all approval services.
Functions ¶
func FilterEditableFormData ¶
func FilterEditableFormData(formData map[string]any, permissions map[string]approval.Permission) map[string]any
FilterEditableFormData filters form data to only include fields that are editable or required based on the node's field permissions configuration.
func MergeFormData ¶
func MergeFormData(instance *approval.Instance, formData map[string]any, permissions map[string]approval.Permission)
MergeFormData filters editable form data and merges it into the instance.
Types ¶
type ActionLogParams ¶
type ActionLogParams struct {
Opinion string
TransferToID string
TransferToName string
RollbackToNodeID string
}
ActionLogParams holds optional fields for InsertActionLog.
type FlowDefinitionService ¶
type FlowDefinitionService struct{}
FlowDefinitionService provides flow-level domain operations.
func NewFlowDefinitionService ¶
func NewFlowDefinitionService() *FlowDefinitionService
NewFlowDefinitionService creates a new FlowDefinitionService.
func (*FlowDefinitionService) ValidateFlowDefinition ¶
func (*FlowDefinitionService) ValidateFlowDefinition(def *approval.FlowDefinition) error
ValidateFlowDefinition validates the structural integrity of a flow definition.
type NodeService ¶
type NodeService struct {
// contains filtered or unexported fields
}
NodeService provides node-level domain operations.
func NewNodeService ¶
func NewNodeService(eng *engine.FlowEngine, pub *dispatcher.EventPublisher, taskSvc *TaskService, userResolver approval.UserInfoResolver) *NodeService
NewNodeService creates a new NodeService.
func (*NodeService) CheckCCNodeCompletion ¶
func (s *NodeService) CheckCCNodeCompletion(ctx context.Context, db orm.DB, instanceID string, records []approval.CCRecord) error
CheckCCNodeCompletion checks if all CC records for CC nodes are read and advances the flow.
func (*NodeService) HandleNodeCompletion ¶
func (s *NodeService) HandleNodeCompletion( ctx context.Context, db orm.DB, instance *approval.Instance, node *approval.FlowNode, ) ([]approval.DomainEvent, error)
HandleNodeCompletion evaluates node completion and handles the result. On PassRulePassed: advances to the next node and cancels remaining tasks. On PassRuleRejected: marks instance as rejected, cancels remaining tasks, and resumes parent flow.
This method mutates instance fields (Status, FinishedAt, CurrentNodeID) in memory. The caller is responsible for persisting instance changes to the database.
func (*NodeService) TriggerNodeCC ¶
func (s *NodeService) TriggerNodeCC(ctx context.Context, db orm.DB, instance *approval.Instance, node *approval.FlowNode, completionResult approval.PassRuleResult) error
TriggerNodeCC creates CC records when a node completes, based on CCTiming configuration.
type TaskContext ¶
TaskContext holds the validated context for task processing operations.
type TaskContextLoadOptions ¶
type TaskContextLoadOptions struct {
OperatorID string
RequireOperatorAssignee bool
RequireTaskPending bool
RequireCurrentNode bool
}
TaskContextLoadOptions controls validations when loading task operation context.
type TaskService ¶
type TaskService struct{}
TaskService provides task-level domain operations.
func (*TaskService) ActivateNextSequentialTask ¶
func (*TaskService) ActivateNextSequentialTask(ctx context.Context, db orm.DB, instance *approval.Instance, node *approval.FlowNode) error
ActivateNextSequentialTask activates the next waiting task in sequential approval.
func (*TaskService) CanRemoveAssigneeTask ¶
func (*TaskService) CanRemoveAssigneeTask(ctx context.Context, db orm.DB, eng *engine.FlowEngine, node *approval.FlowNode, task approval.Task) (bool, error)
CanRemoveAssigneeTask determines whether removing a task can still drive the node to progress (either through remaining actionable tasks or immediate completion under pass-rule evaluation).
func (*TaskService) CancelInstanceTasks ¶
CancelInstanceTasks cancels all pending/waiting tasks for an entire instance.
func (*TaskService) CancelRemainingTasks ¶
func (*TaskService) CancelRemainingTasks(ctx context.Context, db orm.DB, instanceID, nodeID string) error
CancelRemainingTasks cancels all pending/waiting tasks on the given node.
func (*TaskService) FinishTask ¶
func (*TaskService) FinishTask(ctx context.Context, db orm.DB, task *approval.Task, status approval.TaskStatus) error
FinishTask transitions a task to the given status and sets its FinishedAt timestamp.
func (*TaskService) InsertActionLog ¶
func (*TaskService) InsertActionLog( ctx context.Context, db orm.DB, instanceID string, task *approval.Task, operator approval.OperatorInfo, action approval.ActionType, params ActionLogParams, ) error
InsertActionLog creates and inserts an action log entry.
func (*TaskService) IsAuthorizedForNodeOperation ¶
func (*TaskService) IsAuthorizedForNodeOperation(ctx context.Context, db orm.DB, task approval.Task, operatorID string) bool
IsAuthorizedForNodeOperation checks if the operator is authorized to perform node-level operations (e.g., remove assignee). Returns true if the operator is a peer assignee on the same node or a flow admin.
func (*TaskService) IsInstanceParticipant ¶
func (*TaskService) IsInstanceParticipant(ctx context.Context, db orm.DB, instanceID, userID string) (bool, error)
IsInstanceParticipant checks whether the user is related to the instance as applicant, task assignee, or CC recipient.
func (*TaskService) LoadTaskContextForNodeOperation ¶
func (s *TaskService) LoadTaskContextForNodeOperation(ctx context.Context, db orm.DB, taskID string, options TaskContextLoadOptions) (*TaskContext, error)
LoadTaskContextForNodeOperation loads and validates instance/task/node context for node operations. The lock order is always instance first, then task.
func (*TaskService) PrepareOperation ¶
func (s *TaskService) PrepareOperation(ctx context.Context, db orm.DB, taskID, operatorID string, formData map[string]any) (*TaskContext, error)
PrepareOperation loads task context and merges editable form data. Callers that require opinion validation should invoke ValidateOpinion separately.
type ValidationService ¶
type ValidationService struct {
// contains filtered or unexported fields
}
ValidationService provides validation operations.
func NewValidationService ¶
func NewValidationService(assigneeSvc approval.AssigneeService) *ValidationService
NewValidationService creates a new ValidationService.
func (*ValidationService) CheckInitiationPermission ¶
func (s *ValidationService) CheckInitiationPermission(ctx context.Context, db orm.DB, flowID, applicantID string, applicantDepartmentID *string) (bool, error)
CheckInitiationPermission checks if the applicant is allowed to initiate the flow.
func (*ValidationService) ValidateFormData ¶
func (*ValidationService) ValidateFormData(schema *approval.FormDefinition, formData map[string]any) error
ValidateFormData validates submitted form data against the published form schema.
func (*ValidationService) ValidateOpinion ¶
func (*ValidationService) ValidateOpinion(node *approval.FlowNode, opinion string) error
ValidateOpinion checks if an opinion is required but missing.
func (*ValidationService) ValidateRollbackTarget ¶
func (*ValidationService) ValidateRollbackTarget(ctx context.Context, db orm.DB, instance *approval.Instance, currentNode *approval.FlowNode, targetNodeID string) error
ValidateRollbackTarget validates the rollback target node based on the node's RollbackType.