Documentation
¶
Overview ¶
Package workflow - the editorial workflow module: content items of the types following it move between states (draft, in review, …) by transitions the roles may make; a state publishes or unpublishes the item.
Index ¶
- Constants
- Variables
- func RegisterRoutes(r modulekit.Mux, c *Controller, ...)
- func Wire(d modulekit.Deps) modulekit.Parts
- type Config
- type Controller
- func (c *Controller) KeepLock(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Queue(w http.ResponseWriter, r *http.Request)
- func (c *Controller) ReleaseLock(w http.ResponseWriter, r *http.Request)
- func (c *Controller) SaveSettings(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)
- func (c *Controller) TakeLock(w http.ResponseWriter, r *http.Request)
- func (c *Controller) Transition(w http.ResponseWriter, r *http.Request)
- func (c *Controller) TransitionPage(w http.ResponseWriter, r *http.Request)
- type HistoryEntry
- type Lock
- type NodeState
- type Repo
- func (r *Repo) AcquireLock(ctx context.Context, nid, uid int, now, since time.Time) (Lock, error)
- func (r *Repo) AddHistory(ctx context.Context, h HistoryEntry) error
- func (r *Repo) Backfill(ctx context.Context, types []string, states joinStates, now time.Time) ([]int, error)
- func (r *Repo) Config(ctx context.Context) (Config, error)
- func (r *Repo) Counts(ctx context.Context) (map[string]int, error)
- func (r *Repo) History(ctx context.Context, nid, limit int) ([]HistoryEntry, error)
- func (r *Repo) InState(ctx context.Context, state string, limit, offset int) ([]NodeState, int, error)
- func (r *Repo) Lock(ctx context.Context, nid int) (Lock, bool, error)
- func (r *Repo) Locks(ctx context.Context, ids []int, since time.Time) (map[int]Lock, error)
- func (r *Repo) NodeState(ctx context.Context, nid int) (NodeState, bool, error)
- func (r *Repo) ReleaseLock(ctx context.Context, nid, uid int) error
- func (r *Repo) SaveConfig(ctx context.Context, cfg Config) error
- func (r *Repo) SetNodeState(ctx context.Context, nid int, state string, uid int, now time.Time) error
- func (r *Repo) States(ctx context.Context, ids []int) (map[int]NodeState, error)
- func (r *Repo) TakeLock(ctx context.Context, nid, uid int, now time.Time) error
- type State
- type Transition
- type Workflow
- func (w *Workflow) Allowed(ctx context.Context, user *modulekit.User, state string) ([]Transition, error)
- func (w *Workflow) Config(ctx context.Context) (Config, error)
- func (w *Workflow) Handles(ctx context.Context, contentType string) bool
- func (w *Workflow) Make(ctx context.Context, node modulekit.Node, from State, t Transition, ...) error
- func (w *Workflow) SaveConfig(ctx context.Context, db *sql.DB, cfg Config) error
- func (w *Workflow) StateOf(ctx context.Context, node modulekit.Node) (State, error)
Constants ¶
const DefaultLockMinutes = 30
DefaultLockMinutes - LockMinutes until the settings are saved.
Variables ¶
var Assets embed.FS
Assets - the module's templates/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(r modulekit.Mux, c *Controller, admin, signedIn func(http.Handler) http.Handler)
RegisterRoutes registers the settings and the queue with its actions (behind admin), an item's lock's actions (behind signedIn: its editors).
Types ¶
type Config ¶
type Config struct {
States []State
Transitions []Transition
Types []string
LockMinutes int
}
Config - the workflow; LockMinutes - how long an item's form stays locked without its editor's activity (0 - items aren't locked).
func (Config) FirstPublished ¶
FirstPublished - the first published state ("" - none).
type Controller ¶
type Controller struct {
*modulekit.BaseController
// contains filtered or unexported fields
}
Controller - the workflow's settings and the editorial queue.
func NewController ¶
func NewController(base *modulekit.BaseController, db *sql.DB, w *Workflow, nodes modulekit.NodesRepository, types modulekit.ContentTypeService, users users, roles interface { Roles(ctx context.Context) (modulekit.Roles, error) }) *Controller
NewController creates a Controller.
func (*Controller) KeepLock ¶
func (c *Controller) KeepLock(w http.ResponseWriter, r *http.Request)
KeepLock handles POST /workflow/lock/{nid}: the form still edited - its lock kept, or got again if free; JSON lockState.
func (*Controller) Queue ¶
func (c *Controller) Queue(w http.ResponseWriter, r *http.Request)
Queue renders GET /admin/content/workflow?state=…: the items in a state (the first waiting one - not initial, not published - by default), the longest waiting first, with the transitions the user may make from it.
func (*Controller) ReleaseLock ¶
func (c *Controller) ReleaseLock(w http.ResponseWriter, r *http.Request)
ReleaseLock handles POST /workflow/lock/{nid}/release: the form closed unsaved - the user's lock removed.
func (*Controller) SaveSettings ¶
func (c *Controller) SaveSettings(w http.ResponseWriter, r *http.Request)
SaveSettings handles POST /admin/config/workflow: the states and transitions as the form lists them (indexed fields; a row without a label - none, "delete" - dropped), the content types, the locking.
func (*Controller) Settings ¶
func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)
Settings renders GET /admin/config/workflow: the states (a blank row adds one), the transitions (so), the content types following it.
func (*Controller) TakeLock ¶
func (c *Controller) TakeLock(w http.ResponseWriter, r *http.Request)
TakeLock handles POST /workflow/lock/{nid}/take: the lock taken over (PermTakeOver), the form opened.
func (*Controller) Transition ¶
func (c *Controller) Transition(w http.ResponseWriter, r *http.Request)
Transition handles POST /admin/content/workflow/{nid}/{tid}: the item moved by the transition (with its comment, when it takes one), its publishing changed with the item's history; back to the queue.
func (*Controller) TransitionPage ¶
func (c *Controller) TransitionPage(w http.ResponseWriter, r *http.Request)
TransitionPage renders GET /admin/content/workflow/{nid}/{tid}: the transition's confirmation with its comment.
type HistoryEntry ¶
HistoryEntry - a transition made.
type Lock ¶
Lock - an item edited by UID in its form since LockedAt, last active at TouchedAt (workflow_locks).
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo - the module's tables (Backfill reads the core's nodes). A built-in module, tested with the engine, may read the core's tables in its SQL; a module of its own repository goes through the SDK's services instead (docs/modules/sdk.md): the core's columns aren't its API.
func (*Repo) AcquireLock ¶
AcquireLock locks nid for uid at now - its own lock touched, a lock inactive since before since taken over - unless another's active lock holds it: the lock holding nid after.
func (*Repo) AddHistory ¶
func (r *Repo) AddHistory(ctx context.Context, h HistoryEntry) error
AddHistory records a transition of nid.
func (*Repo) Backfill ¶
func (r *Repo) Backfill(ctx context.Context, types []string, states joinStates, now time.Time) ([]int, error)
Backfill records a state for the items of types without one (a type joining the workflow) by states, and returns those on moderation: their publishing is to follow their state.
func (*Repo) Config ¶
Config - the workflow: its states and transitions in order, the content types following it.
func (*Repo) InState ¶
func (r *Repo) InState(ctx context.Context, state string, limit, offset int) ([]NodeState, int, error)
InState - the items in state, the longest waiting first, with how many there are.
func (*Repo) ReleaseLock ¶
ReleaseLock removes uid's lock of nid (none - nothing to do).
func (*Repo) SaveConfig ¶
SaveConfig replaces the workflow's states, transitions and content types with cfg's (in ctx's transaction).
func (*Repo) SetNodeState ¶
func (r *Repo) SetNodeState(ctx context.Context, nid int, state string, uid int, now time.Time) error
SetNodeState records nid's state, since now, by uid.
type State ¶
type State struct {
ID int
Name string
Label string
Color string
Published bool
Initial bool
Weight int
}
State - a state of an item (workflow_states).
type Transition ¶
type Transition struct {
ID int
From []string
To string
Label string
Roles []string
Comment string
Weight int
}
Transition - a move between states (workflow_transitions): from one of From to To, by the button Label, for Roles; Comment - manifest's Comment*.
type Workflow ¶
type Workflow struct {
// contains filtered or unexported fields
}
Workflow - the workflow's settings (read once, kept until saved) and moving items between its states.
func NewWorkflow ¶
func NewWorkflow(repo *Repo, nodes modulekit.NodesRepository, auth modulekit.AuthService) *Workflow
NewWorkflow creates a Workflow.
func (*Workflow) Allowed ¶
func (w *Workflow) Allowed(ctx context.Context, user *modulekit.User, state string) ([]Transition, error)
Allowed - the transitions from state user may make: one of its roles is the transition's, or the user has full access.
func (*Workflow) Make ¶
func (w *Workflow) Make(ctx context.Context, node modulekit.Node, from State, t Transition, user *modulekit.User, comment string) error
Make moves node from its state by t (by user, with comment): records it, sets the node's publishing by the new state (in ctx's transaction: the caller tracks the change).
func (*Workflow) SaveConfig ¶
SaveConfig saves the workflow's settings; the items of a type newly following it get a state (Repo.Backfill): those on moderation the waiting one, unpublished and off moderation as it is.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
migrations
command
Command migrations writes the module's next migration (kosatka.GenerateMigrations), run from the module's root with the two test databases running:
|
Command migrations writes the module's next migration (kosatka.GenerateMigrations), run from the module's root with the two test databases running: |
|
Package ent - the workflow module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, cmd/migrations writes them), apart from the core's: the module's set of migrations (Schema).
|
Package ent - the workflow module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, cmd/migrations writes them), apart from the core's: the module's set of migrations (Schema). |
|
schema
Package schema - the workflow module's own ent schema: its states and transitions, which content types follow it, each item's state and the transitions made.
|
Package schema - the workflow module's own ent schema: its states and transitions, which content types follow it, each item's state and the transitions made. |
|
Package manifest declares the editorial workflow module (its registry entry): states of content items and the transitions between them by role, publishing what reaches a published state.
|
Package manifest declares the editorial workflow module (its registry entry): states of content items and the transitions between them by role, publishing what reaches a published state. |
|
Package translations holds the workflow module's interface catalogs (<lang>.json, see pkg/i18n): the strings only the module's code uses.
|
Package translations holds the workflow module's interface catalogs (<lang>.json, see pkg/i18n): the strings only the module's code uses. |