Documentation
¶
Overview ¶
Package settings manages site-wide configuration and storage limit overrides. It provides a key-value store for global settings (stored in site_settings), per-user upload/storage overrides, and per-campaign storage/file-count overrides. The resolution order for effective limits is: per-campaign > per-user > global, with 0 meaning unlimited at any tier.
Index ¶
- Constants
- Variables
- func IsValidClientIPHeader(m string) bool
- func IsValidLongTermTrash(months int) bool
- func IsValidRegistrationMode(m string) bool
- func IsValidSiteTrashRetention(days int) bool
- func IsValidTrashRetention(days int) bool
- func RegisterRoutes(adminGroup *echo.Group, h *Handler)
- type ActivityRecorder
- type CampaignStorageLimit
- type CampaignStorageLimitWithName
- type EffectiveLimits
- type GlobalStorageLimits
- type Handler
- func (h *Handler) ClearCampaignBypass(c *echo.Context) error
- func (h *Handler) ClearUserBypass(c *echo.Context) error
- func (h *Handler) DeleteCampaignStorageLimit(c *echo.Context) error
- func (h *Handler) DeleteUserStorageLimit(c *echo.Context) error
- func (h *Handler) GetCORSOrigins(c *echo.Context) error
- func (h *Handler) SetActivityRecorder(r ActivityRecorder)
- func (h *Handler) SetCampaignBypass(c *echo.Context) error
- func (h *Handler) SetCampaignStorageLimit(c *echo.Context) error
- func (h *Handler) SetUserBypass(c *echo.Context) error
- func (h *Handler) SetUserStorageLimit(c *echo.Context) error
- func (h *Handler) StorageSettings(c *echo.Context) error
- func (h *Handler) UpdateCORSOrigins(c *echo.Context) error
- func (h *Handler) UpdateStorageSettings(c *echo.Context) error
- func (h *Handler) UpdateTrashRetention(c *echo.Context) error
- type SettingsRepository
- type SettingsService
- type SiteSetting
- type UserStorageLimit
- type UserStorageLimitWithName
Constants ¶
const ( KeyMaxUploadSize = "storage.max_upload_size" KeyMaxStoragePerUser = "storage.max_storage_per_user" KeyMaxStoragePerCampaign = "storage.max_storage_per_campaign" KeyMaxFilesPerCampaign = "storage.max_files_per_campaign" KeyRateLimitUploadsPerMin = "storage.rate_limit_uploads_per_min" // KeyCORSAllowedOrigins stores a comma-separated list of additional origins // permitted to make cross-origin API requests (e.g., Foundry VTT servers). // BaseURL is always allowed implicitly. Managed from admin panel. KeyCORSAllowedOrigins = "cors.allowed_origins" // KeyPackageRepoPolicy controls which repository sources are allowed. // Values: "github_only" (default), "any_git", "allow_all". KeyPackageRepoPolicy = "packages.repo_policy" // KeyPackageRequireApproval controls whether owner-submitted packages // need admin sign-off before being fetched. Values: "true" (default), "false". KeyPackageRequireApproval = "packages.require_approval" // KeyPackageMaxFileSize is the maximum download size in bytes for package // ZIP assets. Default: 52428800 (50 MB). KeyPackageMaxFileSize = "packages.max_file_size" // KeyPackageValidateManifest controls whether downloaded packages must // contain a valid manifest.json. Values: "true" (default), "false". KeyPackageValidateManifest = "packages.validate_manifest" // KeyPackageScanContent controls whether downloaded packages are scanned // for suspicious files (executables, symlinks). Values: "true" (default), "false". KeyPackageScanContent = "packages.scan_content" // KeyRegistrationMode controls who may create an account via POST /register. // Values: "open" (default), "invite", "closed". Enforced in the auth service; // the first-user-admin bootstrap always works regardless of mode. KeyRegistrationMode = "auth.registration_mode" // KeyTrashRetentionDays is how many days a deleted world page waits in // its campaign's Trash before it is removed for good. One of // TrashRetentionChoices; anything else reads as the default. KeyTrashRetentionDays = "content.trash_retention_days" // KeySiteTrashRetentionDays is how many days a deleted campaign or a file // clean-up waits in the site Trash before it is removed for good. One of // SiteTrashRetentionChoices; anything else reads as the default. Separate // from KeyTrashRetentionDays, which is for pages inside a campaign. KeySiteTrashRetentionDays = "content.site_trash_retention_days" // KeyLongTermTrashMonths is how many months removed pages and players' // old values are kept packed after a campaign's Trash lets them go. One // of LongTermTrashChoices, 0 meaning off; anything else reads as the // default. KeyLongTermTrashMonths = "content.long_term_trash_months" // KeySiteName is the site name ("" is Chronicle). KeySiteName = "site.name" // KeySiteLogo is the stored media filename of the logo ("" is the letter mark). KeySiteLogo = "site.logo" // KeySiteLogoFavicon is "1" to use the logo as the browser tab icon. KeySiteLogoFavicon = "site.logo_as_favicon" // KeySiteLook is a campaign look id, or "" to leave pages as they are. KeySiteLook = "site.look" // KeySiteSigninBackground is "plain", "look" or "picture". KeySiteSigninBackground = "site.signin_background" // KeySiteSigninPicture is the stored media filename of the sign-in picture. KeySiteSigninPicture = "site.signin_picture" // KeySiteWelcome is the optional welcome line on the sign-in card. KeySiteWelcome = "site.welcome" // KeySiteMove is "1" to let the sign-in background and the top bar drift // slowly. Absent or anything else is off. KeySiteMove = "site.move" )
Setting keys used in the site_settings table.
const ( RegistrationOpen = "open" // Anyone may register (default — zero behavior change). RegistrationInvite = "invite" // Only holders of a valid campaign invite may register. RegistrationClosed = "closed" // No new registrations (except the first-user bootstrap). )
Registration mode values for KeyRegistrationMode. Defined here as the canonical source of truth for the site setting; the auth service compares against its own matching local constants (it must not import this plugin).
const ( ClientIPAuto = "auto" // X-Real-IP if sent, else X-Forwarded-For from the right. ClientIPRealIP = "x-real-ip" // X-Real-IP only. ClientIPForwardedFor = "x-forwarded-for" // X-Forwarded-For only, from the right. ClientIPDirect = "direct" // No proxy: the connection's own address. )
Values for KeyClientIPHeader. The middleware package holds the same strings because it cannot import this plugin; app passes the stored value across.
const DefaultLongTermTrashMonths = 6
DefaultLongTermTrashMonths applies while the setting is unset.
const DefaultSiteTrashRetentionDays = 30
DefaultSiteTrashRetentionDays applies while the setting is unset.
const DefaultTrashRetentionDays = 30
DefaultTrashRetentionDays applies while the setting is unset.
const KeyClientIPHeader = "network.client_ip_header"
KeyClientIPHeader chooses which request header Chronicle believes for the visitor's address (one of the ClientIP values). Absent reads as auto.
Variables ¶
var LongTermTrashChoices = []int{0, 3, 6, 12, 24}
LongTermTrashChoices are the Long-term trash lengths the admin can pick, in months; 0 turns it off. They match the player changes plugin's list.
var SiteTrashRetentionChoices = []int{7, 14, 30, 90}
SiteTrashRetentionChoices are the periods the admin can pick for the site Trash (campaigns and file clean-ups), in days.
var TrashRetentionChoices = []int{30, 60, 90, 180, 365}
TrashRetentionChoices are the retention periods the admin can pick, in days. They match the entities plugin's list, which reads this setting through an adapter (plugins don't import each other).
Functions ¶
func IsValidClientIPHeader ¶
IsValidClientIPHeader reports whether m is one of the four known values.
func IsValidLongTermTrash ¶
IsValidLongTermTrash reports whether months is one of the offered choices.
func IsValidRegistrationMode ¶
IsValidRegistrationMode reports whether m is one of the three known modes.
func IsValidSiteTrashRetention ¶
IsValidSiteTrashRetention reports whether days is one of the offered choices.
func IsValidTrashRetention ¶
IsValidTrashRetention reports whether days is one of the offered choices.
func RegisterRoutes ¶
RegisterRoutes sets up storage settings routes on the given admin group. All routes require site admin middleware (applied by the caller via the admin group's middleware stack).
Types ¶
type ActivityRecorder ¶
type ActivityRecorder interface {
RecordAdminChange(c *echo.Context, action, targetType, targetID, label string)
}
ActivityRecorder is the slice of the admin change log this plugin writes to. It is declared here, not imported from the admin plugin, so the plugins stay independent; app wiring supplies an adapter that stamps the signed-in admin. Recording is best-effort: implementations must not fail the request.
type CampaignStorageLimit ¶
type CampaignStorageLimit struct {
CampaignID string `json:"campaign_id"`
MaxTotalStorage *int64 `json:"max_total_storage"` // NULL = use global/user default.
MaxFiles *int `json:"max_files"` // NULL = use global default.
UpdatedAt time.Time `json:"updated_at"`
// Bypass fields: temporary time-limited overrides that take highest priority.
BypassMaxStorage *int64 `json:"bypass_max_storage,omitempty"`
BypassMaxFiles *int `json:"bypass_max_files,omitempty"`
BypassExpiresAt *time.Time `json:"bypass_expires_at,omitempty"`
BypassReason *string `json:"bypass_reason,omitempty"`
BypassGrantedBy *string `json:"bypass_granted_by,omitempty"`
}
CampaignStorageLimit represents a per-campaign storage override. NULL fields mean "fall back to user or global default". Stored in campaign_storage_limits.
func (*CampaignStorageLimit) HasActiveBypass ¶
func (cl *CampaignStorageLimit) HasActiveBypass() bool
HasActiveBypass returns true if the campaign has a non-expired bypass.
type CampaignStorageLimitWithName ¶
type CampaignStorageLimitWithName struct {
CampaignStorageLimit
CampaignName string `json:"campaign_name"`
}
CampaignStorageLimitWithName extends CampaignStorageLimit with the campaign name for rendering in admin tables.
type EffectiveLimits ¶
type EffectiveLimits struct {
MaxUploadSize int64 `json:"max_upload_size"` // Per-file upload cap in bytes.
MaxTotalStorage int64 `json:"max_total_storage"` // Total storage cap in bytes.
MaxFiles int `json:"max_files"` // Max file count.
}
EffectiveLimits represents the resolved storage limits for a specific user + campaign context. This is the final result after merging global, per-user, and per-campaign overrides. Values of 0 mean unlimited.
type GlobalStorageLimits ¶
type GlobalStorageLimits struct {
MaxUploadSize int64 `json:"max_upload_size"` // Bytes. Per-file upload cap.
MaxStoragePerUser int64 `json:"max_storage_per_user"` // Bytes. Total across all campaigns.
MaxStoragePerCampaign int64 `json:"max_storage_per_campaign"` // Bytes. Total per campaign.
MaxFilesPerCampaign int `json:"max_files_per_campaign"` // File count cap per campaign.
RateLimitUploadsPerMin int `json:"rate_limit_uploads_per_min"` // Uploads per minute per IP.
}
GlobalStorageLimits holds the parsed global storage settings from the site_settings table. Values of 0 mean "unlimited" (no cap enforced).
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for site storage settings management. All routes require site admin middleware.
func NewHandler ¶
func NewHandler(service SettingsService) *Handler
NewHandler creates a new settings handler.
func (*Handler) ClearCampaignBypass ¶
ClearCampaignBypass removes a temporary bypass from a campaign's storage limits (DELETE /admin/campaigns/:id/storage/bypass).
func (*Handler) ClearUserBypass ¶
ClearUserBypass removes a temporary bypass from a user's storage limits (DELETE /admin/users/:id/storage/bypass).
func (*Handler) DeleteCampaignStorageLimit ¶
DeleteCampaignStorageLimit removes a per-campaign storage override (DELETE /admin/campaigns/:id/storage).
func (*Handler) DeleteUserStorageLimit ¶
DeleteUserStorageLimit removes a per-user storage override (DELETE /admin/users/:id/storage).
func (*Handler) GetCORSOrigins ¶
GetCORSOrigins returns the current CORS origin whitelist as JSON (GET /admin/api/cors).
func (*Handler) SetActivityRecorder ¶
func (h *Handler) SetActivityRecorder(r ActivityRecorder)
SetActivityRecorder wires the admin change log. Optional: nil disables it.
func (*Handler) SetCampaignBypass ¶
SetCampaignBypass sets a temporary bypass on a campaign's storage limits (PUT /admin/campaigns/:id/storage/bypass).
func (*Handler) SetCampaignStorageLimit ¶
SetCampaignStorageLimit creates or updates a per-campaign storage override (PUT /admin/campaigns/:id/storage).
func (*Handler) SetUserBypass ¶
SetUserBypass sets a temporary bypass on a user's upload limit (PUT /admin/users/:id/storage/bypass).
func (*Handler) SetUserStorageLimit ¶
SetUserStorageLimit creates or updates a per-user storage override (PUT /admin/users/:id/storage).
func (*Handler) StorageSettings ¶
StorageSettings redirects to the combined storage page (GET /admin/storage/settings). Limits live on the unified /admin/storage page under the Limits tab.
func (*Handler) UpdateCORSOrigins ¶
UpdateCORSOrigins replaces the CORS origin whitelist (POST /admin/api/cors).
func (*Handler) UpdateStorageSettings ¶
UpdateStorageSettings saves global storage limits (POST /admin/storage/settings).
type SettingsRepository ¶
type SettingsRepository interface {
// Get retrieves a single setting value by key. Returns NotFound if the key does not exist.
Get(ctx context.Context, key string) (string, error)
// Set upserts a setting value. Creates the key if it does not exist.
Set(ctx context.Context, key, value string) error
// GetAll returns every setting as a key-value map.
GetAll(ctx context.Context) (map[string]string, error)
// GetUserLimit returns the per-user storage override, or nil if no override exists.
GetUserLimit(ctx context.Context, userID string) (*UserStorageLimit, error)
// SetUserLimit upserts a per-user storage limit override.
SetUserLimit(ctx context.Context, limit *UserStorageLimit) error
// DeleteUserLimit removes a per-user storage override, reverting to global defaults.
DeleteUserLimit(ctx context.Context, userID string) error
// GetCampaignLimit returns the per-campaign storage override, or nil if none exists.
GetCampaignLimit(ctx context.Context, campaignID string) (*CampaignStorageLimit, error)
// SetCampaignLimit upserts a per-campaign storage limit override.
SetCampaignLimit(ctx context.Context, limit *CampaignStorageLimit) error
// DeleteCampaignLimit removes a per-campaign storage override, reverting to defaults.
DeleteCampaignLimit(ctx context.Context, campaignID string) error
// ListUserLimits returns all per-user overrides with display names for the admin table.
ListUserLimits(ctx context.Context) ([]UserStorageLimitWithName, error)
// ListCampaignLimits returns all per-campaign overrides with campaign names for the admin table.
ListCampaignLimits(ctx context.Context) ([]CampaignStorageLimitWithName, error)
// SetUserBypass sets a temporary bypass on a user's storage limits.
SetUserBypass(ctx context.Context, userID string, maxUpload *int64, expiresAt time.Time, reason, grantedBy string) error
// ClearUserBypass removes the temporary bypass from a user's storage limits.
ClearUserBypass(ctx context.Context, userID string) error
// SetCampaignBypass sets a temporary bypass on a campaign's storage limits.
SetCampaignBypass(ctx context.Context, campaignID string, maxStorage *int64, maxFiles *int, expiresAt time.Time, reason, grantedBy string) error
// ClearCampaignBypass removes the temporary bypass from a campaign's storage limits.
ClearCampaignBypass(ctx context.Context, campaignID string) error
}
SettingsRepository defines the data access contract for site settings and per-entity storage limit overrides.
func NewSettingsRepository ¶
func NewSettingsRepository(db *sql.DB) SettingsRepository
NewSettingsRepository creates a new settings repository backed by MariaDB.
type SettingsService ¶
type SettingsService interface {
// TrashRetentionDays is how long deleted world pages wait in a Trash.
TrashRetentionDays(ctx context.Context) int
// UpdateTrashRetentionDays saves it; only TrashRetentionChoices pass.
UpdateTrashRetentionDays(ctx context.Context, days int) error
// SiteTrashRetentionDays is how long a deleted campaign or a file clean-up
// waits in the site Trash.
SiteTrashRetentionDays(ctx context.Context) (int, error)
// UpdateSiteTrashRetentionDays saves it; only SiteTrashRetentionChoices pass.
UpdateSiteTrashRetentionDays(ctx context.Context, days int) error
// LongTermTrashMonths is how long removed pages and players' old values
// stay packed after the Trash; 0 is off.
LongTermTrashMonths(ctx context.Context) int
// UpdateLongTermTrashMonths saves it; only LongTermTrashChoices pass.
UpdateLongTermTrashMonths(ctx context.Context, months int) error
// GetStorageLimits returns the parsed global storage limits.
GetStorageLimits(ctx context.Context) (*GlobalStorageLimits, error)
// UpdateStorageLimits validates and persists updated global storage limits.
UpdateStorageLimits(ctx context.Context, limits *GlobalStorageLimits) error
// GetEffectiveLimits resolves the final storage limits for a given user and
// campaign. Override priority: per-campaign > per-user > global. A value of
// 0 at any tier means unlimited (no cap enforced).
GetEffectiveLimits(ctx context.Context, userID, campaignID string) (*EffectiveLimits, error)
// GetUserLimit returns the per-user storage override, or nil if none exists.
GetUserLimit(ctx context.Context, userID string) (*UserStorageLimit, error)
// SetUserLimit validates and upserts a per-user storage override.
SetUserLimit(ctx context.Context, limit *UserStorageLimit) error
// DeleteUserLimit removes a per-user storage override.
DeleteUserLimit(ctx context.Context, userID string) error
// GetCampaignLimit returns the per-campaign storage override, or nil if none exists.
GetCampaignLimit(ctx context.Context, campaignID string) (*CampaignStorageLimit, error)
// SetCampaignLimit validates and upserts a per-campaign storage override.
SetCampaignLimit(ctx context.Context, limit *CampaignStorageLimit) error
// DeleteCampaignLimit removes a per-campaign storage override.
DeleteCampaignLimit(ctx context.Context, campaignID string) error
// ListUserLimits returns all per-user overrides with display names.
ListUserLimits(ctx context.Context) ([]UserStorageLimitWithName, error)
// ListCampaignLimits returns all per-campaign overrides with campaign names.
ListCampaignLimits(ctx context.Context) ([]CampaignStorageLimitWithName, error)
// SetUserBypass sets a temporary bypass on a user's storage limits.
SetUserBypass(ctx context.Context, userID string, maxUpload *int64, expiresAt time.Time, reason, grantedBy string) error
// ClearUserBypass removes the temporary bypass from a user's storage limits.
ClearUserBypass(ctx context.Context, userID string) error
// SetCampaignBypass sets a temporary bypass on a campaign's storage limits.
SetCampaignBypass(ctx context.Context, campaignID string, maxStorage *int64, maxFiles *int, expiresAt time.Time, reason, grantedBy string) error
// ClearCampaignBypass removes the temporary bypass from a campaign's storage limits.
ClearCampaignBypass(ctx context.Context, campaignID string) error
// GetCORSOrigins returns the list of additional CORS origins from the database.
// Returns an empty slice if no origins are configured.
GetCORSOrigins(ctx context.Context) ([]string, error)
// UpdateCORSOrigins replaces the CORS origin whitelist with the given origins.
// Each origin must be a valid URL scheme+host (e.g., "http://localhost:30000").
UpdateCORSOrigins(ctx context.Context, origins []string) error
// GetRegistrationMode returns the site registration mode ("open", "invite",
// "closed"), defaulting to "open" when unset or invalid.
GetRegistrationMode(ctx context.Context) (string, error)
// UpdateRegistrationMode validates and persists the site registration mode.
UpdateRegistrationMode(ctx context.Context, mode string) error
// GetClientIPHeader returns which header is believed for the visitor's
// address, defaulting to "auto" when unset or invalid.
GetClientIPHeader(ctx context.Context) (string, error)
// UpdateClientIPHeader validates and persists that choice.
UpdateClientIPHeader(ctx context.Context, mode string) error
// MaxUploadCeiling is the largest per-file upload size any request could
// be allowed: the site limit and every per-person override or active
// bypass. A limit of 0 at a tier means "use fallback", as the upload
// route resolves it. It lets a size cap run before anyone is signed in.
MaxUploadCeiling(ctx context.Context, fallback int64) (int64, error)
// GetSiteLook returns the saved site look. A site that never saved one
// gets the zero value (Configured false), which renders as before. Reads
// are cached briefly because every page render asks for it.
GetSiteLook(ctx context.Context) (sitelook.Settings, error)
// UpdateSiteLook validates and persists the site look and returns the
// normalised values that were stored.
UpdateSiteLook(ctx context.Context, in sitelook.Settings) (sitelook.Settings, error)
}
SettingsService handles business logic for site settings and storage limits. It parses string values from the database into typed structs and resolves the override chain (per-campaign > per-user > global) for effective limits.
func NewSettingsService ¶
func NewSettingsService(repo SettingsRepository) SettingsService
NewSettingsService creates a new settings service.
type SiteSetting ¶
type SiteSetting struct {
Key string `json:"key"`
Value string `json:"value"`
UpdatedAt time.Time `json:"updated_at"`
}
SiteSetting represents a single row in the site_settings key-value table. Settings are stored as string values and parsed into typed structs by the service layer.
type UserStorageLimit ¶
type UserStorageLimit struct {
UserID string `json:"user_id"`
MaxUploadSize *int64 `json:"max_upload_size"` // NULL = use global default.
MaxTotalStorage *int64 `json:"max_total_storage"` // NULL = use global default.
UpdatedAt time.Time `json:"updated_at"`
// Bypass fields: temporary time-limited overrides that take highest priority.
BypassMaxUpload *int64 `json:"bypass_max_upload,omitempty"`
BypassExpiresAt *time.Time `json:"bypass_expires_at,omitempty"`
BypassReason *string `json:"bypass_reason,omitempty"`
BypassGrantedBy *string `json:"bypass_granted_by,omitempty"`
}
UserStorageLimit represents a per-user storage override. NULL fields mean "fall back to global default". Stored in the user_storage_limits table.
func (*UserStorageLimit) HasActiveBypass ¶
func (ul *UserStorageLimit) HasActiveBypass() bool
HasActiveBypass returns true if the user has a non-expired bypass.
type UserStorageLimitWithName ¶
type UserStorageLimitWithName struct {
UserStorageLimit
DisplayName string `json:"display_name"`
}
UserStorageLimitWithName extends UserStorageLimit with the user's display name for rendering in admin tables.