Documentation
¶
Overview ¶
Package eppreview is a form's preview (#2494): its owner, or an administrator, sees the form rendered as /forms/<endpoint> renders it, from a saved version or an unsaved source, with no endpoint bound and nobody else involved.
Opening a preview stores one row naming the script, the version or the source, and who opened it, with the identity they opened it with; it expires within the hour. Its page (internal/endpoint/epformpage) renders only for that person, and its spec and submissions are answered here, by the endpoint runner's own rules (eprun.ServePreview), with form_spec and form_submit run as drafts under that identity: the draft's write barrier stops every write, and nothing a submission carries is stored, saved, notified or recorded.
Index ¶
Constants ¶
const ( PagePrefix = "/forms/_preview/" APIPrefix = "/endpoints/_preview/" )
The routes a preview is reached at. An endpoint's name never starts with "_", so neither is ever an endpoint's or a form page's address.
const PortalPath = "/api/v1/portal/scripts/{id}/form-preview"
PortalPath is the route the script page opens a preview through.
const TTL = 30 * time.Minute
TTL is how long a preview can be opened after it was created.
Variables ¶
var ErrNotAllowed = errors.New("eppreview: not allowed")
ErrNotAllowed is a preview opened by someone who may not open it.
var ErrNotFound = errors.New("eppreview: no such preview")
ErrNotFound is a preview that does not exist or has expired.
Functions ¶
This section is empty.
Types ¶
type Drafts ¶
type Drafts interface {
Run(ctx context.Context, req scriptdraft.Request) (*scriptdraft.Outcome, error)
}
Drafts runs a draft (internal/platform/scriptdraft).
type Handler ¶
type Handler struct {
Store *Store
Scripts Scripts
Runner *eprun.Runner
Drafts Drafts
// ViewerKey opens the viewer token the preview's page signed for the
// person who opened it (epform.ViewerKey).
ViewerKey []byte
}
Handler answers a preview's spec and submissions at APIPrefix+{id}.
type Opened ¶
type Opened struct {
ID string `json:"id"`
URL string `json:"url"`
ExpiresAt time.Time `json:"expires_at"`
}
Opened is a preview just opened: its id and the address its page is at.
type Portal ¶
type Portal struct {
Previews *Previews
Scripts interface {
GetByID(ctx context.Context, id string) (*script.Script, error)
}
// Opener is who made a request, nil for none.
Opener func(r *http.Request) *Opener
}
Portal opens previews from the portal's script page.
type Previews ¶
type Previews struct {
Store *Store
Versions Versions
// BaseURL is the deployment's public address, empty for a relative link.
BaseURL string
}
Previews opens previews.
func (*Previews) Open ¶
func (p *Previews) Open(ctx context.Context, o Opener, sc *script.Script, version int, source string) (*Opened, error)
Open opens a preview of sc for o: the unsaved source when source is not empty, else the saved version (the latest for 0). Only the script's owner or an administrator opens one, and only of a form.
type Record ¶
type Record struct {
ID string
ScriptID string
// Version is the saved version rendered, 0 for Source.
Version int
// Source is the unsaved source rendered, empty for Version.
Source string
CreatedBy string
UserID string
Roles []string
AuthType string
CreatedAt time.Time
ExpiresAt time.Time
}
Record is one preview.
type RefusedError ¶
type RefusedError struct{ Msg string }
RefusedError is a preview refused for a reason the caller can act on.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
type Scripts ¶
type Scripts interface {
GetByID(ctx context.Context, id string) (*script.Script, error)
GetVersion(ctx context.Context, scriptID string, version int) (*script.Version, error)
}
Scripts reads the script a preview renders.