Documentation
¶
Overview ¶
Package users manages accounts: creating, changing and deleting users, their grants, invites and the first-run setup that creates the admin.
Index ¶
- Constants
- Variables
- type Grants
- type GrantsPatch
- type NewInvite
- type NewUser
- type Patch
- type Service
- func (s *Service) AcceptInvite(ctx context.Context, token string, n NewUser, ci auth.ClientInfo) (db.User, auth.NewSession, error)
- func (s *Service) CheckInvite(ctx context.Context, token string) (db.Invite, error)
- func (s *Service) CompleteSetup(ctx context.Context, actor uuid.UUID) (SetupStatus, error)
- func (s *Service) CreateFirstAdmin(ctx context.Context, n NewUser, ci auth.ClientInfo) (db.User, auth.NewSession, error)
- func (s *Service) CreateInvite(ctx context.Context, actor uuid.UUID, n NewInvite) (db.Invite, string, error)
- func (s *Service) CreateUser(ctx context.Context, actor uuid.UUID, n NewUser) (db.User, error)
- func (s *Service) DeleteInvite(ctx context.Context, actor, id uuid.UUID) error
- func (s *Service) DeleteUser(ctx context.Context, actor, id uuid.UUID) error
- func (s *Service) GetUser(ctx context.Context, id uuid.UUID) (db.User, error)
- func (s *Service) HasUsers(ctx context.Context) (bool, error)
- func (s *Service) ListInvites(ctx context.Context) ([]db.Invite, error)
- func (s *Service) ListUsers(ctx context.Context, after string, limit int) ([]db.User, string, error)
- func (s *Service) SetupStatus(ctx context.Context) (SetupStatus, error)
- func (s *Service) UpdateUser(ctx context.Context, actor, id uuid.UUID, p Patch) (db.User, error)
- type SetupStatus
Constants ¶
const DefaultInviteTTL = 72 * time.Hour
DefaultInviteTTL is how long an invite stays valid unless set.
Variables ¶
var ( ErrNotFound = errors.New("users: not found") ErrUsernameTaken = errors.New("users: username taken") ErrLastAdmin = errors.New("users: the last enabled admin can't be disabled, demoted or deleted") ErrCannotChangeSelf = errors.New("users: admins can't disable, demote or delete themselves") ErrAlreadySetUp = errors.New("users: the first account already exists") ErrInviteInvalid = errors.New("users: invite unknown, used or expired") )
Errors callers map to responses.
var ContentRatings = []string{"safe", "suggestive", "erotic", "pornographic"}
Content ratings, mildest first.
Functions ¶
This section is empty.
Types ¶
type Grants ¶
type Grants struct {
MayAdd bool `json:"may_add"`
MayDownload bool `json:"may_download"`
MayManageMatches bool `json:"may_manage_matches"`
ContentRatingCeiling string `json:"content_rating_ceiling"`
AllSources bool `json:"all_sources"`
AllowedSources []string `json:"allowed_sources"`
}
Grants say what a user may do. Admins may do everything regardless.
func DefaultGrants ¶
func DefaultGrants() Grants
DefaultGrants are a new user's grants unless the admin sets others: browse every source, add to their own library and read, up to suggestive content; no downloads and no match fixing.
func InviteGrants ¶
InviteGrants decodes an invite's grants.
type GrantsPatch ¶
type GrantsPatch struct {
MayAdd *bool
MayDownload *bool
MayManageMatches *bool
ContentRatingCeiling *string
AllSources *bool
AllowedSources *[]string
}
GrantsPatch changes some grants; nil fields stay.
func (*GrantsPatch) Apply ¶
func (p *GrantsPatch) Apply(g Grants) Grants
Apply returns g with p applied.
type NewUser ¶
type NewUser struct {
Username string
Password string
DisplayName string
Role string
Grants Grants
}
NewUser is a user to create.
type Patch ¶
type Patch struct {
DisplayName *string
Role *string
Disabled *bool
Password *string
Grants *GrantsPatch
}
Patch changes some of a user's fields; nil fields stay.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages accounts.
func NewService ¶
NewService returns the users service.
func (*Service) AcceptInvite ¶
func (s *Service) AcceptInvite(ctx context.Context, token string, n NewUser, ci auth.ClientInfo) (db.User, auth.NewSession, error)
AcceptInvite creates the account an invite allows, uses the invite up and signs the new user in. n's role and grants are ignored: they come from the invite.
func (*Service) CheckInvite ¶
CheckInvite returns the open invite for token.
func (*Service) CompleteSetup ¶
CompleteSetup marks the wizard finished. Finishing it again keeps the first time.
func (*Service) CreateFirstAdmin ¶
func (s *Service) CreateFirstAdmin(ctx context.Context, n NewUser, ci auth.ClientInfo) (db.User, auth.NewSession, error)
CreateFirstAdmin creates the first account as an admin and signs it in. Once any account exists it fails with ErrAlreadySetUp, also when two requests race.
func (*Service) CreateInvite ¶
func (s *Service) CreateInvite(ctx context.Context, actor uuid.UUID, n NewInvite) (db.Invite, string, error)
CreateInvite creates an invite. Its token is returned only here.
func (*Service) CreateUser ¶
CreateUser creates a user (an admin's action).
func (*Service) DeleteInvite ¶
DeleteInvite revokes an invite.
func (*Service) DeleteUser ¶
DeleteUser deletes a user with their sessions and keys.
func (*Service) ListInvites ¶
ListInvites lists open invites.
func (*Service) ListUsers ¶
func (s *Service) ListUsers(ctx context.Context, after string, limit int) ([]db.User, string, error)
ListUsers returns up to limit users after the cursor (a lowercased username), and the cursor of the next page ("" on the last).
func (*Service) SetupStatus ¶
func (s *Service) SetupStatus(ctx context.Context) (SetupStatus, error)
SetupStatus reports the wizard's state.
type SetupStatus ¶
SetupStatus is where the first-run wizard stands.