eppreview

package
v1.167.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const PortalPath = "/api/v1/portal/scripts/{id}/form-preview"

PortalPath is the route the script page opens a preview through.

View Source
const TTL = 30 * time.Minute

TTL is how long a preview can be opened after it was created.

Variables

View Source
var ErrNotAllowed = errors.New("eppreview: not allowed")

ErrNotAllowed is a preview opened by someone who may not open it.

View Source
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}.

func (*Handler) Mount

func (h *Handler) Mount(mux *http.ServeMux)

Mount registers the routes on mux.

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 Opener

type Opener struct {
	UserID   string
	Email    string
	Roles    []string
	AuthType string
	Admin    bool
}

Opener is who opens a preview, and the identity its drafts run as.

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.

func (*Portal) Register

func (p *Portal) Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler)

Register mounts the route behind wrap, the portal's authentication.

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.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store keeps previews.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore builds the store over db.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Record, error)

Get reads a preview that has not expired.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, r *Record) error

Insert stores a preview, removing the expired ones first.

func (*Store) Owner

func (s *Store) Owner(ctx context.Context, id string) (string, error)

Owner is the address of the person who opened a preview, which is the one person its page renders for (internal/endpoint/epformpage).

type Versions

type Versions interface {
	GetVersion(ctx context.Context, scriptID string, version int) (*script.Version, error)
}

Versions reads a script's saved versions.

Jump to

Keyboard shortcuts

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