access

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: AGPL-3.0 Imports: 9 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 CantGrant

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

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

func Groups

func Groups() []string

Groups returns the permission groups in display order.

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 OrList

func OrList(names []string) string

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

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 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"`
}

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

func Catalog

func Catalog() []PermissionInfo

Catalog returns every permission in display order.

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.

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. listWord adds " list" after a single list name ("Beta Program list only", used for members) or not ("Weekly Digest only", used for keys).

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