Documentation
¶
Index ¶
- Constants
- Variables
- type BooleanValidator
- type Filter
- type Preference
- type PreferenceValidator
- type Repository
- type SelectValidator
- type Service
- func (s *Service) Create(ctx context.Context, preference Preference) (Preference, error)
- func (s *Service) Describe(ctx context.Context) []Trait
- func (s *Service) Get(ctx context.Context, id string) (Preference, error)
- func (s *Service) List(ctx context.Context, filter Filter) ([]Preference, error)
- func (s *Service) LoadPlatformPreferences(ctx context.Context) (map[string]string, error)
- type TextValidator
- type Trait
- type TraitInput
- type TraitsConfig
Constants ¶
View Source
const ( // platform default traits PlatformDisableOrgsOnCreate = "disable_orgs_on_create" PlatformDisableOrgsListing = "disable_orgs_listing" PlatformDisableUsersListing = "disable_users_listing" PlatformInviteWithRoles = "invite_with_roles" PlatformInviteMailSubject = "invite_mail_template_subject" PlatformInviteMailBody = "invite_mail_template_body" // organization default traits OrganizationMailLink = "mail_link" OrganizationMailOTP = "mail_otp" OrganizationSocialLogin = "social_login" // user default traits UserFirstName = "first_name" UserNewsletter = "newsletter" // Zero values for global/unscoped preferences // Used instead of NULL for PostgreSQL 14 compatibility ScopeTypeGlobal = "app/platform" ScopeIDGlobal = "00000000-0000-0000-0000-000000000000" )
Variables ¶
View Source
var ( ErrInvalidID = fmt.Errorf("invalid preference id") ErrNotFound = fmt.Errorf("preference not found") ErrInvalidFilter = fmt.Errorf("invalid preference filter set") ErrTraitNotFound = fmt.Errorf("preference trait not found, preferences can only be created with valid trait") ErrInvalidValue = fmt.Errorf("invalid value for preference") )
View Source
var DefaultTraits = []Trait{ { ResourceType: schema.PlatformNamespace, Name: PlatformDisableOrgsOnCreate, Title: "Disable Orgs On Create", Description: "If selected the new orgs created by members will be disabled by default.This can be used to prevent users from accessing the org until they contact the admin and get it enabled. Default is false.", Heading: "Platform Settings", SubHeading: "Manage platform settings and how it's members interact with the platform.", Input: TraitInputCheckbox, InputHints: "true,false", Default: "false", }, { ResourceType: schema.PlatformNamespace, Name: PlatformDisableOrgsListing, Title: "Disable Orgs Listing", Description: "If selected will disallow non-admin APIs to list all organizations on the platform. Default is false.", Heading: "Platform Settings", SubHeading: "Manage platform settings and how it's members interact with the platform.", Input: TraitInputCheckbox, InputHints: "true,false", Default: "false", }, { ResourceType: schema.PlatformNamespace, Name: PlatformDisableUsersListing, Title: "Disable Users Listing", Description: "If selected will will disallow non-admin APIs to list all users on the platform. Default is false.", Heading: "Platform Settings", SubHeading: "Manage platform settings and how it's members interact with the platform.", Input: TraitInputCheckbox, InputHints: "true,false", Default: "false", }, { ResourceType: schema.PlatformNamespace, Name: PlatformInviteWithRoles, Title: "Invite With Roles", Description: "Allow inviting new members with set of role ids. When the invitation is accepted, the user will be added to the org with the roles specified. Default is false.", Heading: "Platform Settings", SubHeading: "Manage platform settings and how it's members interact with the platform.", Input: TraitInputCheckbox, InputHints: "true,false", Default: "false", }, { ResourceType: schema.PlatformNamespace, Name: PlatformInviteMailSubject, Title: "Invite Mail Subject", Description: "The subject of the invite mail sent to new members.", Heading: "Platform Settings", SubHeading: "Manage platform settings and how it's members interact with the platform.", Input: TraitInputText, Default: "You have been invited to join an organization", }, { ResourceType: schema.PlatformNamespace, Name: PlatformInviteMailBody, Title: "Invite Mail Body", Description: "The body of the invite mail sent to new members. The following variables can be used in the template: {{.UserID}}, {{.Organization}} to personalize the mail for the user.", Default: "<div>Hi {{.UserID}},</div><br><p>You have been invited to join an organization: {{.Organization}}. Login to your account to accept the invitation.</p><br><div>Thanks,<br>Team Frontier</div>", Input: TraitInputTextarea, }, { ResourceType: schema.UserPrincipal, Name: UserFirstName, Title: "Full name", Description: "Full name of the user", Heading: "Profile", Input: TraitInputText, }, { ResourceType: schema.UserPrincipal, Name: UserNewsletter, Title: "Newsletter Subscription", Description: "Subscribe to newsletter to get updates.", Heading: "Profile", Input: TraitInputCheckbox, InputHints: "true,false", Default: "false", }, { ResourceType: schema.OrganizationNamespace, Name: OrganizationSocialLogin, Title: "Social Login", Description: "Allow login through Google/Github/Facebook/etc single sign-on functionality.", Heading: "Security", SubHeading: "Manage organization security and how it's members authenticate.", Input: TraitInputCheckbox, }, { ResourceType: schema.OrganizationNamespace, Name: OrganizationMailOTP, Title: "Email code", Description: "Allow password less login via code delivered over email.", Heading: "Security", SubHeading: "Manage organization security and how it's members authenticate.", Input: TraitInputCheckbox, }, { ResourceType: schema.OrganizationNamespace, Name: OrganizationMailLink, Title: "Email magic link", Description: "Allow password less login via a link delivered over email.", Heading: "Security", SubHeading: "Manage organization security and how it's members authenticate.", Input: TraitInputCheckbox, }, }
View Source
var ( // nil UUID for a platform-wide preference PlatformID = uuid.Nil.String() )
Functions ¶
This section is empty.
Types ¶
type BooleanValidator ¶ added in v0.55.0
type BooleanValidator struct {
// contains filtered or unexported fields
}
func NewBooleanValidator ¶ added in v0.55.0
func NewBooleanValidator() *BooleanValidator
func (*BooleanValidator) Validate ¶ added in v0.55.0
func (v *BooleanValidator) Validate(value string) bool
type Preference ¶
type Preference struct {
ID string `json:"id"`
Name string `json:"name"`
Value string `json:"value"`
ResourceID string `json:"resource_id"`
ResourceType string `json:"resource_type"`
ScopeType string `json:"scope_type"`
ScopeID string `json:"scope_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type PreferenceValidator ¶ added in v0.55.0
type Repository ¶
type Repository interface {
Set(ctx context.Context, preference Preference) (Preference, error)
Get(ctx context.Context, id uuid.UUID) (Preference, error)
List(ctx context.Context, filter Filter) ([]Preference, error)
}
type SelectValidator ¶ added in v0.89.2
type SelectValidator struct {
// contains filtered or unexported fields
}
SelectValidator validates that a value is one of the allowed options specified in the InputHints field (comma-separated values)
func NewSelectValidator ¶ added in v0.89.2
func NewSelectValidator(inputHints string) *SelectValidator
func (*SelectValidator) Validate ¶ added in v0.89.2
func (v *SelectValidator) Validate(value string) bool
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo Repository, traits []Trait) *Service
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, preference Preference) (Preference, error)
func (*Service) LoadPlatformPreferences ¶ added in v0.7.12
LoadPlatformPreferences loads platform preferences from the database and returns a map of preference name to value if a preference is not set in the database, the default value is used from DefaultTraits
type TextValidator ¶ added in v0.55.0
type TextValidator struct{}
func NewTextValidator ¶ added in v0.55.0
func NewTextValidator() *TextValidator
func (*TextValidator) Validate ¶ added in v0.55.0
func (v *TextValidator) Validate(value string) bool
type Trait ¶
type Trait struct {
// Level at which the trait is applicable (say "platform", "organization", "user")
ResourceType string `json:"resource_type" yaml:"resource_type"`
// Name of the trait (say "disable_orgs_on_create", "disable_orgs_listing", "disable_users_listing", "invite_with_roles", "invite_mail_template_subject", "invite_mail_template_body")
Name string `json:"name" yaml:"name"`
// Readable name of the trait (say "Disable Orgs On Create", "Disable Orgs Listing")
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
LongDescription string `json:"long_description" yaml:"long_description"`
Heading string `json:"heading" yaml:"heading"`
SubHeading string `json:"sub_heading" yaml:"sub_heading"`
// Breadcrumb to be used to group the trait with other traits (say "Platform.Settings.Authentication", "Platform.Settings.Invitation")
Breadcrumb string `json:"breadcrumb" yaml:"breadcrumb"`
// Type of input to be used to collect the value for the trait (say "text", "select", "checkbox", etc.)
Input TraitInput `json:"input" yaml:"input"`
// Acceptable values to be provided in the input (say "true,false") for a TraitInput of type Checkbox
InputHints string `json:"input_hints" yaml:"input_hints"`
// Default value to be used for the trait if the preference is not set (say "true" for a TraitInput of type Checkbox)
Default string `json:"default" yaml:"default"`
}
func LoadTraitsFromFile ¶ added in v0.89.2
LoadTraitsFromFile loads custom traits from a YAML configuration file and merges them with DefaultTraits
func (Trait) GetValidator ¶ added in v0.55.0
func (t Trait) GetValidator() PreferenceValidator
type TraitInput ¶
type TraitInput string
const ( TraitInputText TraitInput = "text" TraitInputTextarea TraitInput = "textarea" TraitInputSelect TraitInput = "select" TraitInputCombobox TraitInput = "combobox" TraitInputCheckbox TraitInput = "checkbox" TraitInputMultiselect TraitInput = "multiselect" TraitInputNumber TraitInput = "number" )
type TraitsConfig ¶ added in v0.89.2
type TraitsConfig struct {
Traits []Trait `yaml:"traits"`
}
TraitsConfig represents the YAML config file structure for custom traits
Click to show internal directories.
Click to hide internal directories.