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 QueueItem
- type QueueSort
- 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, sort QueueSort, limit, offset int) ([]QueueItem, 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) MailOff(ctx context.Context, userIDs []int) (map[int]bool, 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) SetMail(ctx context.Context, userID int, on bool) 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 ( QueueSortUpdated = "updated" QueueSortType = "type" QueueSortAuthor = "author" QueueSortTitle = "title" )
The queue's sort columns (QueueSort.Key, its "sort" parameter).
const ( MailAuthor = manifest.Name + ".author" MailWaiting = manifest.Name + ".waiting" )
The module's e-mails (modulekit.AddMail): to an item's author when someone else moved it; to who it waits for when it comes to a state neither initial nor on the site (mailer.waitingFor).
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).
func Wire ¶
Wire - the workflow publishing its content types' items through their forms (SetNodeWorkflow), an item's history on its page for who may edit it (AddNodePage), its settings and the editorial queue, the count of what waits for the user by the queue's menu item; the state's filter, field and sort criterion in content Views.
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 QueueItem ¶ added in v0.1.1
QueueItem - an item of the queue: its state and when its content was last saved.
type QueueSort ¶ added in v0.1.1
QueueSort - the queue's order: a column (QueueSort*) and its direction.
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, sort QueueSort, limit, offset int) ([]QueueItem, int, error)
InState - a page of the items in state in sort's order (an unknown key - the last saved first), with how many there are.
func (*Repo) MailOff ¶ added in v0.1.2
MailOff - those of userIDs who turned the module's e-mails off.
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) SetMail ¶ added in v0.1.2
SetMail stores whether the user gets the module's e-mails (the row made on the first save).
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), then sends its e-mails in the background (mailer.later).
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 - a change of the site's, not an edit: their last save stays (SetPublishing).
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. |