access

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package access holds the presentation side of authorization shared by the team, roles, API key and MCP screens: the permission catalogue as the API returns it, scope labels ("Beta Program list only"), sign-in method and two-factor labels, and the "who can help" helper names.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AndList

func AndList(names []string) string

AndList joins names as "A, B and C".

func AudienceInScope

func AudienceInScope(scope authz.Scope, lists []uuid.UUID, segments int) bool

AudienceInScope reports whether a list scope allows an audience: its lists only, no segment.

func AudienceScopeProblem

func AudienceScopeProblem(l i18n.Lang) string

AudienceScopeProblem says why AudienceInScope refused, in a language.

func CampaignSendProblem

func CampaignSendProblem(ctx context.Context, q *store.Queries, l i18n.Lang, p *authz.Principal, wsID, campaignID uuid.UUID) (string, error)

CampaignSendProblem is SendScopeProblem for a campaign by id, for what acts on a send without loading its campaign: the live monitor and the MCP tools.

func CantGrant

func CantGrant(l i18n.Lang, p authz.Permission, helpers []string) string

CantGrant explains an escalation in a language: "You can't grant segments:sql because you don't hold it. Ask Linh Nguyen."

func ContactInScope

func ContactInScope(ctx context.Context, q *store.Queries, p *authz.Principal, contactID uuid.UUID) (bool, error)

ContactInScope reports whether the caller may see a contact: they aren't limited to some lists, or one of their lists has the contact.

func Groups

func Groups(l i18n.Lang) []string

Groups returns the permission groups in display order, named in a language as Catalog names them.

func Helpers

func Helpers(ctx context.Context, q *store.Queries, wsID uuid.UUID, perm authz.Permission) []string

Helpers names up to two active members who hold perm, Owners first ("Ask Linh Nguyen or Marcus Chen").

func ImpliedBy

func ImpliedBy(set authz.Set, p authz.Permission) authz.Permission

ImpliedBy returns the permission in set that implies p ("campaigns:edit" implies "campaigns:view"), or "" when p stands on its own.

func ListNames

func ListNames(ctx context.Context, q *store.Queries, wsID uuid.UUID) (map[uuid.UUID]string, error)

ListNames maps the workspace's list ids to names.

func NotHoldable

func NotHoldable(l i18n.Lang, p authz.Permission, t authz.ActorType) string

NotHoldable explains in a language why a key or agent can't hold p (authz.HoldableBy).

func OrList

func OrList(names []string) string

OrList joins names as "A, B or C".

func ParseLists

func ParseLists(ids []string) []uuid.UUID

ParseLists parses stored list ids, skipping invalid ones.

func ParseScope

func ParseScope(raw json.RawMessage) authz.Scope

ParseScope reads a stored scope ({} = everything).

func Plural

func Plural(n int, one, many string) string

Plural returns "member" or "members".

func ScopeJSON

func ScopeJSON(s authz.Scope) json.RawMessage

ScopeJSON encodes a scope for storage.

func ScopeKind

func ScopeKind(s authz.Scope, names map[uuid.UUID]string) (kind, value string)

ScopeKind describes a scope for a kept message's select: "all", "list" (one list: value is its name), "only" (one sender domain: the domain) or "other" (value is the lists and domains written in English).

func ScopeLists

func ScopeLists(p *authz.Principal) []uuid.UUID

ScopeLists is the caller's list scope as a query argument: their lists, or an empty array when they see every contact. Never nil: Postgres reads a nil slice as NULL, and "cardinality(@scope_lists) = 0" would then match no one.

func ScopeProblem

func ScopeProblem(l i18n.Lang, err error) string

ScopeProblem is the field problem's sentence for a scope that doesn't resolve, in a language: "Unknown list "…"."

func ScopeText

func ScopeText(s authz.Scope, names map[uuid.UUID]string, listWord bool) i18n.Text

ScopeText keeps a scope's label for later readers (an audit entry's summary): "Beta Program list only", or "all lists" when it places no restriction.

func ScopeWhat

func ScopeWhat(l i18n.Lang, s authz.Scope, names map[uuid.UUID]string) string

ScopeWhat says what a scope covers, without "only", for a table's Scope column: "Beta Program", "2 lists · news.acme.io", or "all lists".

func SendScopeProblem

func SendScopeProblem(l i18n.Lang, scope authz.Scope, lists []uuid.UUID, segments int, senderDomain, senderEmail string) string

SendScopeProblem says, in a language, why a member, key or agent can't start, schedule or resume a campaign's send, or "" when they can: the audience must be their lists only (no segment), and the domain it sends from one of their sender domains.

func SenderDomain

func SenderDomain(domain, email string) string

SenderDomain is the domain a campaign sends from: its sender's sending domain, or the domain of the sender's address when that sending domain is gone. Empty for a campaign without a sender: there is no other From to fall back to when it sends, so Send Readiness blocks it and the engine never starts it.

func Verb

func Verb(p authz.Permission) string

