Introduce internal/contracts/vocabulary for state/role/error sentinels, alias through docgov, and retarget hot production consumers so coordinator no longer imports docgov for vocabulary-only use.
88 lines
4.2 KiB
Go
88 lines
4.2 KiB
Go
// Package vocabulary holds stable, behavior-free shared enums and sentinel values.
|
|
// Domain packages keep invariants and typed error wrappers; consumers import this
|
|
// leaf instead of pulling docgov solely for state/role/error strings.
|
|
package vocabulary
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// DocumentState is the controlled-document lifecycle vocabulary.
|
|
type DocumentState string
|
|
|
|
const (
|
|
StateDrafting DocumentState = "drafting" // 编制中 (草稿)
|
|
StateReviewing DocumentState = "reviewing" // 审核中 (待审核, 锁定)
|
|
StateApproving DocumentState = "approving" // 批准中 (待批准, 锁定)
|
|
StateApproved DocumentState = "approved" // 已批准 (归档生效, 终态锁定)
|
|
StateRejected DocumentState = "rejected" // 已驳回 (中间状态或流转标记)
|
|
)
|
|
|
|
// UserRole is the document-governance duty role vocabulary.
|
|
type UserRole string
|
|
|
|
const (
|
|
RoleAuthor UserRole = "author" // 编制人
|
|
RoleReviewer UserRole = "reviewer" // 审核人
|
|
RoleApprover UserRole = "approver" // 批准人
|
|
RoleSystem UserRole = "system" // 系统/智能体小队
|
|
)
|
|
|
|
// LeaseHolderType is the edit-lease holder vocabulary (orthogonal to IsLocked).
|
|
type LeaseHolderType string
|
|
|
|
const (
|
|
LeaseHolderNone LeaseHolderType = ""
|
|
LeaseHolderSquad LeaseHolderType = "squad"
|
|
LeaseHolderHuman LeaseHolderType = "human"
|
|
)
|
|
|
|
// Default lease TTLs shared by squad/human writers.
|
|
const (
|
|
DefaultSquadLeaseTTL = 30 * time.Minute
|
|
DefaultHumanLeaseTTL = 15 * time.Minute
|
|
)
|
|
|
|
// CommentType is the document comment-kind vocabulary.
|
|
type CommentType string
|
|
|
|
const (
|
|
CommentGeneral CommentType = "comment" // 普通批注
|
|
CommentSuggestion CommentType = "suggestion" // 修改建议
|
|
CommentRejection CommentType = "reject_reason" // 驳回原因
|
|
)
|
|
|
|
// Cross-module sentinel errors. Wire/HTTP mapping stays in server; wrappers with
|
|
// extra fields (e.g. DocumentBusyError) remain in the owning domain package.
|
|
var (
|
|
ErrDocumentNotFound = errors.New("docgov: document not found")
|
|
ErrDocumentLocked = errors.New("docgov: document is locked, direct modification prohibited")
|
|
ErrOnlyAuthorCanEdit = errors.New("docgov: only the designated author is allowed to edit or modify document content")
|
|
ErrReviewerCannotEdit = errors.New("docgov: reviewers are not allowed to edit document content, only comments and review decisions are permitted")
|
|
ErrApproverCannotEdit = errors.New("docgov: approvers are not allowed to edit document content, only comments and approval decisions are permitted")
|
|
ErrInvalidStateTransition = errors.New("docgov: invalid document lifecycle state transition")
|
|
ErrRejectReasonRequired = errors.New("docgov: rejection reason must not be empty")
|
|
ErrUnauthorizedActor = errors.New("docgov: actor is not authorized for this role or action")
|
|
ErrProposalNotFound = errors.New("docgov: change proposal not found")
|
|
ErrProposalAlreadyDecided = errors.New("docgov: change proposal has already been decided")
|
|
ErrChangeProposalPending = errors.New("docgov: document is claimed and has pending change proposal waiting for author approval")
|
|
ErrDocumentBusy = errors.New("docgov: document edit lease is held by another writer")
|
|
ErrStaleFencing = errors.New("docgov: stale lease fencing token")
|
|
ErrLeaseExpired = errors.New("docgov: document edit lease has expired")
|
|
ErrLeaseNotHeld = errors.New("docgov: caller does not hold the document edit lease")
|
|
ErrForceEditNotAllowed = errors.New("docgov: force_direct_edit requires an approved_by_author proposal and unlocked drafting document")
|
|
ErrContentProjectionMissing = errors.New("docgov: document content projection missing")
|
|
ErrContentProjectionEmpty = errors.New("docgov: document content projection empty")
|
|
ErrContentIntegrityMismatch = errors.New("docgov: document content integrity mismatch")
|
|
)
|
|
|
|
// Stable machine-readable content-error codes (HTTP status mapping stays in server).
|
|
const (
|
|
ErrCodeDocumentNotFound = "DOCUMENT_NOT_FOUND"
|
|
ErrCodeProjectionMissing = "DOCUMENT_CONTENT_PROJECTION_MISSING"
|
|
ErrCodeProjectionEmpty = "DOCUMENT_CONTENT_PROJECTION_EMPTY"
|
|
ErrCodeIntegrityMismatch = "DOCUMENT_CONTENT_INTEGRITY_MISMATCH"
|
|
ErrCodeProjectionDrift = "DOCUMENT_CONTENT_PROJECTION_DRIFT"
|
|
)
|