accessv1
import accessv1 "pocketone.dev/ext/contracts/access/v1"
Package accessv1 is the access/v1 contract: the app's policy, which says who holds which grants. Contracts speak only scopes and owners (ext/extkit's access.go); this is the one place auth collections and roles turn into grants.
The policy is an ordered list of rows: an auth collection, an optional PocketBase filter on the caller's own record ("roles ?= 'billing_admin'"), and the grants the row gives ("billing:refunds", "billing:read@all"). A caller holds the union of the grants of every enabled row it matches; matching none, nothing. Three layers, each on top of the one before: extension defaults (registered here, in Go), pocketone.yaml's app `access:`, and the rows a superuser keeps in Settings → Access. A superuser may switch off any default or yaml row. The superusers row (SuperuserRow) is fixed: no layer can change or remove it.
Source: ext/contracts/access/v1.
Constants
const (
SourceFixed = "fixed" // the superusers row
SourceDefault = "default" // an extension's default (Extension names it)
SourceYAML = "yaml" // pocketone.yaml's app `access:`
SourceSettings = "settings" // Settings → Access
)
Sources of a row.
const (
EveryCollection = "*" // every auth collection
)
Who values.
Variables
var Contract = extkit.NewContract[Policy]("access/v1", extkit.One)
Contract is access/v1.
var SuperuserRow = Row{ID: "superusers", Who: core.CollectionNameSuperusers, Grant: []string{"*" + extkit.AllSuffix},
Description: "Superusers can do everything. Fixed.", Source: SourceFixed, Enabled: true}
SuperuserRow is fixed: superusers hold every scope, reaching every owner. Nothing can change it.
Functions
AddDefault
func AddDefault(app core.App, extension string, d Default)
AddDefault registers extension's default row on app. A superuser may switch it off in Settings → Access.
Types
Default
type Default struct {
Name string // unique within the extension; the row's ID is "<extension>.<name>"
Who string // an auth collection's name, or "*"
WhoOf func() string // read at each call instead of Who, for a collection that's a setting (billing's owners)
Where string
Grant []string
Description string
}
Default is a row an extension ships. Register it with AddDefault in Register.
Policy
type Policy interface {
extkit.GrantSource
// Rows is every row, in layer order: the superusers row, extension defaults, pocketone.yaml's, Settings'. Rows a
// superuser switched off are listed with Enabled false.
Rows(ctx context.Context) ([]Row, error)
}
Policy is the app's policy. Its provider is the gate's extkit.GrantSource.
Row
type Row struct {
// ID names the row, stably: "<extension>.<name>" for defaults, "yaml.<n>" and "settings.<n>" for the others. A
// superuser switches a default or yaml row off by its ID.
ID string `json:"id"`
// Who is an auth collection's name, or "*" for every auth collection.
Who string `json:"who"`
// Where, when set, is a PocketBase filter run against the caller's own record (the syntax of API rules):
// "role = 'admin'", "roles.name ?= 'billing_admin'", "verified = true".
Where string `json:"where,omitempty"`
// Grant is what the row gives: scopes, each optionally reaching every owner ("billing", "billing:read@all").
Grant []string `json:"grant"`
// Description says why the row is there, for Settings.
Description string `json:"description,omitempty"`
// Source and Extension say where it came from.
Source string `json:"source"`
Extension string `json:"extension,omitempty"`
// Enabled is false for a default or yaml row a superuser switched off.
Enabled bool `json:"enabled"`
}
Row is one line of the policy.
Defaults
func Defaults(app core.App) []Row
Defaults are app's extension defaults as rows (enabled; the provider applies what a superuser switched off).
Row.Check
func (r Row) Check() error
Check reports what's wrong with r, if anything (the provider also checks Where against the collection).
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.