shared

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Urge errors. Template parameters:
	//   {{.minutes}} — cooldown window in minutes
	ErrMessageUrgeTooFrequent = "approval_urge_too_frequent"

	// Form field validation errors. Template parameters:
	//   {{.field}} — field label or key
	//   {{.min}}   — minimum length / value
	//   {{.max}}   — maximum length / value
	ErrMessageFormFieldNotDefined        = "approval_form_field_not_defined"
	ErrMessageFormFieldRequired          = "approval_form_field_required"
	ErrMessageFormFieldMustBeString      = "approval_form_field_must_be_string"
	ErrMessageFormFieldMustBeNumber      = "approval_form_field_must_be_number"
	ErrMessageFormFieldMustBeInteger     = "approval_form_field_must_be_integer"
	ErrMessageFormFieldMinLength         = "approval_form_field_min_length"
	ErrMessageFormFieldMaxLength         = "approval_form_field_max_length"
	ErrMessageFormFieldInvalidValidation = "approval_form_field_invalid_validation"
	ErrMessageFormFieldPatternMismatch   = "approval_form_field_pattern_mismatch"
	ErrMessageFormFieldMinValue          = "approval_form_field_min_value"
	ErrMessageFormFieldMaxValue          = "approval_form_field_max_value"
	ErrMessageFormFieldEmpty             = "approval_form_field_empty"
	ErrMessageFormFieldInvalidFileItem   = "approval_form_field_invalid_file_item"
	ErrMessageFormFieldMustBeFile        = "approval_form_field_must_be_file"
	ErrMessageFormFieldInvalidValue      = "approval_form_field_invalid_value"
	ErrMessageFormFieldMustBeRowList     = "approval_form_field_must_be_row_list"
	ErrMessageFormFieldMustBeRowObject   = "approval_form_field_must_be_row_object"
	ErrMessageFormFieldMinRows           = "approval_form_field_min_rows"
	ErrMessageFormFieldMaxRows           = "approval_form_field_max_rows"
	ErrMessageFormFieldTableCell         = "approval_form_field_table_cell"
)

Message IDs for the approval module's i18n keys. Only constants referenced cross-file (template params, factory errors, or mapping tables) are defined here — they template dynamic errors built inside the module. Single-use sentinel keys are inlined directly at their result.Err definition in the public approval/api_errors.go, which is also where the ErrCode* constants live so hosts can match Service errors.

Variables

View Source
var SystemOperator = approval.UserInfo{ID: "system", Name: "系统"}

SystemOperator is the operator identity stamped on actions the engine performs without a human decision: timeout auto-processing, auto-pass execution types, consecutive-approver passes, and similar. Sharing one identity keeps audit trails queryable by a single well-known operator ID.

Functions

func ComputeTaskDeadline

func ComputeTaskDeadline(timeoutHours int) *timex.DateTime

ComputeTaskDeadline calculates a task deadline from timeout hours. Returns nil when timeout is disabled.

func HasText added in v0.50.0

func HasText(s *string) bool

HasText reports whether an optional string carries a non-blank value.

func HasUnreadCCRecords added in v0.29.0

func HasUnreadCCRecords(ctx context.Context, db orm.DB, instanceID, nodeID, visitID string) (bool, error)

HasUnreadCCRecords reports whether the CC node still has any record awaiting a read confirmation. It is the single source of truth for read-confirm CC node completion: both node entry (engine.CCProcessor deciding wait vs. continue) and the mark-read path (NodeService.AdvanceCCNodeIfAllRead deciding whether to advance) consult it, so the two can never disagree about whether the node is done. A node that resolved to zero recipients has no records and is therefore already complete — it must not wait, or nothing could ever advance it.

func InsertAutoCCRecords

func InsertAutoCCRecords(ctx context.Context, db orm.DB, instanceID, nodeID, visitID string, userIDs []string, userInfos map[string]approval.UserInfo) ([]string, error)

