workspaces

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: 33 Imported by: 0

Documentation

Overview

Package workspaces creates and manages workspaces: built-in roles, the owner membership, settings, transfer of ownership and deletion.

Index

Constants

View Source
const RestoreDays = 7

RestoreDays is how long a deleted workspace can be restored by an instance admin before it is purged.

Variables

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

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

View Source
var DefaultSunsetPolicy = json.RawMessage(`{"enabled":true,"after_days":180,"reengage":true,"stop_after_days":30}`)

DefaultSunsetPolicy sends one re-engagement email, then stops broadcasts.

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

func Create(ctx context.Context, tx pgx.Tx, p CreateParams) (store.Workspace, error)

Create makes a workspace with the four built-in roles and the owner membership, inside the caller's transaction.

func EnsureTwoFAGrace

func EnsureTwoFAGrace(ctx context.Context, tx pgx.Tx, userID uuid.UUID) error

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

func HiddenSections(ws *store.Workspace) []string

HiddenSections returns the workspace's hidden sections in sidebar order, leaving out names this version doesn't know.

func Register

func Register(h huma.API, s *Service)

Register adds the workspace settings operations (Settings › General). Creating a workspace lives with the account endpoints (POST /workspaces).

func RegisterJobs

func RegisterJobs(reg *jobs.Registry, pool *pgxpool.Pool, log *slog.Logger)

RegisterJobs adds the purge of deleted workspaces (hourly).

func Slugify

func Slugify(name string) string

Slugify turns "Acme Newsletter" into "acme-newsletter".

func UniqueSlug

func UniqueSlug(ctx context.Context, q store.Querier, name string) (string, error)

UniqueSlug finds a free slug for name.

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.

func (PurgeArgs) Kind

func (PurgeArgs) Kind() string

Kind implements river.JobArgs.

type PurgeWorker

type PurgeWorker struct {
	river.WorkerDefaults[PurgeArgs]
	Pool *pgxpool.Pool
	Log  *slog.Logger
}

PurgeWorker removes soft-deleted workspaces for good.

func (*PurgeWorker) Work

func (w *PurgeWorker) Work(ctx context.Context, _ *river.Job[PurgeArgs]) error

Work implements river.Worker.

type Service

type Service struct {
	Pool  *pgxpool.Pool
	Q     *store.Queries
	Audit *audit.Logger
	Now   func() time.Time
}

func (*Service) Delete

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

Settings returns the general settings with the summaries of the page.

func (*Service) Transfer

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.

func (*Service) UpdateRetention

func (s *Service) UpdateRetention(ctx context.Context, ws *store.Workspace, in WorkspaceRetention) error

UpdateRetention saves the data retention settings, audited.

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 WorkspaceRetention

type WorkspaceRetention struct {
	// UnconfirmedEraseDays erases double opt-in signups never confirmed
	// after this many days; 0 never does.
	UnconfirmedEraseDays int32 `json:"unconfirmedEraseDays" enum:"0,14,30,60,90"`
	// EventDetailDays clears the IP address and user agent of opens and
	// clicks in campaigns and automations after this many days; 0 keeps
	// them. Counts, scores and reports stay.
	EventDetailDays int32 `json:"eventDetailDays" enum:"0,30,90,180,365,730"`
}

WorkspaceRetention is Settings › General › Data retention (review 2026-11 DP-4, DP-6, decision D3).

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"`
	// Retention is Data retention (review 2026-11 DP-4, DP-6).
	Retention WorkspaceRetention `json:"retention"`
}

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.

Jump to

Keyboard shortcuts

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