Verb returns the action part of a permission key: "campaigns:edit" → "edit".

Types

type Identity

type Identity struct {
	Kind           string
	ProviderName   string
	ProviderPreset string
}

Identity is a linked social or SSO identity.

type MemberSignInMethod

type MemberSignInMethod struct {
	Kind string `json:"kind" enum:"password,passkey,sso,google,microsoft,github"`
	// Label is "Password", "passkey" or "Google Workspace SSO".
	Label string `json:"label"`
	// Preset of the SSO provider (google, entra, okta…) for the icon.
	Preset string `json:"preset,omitempty"`
}

MemberSignInMethod is one way a person signs in.

func PrimarySignIn

func PrimarySignIn(all []MemberSignInMethod) []MemberSignInMethod

PrimarySignIn is the sign-in shown in the team list: the member's own credentials (password, passkey) when they have any, otherwise their SSO or social sign-ins. Linked identities next to a password are listed on the member page only.

func SignInMethods

func SignInMethods(hasPassword bool, passkeys int64, ids []Identity) []MemberSignInMethod

SignInMethods lists how a person signs in, password first.

type MemberTwoFA

type MemberTwoFA struct {
	State string `json:"state" enum:"on,off,idp,required"`
	// Method is "TOTP" or "passkey" when on.
	Method     string     `json:"method,omitempty"`
	GraceUntil *time.Time `json:"graceUntil,omitempty"`
	// GraceDays is the whole days left in the grace period (0 = ends today).
	GraceDays *int `json:"graceDays,omitempty"`
}

MemberTwoFA is a member's two-factor status (A5 §5.8): On, Off, Via IdP or "Required, grace ends in N days".

func TwoFAStatus

func TwoFAStatus(in TwoFAInput) MemberTwoFA

TwoFAStatus computes the badge shown in the members list.

type PermissionInfo

type PermissionInfo struct {
	Key         string   `json:"key" example:"campaigns:send"`
	Group       string   `json:"group" example:"Campaigns"`
	Label       string   `json:"label" example:"Send or schedule campaigns"`
	Description string   `json:"description"`
	Sensitive   bool     `json:"sensitive"`
	Implies     []string `json:"implies"`
	OwnerOnly   bool     `json:"ownerOnly"`
	// PeopleOnly: API keys and MCP agents can't hold it.
	PeopleOnly bool `json:"peopleOnly"`
	// NoAgents: MCP agents can't hold it.
	NoAgents bool `json:"noAgents"`
}

PermissionInfo describes one permission key for the role editor, API key and agent pickers.

func Catalog

func Catalog(l i18n.Lang) []PermissionInfo

Catalog returns every permission in display order, its group, label and description in a language.

type ScopeError

type ScopeError struct {
	// Domain is true for a sender domain, false for a list.
	Domain bool
	Value  string
}

ScopeError is a requested list or sender domain the workspace doesn't have.

func (*ScopeError) Error

func (e *ScopeError) Error() string

type ScopeRequest

type ScopeRequest struct {
	Lists         []string `json:"lists,omitempty" maxItems:"100" doc:"List ids"`
	SenderDomains []string `json:"senderDomains,omitempty" maxItems:"20"`
}

ScopeRequest is the request shape of a scope.

func (*ScopeRequest) Resolve

func (in *ScopeRequest) Resolve(lists map[uuid.UUID]string, domains []string) (authz.Scope, error)

Resolve validates a requested scope against the workspace's lists and sender domains. A list or domain it doesn't know is a *ScopeError.

type ScopeSummary

type ScopeSummary struct {
	Lists         []ScopedList `json:"lists"`
	SenderDomains []string     `json:"senderDomains"`
	// Label is "" for no restriction, otherwise "Beta Program list only",
	// "Weekly Digest only" or "2 lists · news.acme.io".
	Label string `json:"label"`
	// All is true when the scope places no restriction ("All lists").
	All bool `json:"all"`
}

ScopeSummary is a scope as shown in the UI.

func View

func View(s authz.Scope, names map[uuid.UUID]string, listWord bool) ScopeSummary

View describes a scope with list names, its label in English (as audit entries keep it). listWord adds " list" after a single list name ("Beta Program list only", used for members) or not ("Weekly Digest only", used for keys).

func ViewIn

func ViewIn(l i18n.Lang, s authz.Scope, names map[uuid.UUID]string, listWord bool) ScopeSummary

ViewIn is View with the label in a language: "chỉ danh sách Beta Program".

type ScopedList

type ScopedList struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

ScopedList is one list in a scope.

type TwoFAInput

type TwoFAInput struct {
	TOTP       bool
	Passkeys   int64
	SSOOnly    bool // signs in only through an IdP that enforces its own second factor
	GraceUntil *time.Time
	Required   bool // the policy requires two-factor for this member
	Now        time.Time
}

TwoFAInput is what the two-factor status is computed from.

Jump to

Keyboard shortcuts

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