InsertAutoCCRecords inserts non-manual CC records and returns newly inserted IDs.

func InsertCCRecords

func InsertCCRecords(
	ctx context.Context,
	db orm.DB,
	instanceID string,
	nodeID *string,
	visitID *string,
	userIDs []string,
	userInfos map[string]approval.UserInfo,
	isManual bool,
) ([]string, error)

InsertCCRecords inserts CC records for the given users and returns only the newly inserted user IDs (existing records are ignored). Each record snapshots the recipient's display info — name and department — as resolved at send time.

Callers must hold an instance-level FOR UPDATE lock to prevent concurrent inserts from racing on the existence check.

nodeID and visitID are set together: a node-anchored record always belongs to one traversal, so dedup is visit-scoped — a rollback redo notifies (and waits) again. Instance-level records (both nil) dedup across the lifetime.

func InsertManualCCRecords

func InsertManualCCRecords(ctx context.Context, db orm.DB, instanceID, nodeID, visitID string, userIDs []string, userInfos map[string]approval.UserInfo) ([]string, error)

InsertManualCCRecords inserts manual CC records and returns newly inserted IDs.

func NormalizeUniqueIDs

func NormalizeUniqueIDs(ids []string) []string

NormalizeUniqueIDs trims, deduplicates, and filters empty IDs while preserving first-seen order.

func ResolveUserInfo added in v0.35.0

func ResolveUserInfo(ctx context.Context, resolver approval.UserInfoResolver, userID string) approval.UserInfo

ResolveUserInfo resolves a single user ID to its display info. Returns a zero UserInfo on failure (best-effort for display-only fields); the ID field is always populated so callers can snapshot it verbatim.

func ResolveUserInfoMap added in v0.35.0

func ResolveUserInfoMap(ctx context.Context, resolver approval.UserInfoResolver, ids []string) (map[string]approval.UserInfo, error)

ResolveUserInfoMap batch-resolves user IDs to a map of ID→UserInfo (name plus optional department, per the host resolver). Missing IDs are simply absent — indexing the map yields a zero UserInfo whose fields are empty. Returns an error if the resolver fails.

func ResolveUserInfoMapSilent added in v0.35.0

func ResolveUserInfoMapSilent(ctx context.Context, resolver approval.UserInfoResolver, ids []string) map[string]approval.UserInfo

ResolveUserInfoMapSilent batch-resolves user IDs to a map of ID→UserInfo. Silently returns an empty map on resolver failure (best-effort for display-only fields).

func SelectionIndex added in v0.50.0

func SelectionIndex[K ~string](descriptors []approval.KindDescriptor[K]) map[K]approval.SelectionMode

SelectionIndex maps each descriptor's kind to the input it requires — the shape validation consumes, derived from the registered resolver set.

func ToFloat64 added in v0.29.0

func ToFloat64(value any) (float64, bool)

ToFloat64 normalizes any JSON-decoded or Go-native numeric value to float64. It is the shared numeric bridge for form-data handling: condition evaluation and form validation both compare user-supplied numbers, and both must accept the full spread of types a decoder or caller may produce.

func UserHasRole added in v0.29.0

func UserHasRole(ctx context.Context, svc approval.AssigneeService, userID, roleID string) (bool, error)

UserHasRole reports whether the user currently holds the role. It is the single source of truth for role-membership checks: it prefers the host's direct RoleMembershipChecker capability and falls back to listing the role's members (correct for any host, but linear in role size). Routing every caller through it keeps the read and validation paths from answering the same question two different ways. A nil service reports no membership.

func UserInfos added in v0.35.0

func UserInfos(ids []string, infos map[string]approval.UserInfo) []approval.UserInfo

UserInfos builds the ordered person list for the given IDs from a resolved info map. An ID missing from the map still yields an entry carrying the ID, so unresolvable users stay visible in the record.

Types

type CreateFlowInitiatorCmd

type CreateFlowInitiatorCmd struct {
	Kind approval.InitiatorKind
	IDs  []string
}

CreateFlowInitiatorCmd contains the parameters for creating a flow initiator.

type FlowGraph

type FlowGraph struct {
	Flow    *approval.Flow        `json:"flow"`
	Version *approval.FlowVersion `json:"version"`
	Nodes   []approval.FlowNode   `json:"nodes"`
	Edges   []approval.FlowEdge   `json:"edges"`
}

FlowGraph contains the complete flow graph for a version.

type FlowVersionSummary added in v0.39.0

type FlowVersionSummary struct {
	ID          string                 `json:"id"`
	FlowID      string                 `json:"flowId"`
	Version     int                    `json:"version"`
	Status      approval.VersionStatus `json:"status"`
	Description *string                `json:"description,omitempty"`
	StorageMode approval.StorageMode   `json:"storageMode"`
	PublishedAt *timex.DateTime        `json:"publishedAt,omitempty"`
	PublishedBy *string                `json:"publishedBy,omitempty"`
	CreatedAt   timex.DateTime         `json:"createdAt"`
	CreatedBy   string                 `json:"createdBy"`
}

FlowVersionSummary is the version-list projection of a FlowVersion: identity and lifecycle metadata without the definition payloads (FlowSchema / FormSchema / FormFields), which a version list never renders. A single version's full definition is fetched through get_graph with an explicit version id.

type KindRuleFault added in v0.50.0

type KindRuleFault int

KindRuleFault names what is wrong with one assignee / CC / initiator rule, leaving the error wording to the caller: the same three checks are made at flow deploy (which reports internal design errors) and at flow save (which reports API errors), and the checks must not drift between them.

const (
	// KindRuleOK means the rule is executable.
	KindRuleOK KindRuleFault = iota
	// KindRuleUnknownKind means no resolver is registered for the kind, so
	// nothing could execute the rule.
	KindRuleUnknownKind
	// KindRuleIDsRequired means the kind selects from a catalog but the rule
	// picked nothing. A rule that selects nobody matches nobody.
	KindRuleIDsRequired
	// KindRuleFormFieldRequired means the kind reads its value from the form
	// but the rule names no field.
	KindRuleFormFieldRequired
)

func CheckKindRule added in v0.50.0

func CheckKindRule[K ~string](kind K, ids []string, formField *string, selections map[K]approval.SelectionMode) KindRuleFault

CheckKindRule validates one rule against the registered kind vocabulary: the kind must resolve, and whatever input its selection mode declares must be present. It is the single place that turns a SelectionMode into a save-time requirement, so registering a kind is all a host has to do for its rules to be validated like a built-in's.

type OrderedUnique

type OrderedUnique[T comparable] struct {
	// contains filtered or unexported fields
}

OrderedUnique stores unique values while preserving first-seen order.

func NewOrderedUnique

func NewOrderedUnique[T comparable](capacity int) *OrderedUnique[T]

NewOrderedUnique creates an ordered-unique container with optional capacity.

func (*OrderedUnique[T]) Add

func (o *OrderedUnique[T]) Add(value T) bool

Add inserts value only if it does not already exist, preserving insertion order.

func (*OrderedUnique[T]) AddAll

func (o *OrderedUnique[T]) AddAll(values ...T) int

AddAll inserts multiple values and returns how many were newly added.

func (*OrderedUnique[T]) Contains

func (o *OrderedUnique[T]) Contains(value T) bool

Contains reports whether value already exists in the set.

func (*OrderedUnique[T]) Len

func (o *OrderedUnique[T]) Len() int

Len returns the number of unique values.

func (*OrderedUnique[T]) ToSlice

func (o *OrderedUnique[T]) ToSlice() []T

ToSlice returns a copy of ordered unique values.

Jump to

Keyboard shortcuts

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