Documentation
¶
Overview ¶
Package workspaces creates and manages workspaces: built-in roles, the owner membership, settings, transfer of ownership and deletion.
Index ¶
- Constants
- Variables
- func Create(ctx context.Context, tx pgx.Tx, p CreateParams) (store.Workspace, error)
- func EnsureTwoFAGrace(ctx context.Context, tx pgx.Tx, userID uuid.UUID) error
- func HiddenSections(ws *store.Workspace) []string
- func Register(h huma.API, s *Service)
- func RegisterJobs(reg *jobs.Registry, pool *pgxpool.Pool, log *slog.Logger)
- func Slugify(name string) string
- func UniqueSlug(ctx context.Context, q store.Querier, name string) (string, error)
- type CreateParams
- type PurgeArgs
- type PurgeWorker
- type Service
- func (s *Service) Delete(ctx context.Context, ws *store.Workspace, in WorkspaceDeleteInput) (WorkspaceDeleteResult, error)
- func (s *Service) Export(ctx context.Context, ws *store.Workspace, p *authz.Principal, w io.Writer) error
- func (s *Service) SetSidebarSection(ctx context.Context, ws *store.Workspace, section string, shown bool) (WorkspaceSidebar, error)
- func (s *Service) Settings(ctx context.Context, ws *store.Workspace, p *authz.Principal) (WorkspaceSettings, error)
- func (s *Service) Transfer(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- func (s *Service) UpdateGeneral(ctx context.Context, ws *store.Workspace, in WorkspaceGeneralInput) error
- type WorkspaceApprovals
- type WorkspaceDanger
- type WorkspaceDeleteInput
- type WorkspaceDeleteResult
- type WorkspaceGeneralInput
- type WorkspaceMembersSummary
- type WorkspaceSender
- type WorkspaceSettings
- type WorkspaceSidebar
- type WorkspaceSidebarSectionInput
- type WorkspaceTransferCandidate
- type WorkspaceTransferInput
Constants ¶
const RestoreDays = 7
RestoreDays is how long a deleted workspace can be restored by an instance admin before it is purged.
Variables ¶
var DefaultApprovalPolicy = json.RawMessage(`{"rules":{"audience_min":{"enabled":true,"n":10000},"warming_provider":{"enabled":true},"new_provider":{"enabled":false,"days":14},"ready_with_warnings":{"enabled":false},"author_lacks_send":{"enabled":true},"approval_lists":{"enabled":false}},"approvals_required":1,"approver_roles":["owner","admin"],"automation_publish":false,"emergency_bypass":true}`)
DefaultApprovalPolicy is the policy of a new workspace (A5 §3.8): approval for big Broadcasts, warming or new providers and authors without send.
var DefaultSendThresholds = json.RawMessage(`{"hard_bounce":2.0,"complaint":0.10,"scope":"route","min_sample":500}`)
DefaultSendThresholds pause a send when bounces or complaints spike.
var DefaultSunsetPolicy = json.RawMessage(`{"enabled":true,"after_days":180,"reengage":true,"stop_after_days":30}`)
DefaultSunsetPolicy sends one re-engagement email, then stops broadcasts.
var SidebarSections = []struct{ Key, Name string }{
{"transactional", "Transactional"},
{"grow", "Grow"},
{"earn", "Earn"},
}
SidebarSections are the sections a workspace can hide, in sidebar order, with the names the audit log uses.
Functions ¶
func Create ¶
Create makes a workspace with the four built-in roles and the owner membership, inside the caller's transaction.
func EnsureTwoFAGrace ¶
EnsureTwoFAGrace starts the two-factor grace period for a user who just gained a sensitive permission and has no second factor yet (A5 §3.3).
func HiddenSections ¶
HiddenSections returns the workspace's hidden sections in sidebar order, leaving out names this version doesn't know.
func Register ¶
Register adds the workspace settings operations (Settings › General). Creating a workspace lives with the account endpoints (POST /workspaces).
func RegisterJobs ¶
RegisterJobs adds the purge of deleted workspaces (hourly).
Types ¶
type CreateParams ¶
type CreateParams struct {
Name string
Timezone string
Owner uuid.UUID
Source string // install, admin, self
}
CreateParams describes a new workspace.
type PurgeArgs ¶
type PurgeArgs struct{}
PurgeArgs deletes workspaces past their restore hold.
func (PurgeArgs) InsertOpts ¶
func (PurgeArgs) InsertOpts() river.InsertOpts
InsertOpts keeps one purge at a time.
type PurgeWorker ¶
PurgeWorker removes soft-deleted workspaces for good.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Now func() time.Time
}
func (*Service) Delete ¶
func (s *Service) Delete(ctx context.Context, ws *store.Workspace, in WorkspaceDeleteInput) (WorkspaceDeleteResult, error)
Delete soft-deletes the workspace: scheduled sends stop at once, keys and agents stop working, and the data is purged after the restore hold.
func (*Service) Export ¶
func (s *Service) Export(ctx context.Context, ws *store.Workspace, p *authz.Principal, w io.Writer) error
Export writes everything in the workspace as a ZIP archive. It streams table by table so large workspaces don't need memory.
func (*Service) SetSidebarSection ¶
func (s *Service) SetSidebarSection(ctx context.Context, ws *store.Workspace, section string, shown bool) (WorkspaceSidebar, error)
SetSidebarSection shows or hides one section. Setting the state it already has changes nothing and writes no audit entry.
func (*Service) Settings ¶
func (s *Service) Settings(ctx context.Context, ws *store.Workspace, p *authz.Principal) (WorkspaceSettings, error)
Settings returns the general settings with the summaries of the page.
func (*Service) Transfer ¶
func (s *Service) Transfer(ctx context.Context, ws *store.Workspace, p *authz.Principal, in WorkspaceTransferInput) error
Transfer makes another member the Owner; the caller becomes an Admin.
func (*Service) UpdateGeneral ¶
func (s *Service) UpdateGeneral(ctx context.Context, ws *store.Workspace, in WorkspaceGeneralInput) error
UpdateGeneral saves name, timezone and default sender.
type WorkspaceApprovals ¶
type WorkspaceApprovals struct {
// Rules are the enabled rules in words ("audience ≥ 10,000").
Rules []string `json:"rules"`
Approvers []string `json:"approvers"`
ApprovalsRequired int `json:"approvalsRequired"`
Automations bool `json:"automations" doc:"Publishing automations needs approval"`
Bypass bool `json:"bypass" doc:"Owners can bypass with a reason"`
Pending int64 `json:"pending"`
}
WorkspaceApprovals summarizes the send approval policy.
type WorkspaceDanger ¶
type WorkspaceDanger struct {
Contacts int64 `json:"contacts"`
Lists int64 `json:"lists"`
Segments int64 `json:"segments"`
Campaigns int64 `json:"campaigns"`
Automations int64 `json:"automations"`
Templates int64 `json:"templates"`
Providers int64 `json:"providers"`
Scheduled int64 `json:"scheduled"`
APIKeys int64 `json:"apiKeys"`
Agents int64 `json:"agents"`
RestoreDays int `json:"restoreDays"`
}
WorkspaceDanger lists what deleting the workspace removes.
type WorkspaceDeleteInput ¶
type WorkspaceDeleteInput struct {
Confirm string `json:"confirm" maxLength:"80" doc:"The workspace name, typed exactly"`
}
WorkspaceDeleteInput confirms deleting the workspace.
type WorkspaceDeleteResult ¶
type WorkspaceDeleteResult struct {
RestoreUntil time.Time `json:"restoreUntil"`
// Cancelled counts scheduled sends that stopped.
Cancelled int64 `json:"cancelled"`
}
WorkspaceDeleteResult says until when an instance admin can restore it.
type WorkspaceGeneralInput ¶
type WorkspaceGeneralInput struct {
Name string `json:"name" minLength:"1" maxLength:"80"`
Timezone string `json:"timezone" minLength:"1" maxLength:"64"`
DefaultSenderID string `json:"defaultSenderId,omitempty"`
}
WorkspaceGeneralInput changes the general settings.
type WorkspaceMembersSummary ¶
type WorkspaceMembersSummary struct {
Active int64 `json:"active"`
Invited int64 `json:"invited"`
Deactivated int64 `json:"deactivated"`
Builtin []string `json:"builtin"`
Custom []string `json:"custom"`
// SignIn is "Google Workspace SSO enforced for acme.io · password kept for the Owner".
SignIn string `json:"signIn"`
}
WorkspaceMembersSummary is the Members and access card.
type WorkspaceSender ¶
type WorkspaceSender struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
// VerifiedOn names the sending providers that verified it ("SES", "Postal").
VerifiedOn []string `json:"verifiedOn"`
}
WorkspaceSender is a sender offered as the default.
type WorkspaceSettings ¶
type WorkspaceSettings struct {
ID string `json:"id"`
Slug string `json:"slug"`
Name string `json:"name"`
Timezone string `json:"timezone"`
DefaultSenderID string `json:"defaultSenderId,omitempty"`
Senders []WorkspaceSender `json:"senders"`
Approvals WorkspaceApprovals `json:"approvals"`
Members WorkspaceMembersSummary `json:"members"`
Danger WorkspaceDanger `json:"danger"`
Candidates []WorkspaceTransferCandidate `json:"candidates"`
CanManage bool `json:"canManage"`
CanTransfer bool `json:"canTransfer"`
CanDelete bool `json:"canDelete"`
// HasPassword says whether transferring asks for the caller's password.
HasPassword bool `json:"hasPassword"`
// Reason explains read-only access.
Reason string `json:"reason,omitempty"`
Helpers []string `json:"helpers"`
// HiddenSections are the sections hidden from the sidebar (Sidebar sections).
HiddenSections []string `json:"hiddenSections" enum:"transactional,grow,earn"`
}
WorkspaceSettings is Settings › General.
type WorkspaceSidebar ¶
type WorkspaceSidebar struct {
HiddenSections []string `json:"hiddenSections" enum:"transactional,grow,earn" doc:"Sections hidden from the sidebar, in sidebar order"`
}
WorkspaceSidebar is what the sidebar hides.
type WorkspaceSidebarSectionInput ¶
type WorkspaceSidebarSectionInput struct {
Shown bool `json:"shown" doc:"Show the section in the sidebar; false hides it"`
}
WorkspaceSidebarSectionInput shows or hides one section.
type WorkspaceTransferCandidate ¶
type WorkspaceTransferCandidate struct {
MemberID string `json:"memberId"`
Name string `json:"name"`
Email string `json:"email"`
RoleName string `json:"roleName"`
TwoFA access.MemberTwoFA `json:"twoFA"`
// Eligible members are active and have two-factor (their own or the IdP's).
Eligible bool `json:"eligible"`
Reason string `json:"reason,omitempty"`
// Note explains how the two-factor requirement is met.
Note string `json:"note,omitempty"`
}
WorkspaceTransferCandidate is a member who could become the Owner.
type WorkspaceTransferInput ¶
type WorkspaceTransferInput struct {
MemberID string `json:"memberId" format:"uuid"`
Password string `json:"password,omitempty" maxLength:"1024" doc:"The caller's password (re-authentication)"`
}
WorkspaceTransferInput hands the workspace to another member.