service

package
v0.21.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

type TaskContext struct {
	Instance *approval.Instance
	Task     *approval.Task
	Node     *approval.FlowNode
}

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 NewTaskService

func NewTaskService() *TaskService

NewTaskService creates a new TaskService.

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

func (*TaskService) CancelInstanceTasks(ctx context.Context, db orm.DB, instanceID string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL