user

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthSubject

type AuthSubject struct {
	// ProviderID is the ID for the provider of the user.
	ProviderID string

	// SubjectID is the ID for the subject of the user.
	SubjectID string

	// UserID is the ID of the user.
	UserID string
}

An AuthSubject contains information about the auth provider and subject ID for a particular user.

func (AuthSubject) Normalize

func (a AuthSubject) Normalize() (*AuthSubject, error)

Normalize will validate and produce a normalized AuthSubject struct.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB implements the Store against a *sql.DB backend.

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

NewDB will create a DB backend from a sql.DB. An error will be returned if statements fail to prepare.

func (*DB) AddAuthSubjectTx

func (db *DB) AddAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error

AddAuthSubjectTx implements the Store interface. It is used to add an auth subject to a given user.

func (*DB) Delete

func (db *DB) Delete(ctx context.Context, id string) error

Delete implements the UserStore interface.

func (*DB) DeleteAuthSubjectTx

func (db *DB) DeleteAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error

DeleteAuthSubjectTx implements the Store interface. It is used to remove an auth subject for a given user.

func (*DB) DeleteManyTx

func (db *DB) DeleteManyTx(ctx context.Context, tx *sql.Tx, ids []string) error

func (*DB) FindAll

func (db *DB) FindAll(ctx context.Context) ([]User, error)

FindAll implements the Store interface.

func (*DB) FindAllAuthSubjectsForUser

func (db *DB) FindAllAuthSubjectsForUser(ctx context.Context, userID string) ([]AuthSubject, error)

FindAllAuthSubjectsForUser implements the Store interface. It finds all auth subjects associated with a given userID.

func (*DB) FindMany

func (db *DB) FindMany(ctx context.Context, ids []string) ([]User, error)

func (*DB) FindOne

func (db *DB) FindOne(ctx context.Context, id string) (*User, error)

FindOne implements the Store interface.

func (*DB) FindOneTx

func (db *DB) FindOneTx(ctx context.Context, tx *sql.Tx, id string, forUpdate bool) (*User, error)

func (*DB) FindSomeAuthSubjectsForProvider

func (db *DB) FindSomeAuthSubjectsForProvider(ctx context.Context, limit int, afterSubjectID, providerID string) ([]AuthSubject, error)

FindSomeAuthSubjectsForProvider implements the Store interface. It finds all auth subjects associated with a given userID.

func (*DB) Insert

func (db *DB) Insert(ctx context.Context, u *User) (*User, error)

Insert implements the Store interface by inserting the new User into the database.

func (*DB) InsertTx

func (db *DB) InsertTx(ctx context.Context, tx *sql.Tx, u *User) (*User, error)

InsertTx implements the Store interface by inserting the new User into the database. The insert statement is first wrapped in tx.

func (*DB) Search

func (db *DB) Search(ctx context.Context, opts *SearchOptions) ([]User, error)

func (*DB) Update

func (db *DB) Update(ctx context.Context, u *User) error

Update implements the Store interface. Only admins can update user roles.

func (*DB) UpdateTx

func (db *DB) UpdateTx(ctx context.Context, tx *sql.Tx, u *User) error

func (*DB) UserExists added in v0.27.0

func (db *DB) UserExists(ctx context.Context) (ExistanceChecker, error)

UserExists returns an ExistanceChecker.

type ExistanceChecker added in v0.27.0

type ExistanceChecker interface {
	UserExistsString(id string) bool
	UserExistsUUID(id uuid.UUID) bool
}

ExistanceChecker allows checking if various users exist.

type SearchCursor

type SearchCursor struct {
	Name string `json:"n,omitempty"`
}

SearchCursor is used to indicate a position in a paginated list.

type SearchOptions

type SearchOptions struct {
	Search string       `json:"s,omitempty"`
	After  SearchCursor `json:"a,omitempty"`

	// Omit specifies a list of user IDs to exclude from the results.
	Omit []string `json:"o,omitempty"`

	Limit int `json:"-"`

	// CMValue is matched against the user's contact method phone number.
	CMValue string `json:"v,omitempty"`

	// CMType is matched against the user's contact method type.
	CMType contactmethod.Type `json:"t,omitempty"`
}

SearchOptions allow filtering and paginating the list of users.

type Store

type Store interface {
	Insert(context.Context, *User) (*User, error)
	InsertTx(context.Context, *sql.Tx, *User) (*User, error)
	Update(context.Context, *User) error
	UpdateTx(context.Context, *sql.Tx, *User) error
	Delete(context.Context, string) error
	DeleteManyTx(context.Context, *sql.Tx, []string) error
	FindOne(context.Context, string) (*User, error)
	FindOneTx(ctx context.Context, tx *sql.Tx, id string, forUpdate bool) (*User, error)
	FindAll(context.Context) ([]User, error)
	FindMany(context.Context, []string) ([]User, error)
	Search(context.Context, *SearchOptions) ([]User, error)

	UserExists(context.Context) (ExistanceChecker, error)

	AddAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error
	DeleteAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error
	FindAllAuthSubjectsForUser(ctx context.Context, userID string) ([]AuthSubject, error)
	FindSomeAuthSubjectsForProvider(ctx context.Context, limit int, afterSubjectID, providerID string) ([]AuthSubject, error)
}

Store allows the lookup and management of Users.

type User

type User struct {
	// ID is the unique identifier for the user
	ID string `json:"id"`

	// Name is the full name of the user
	Name string `json:"name"`

	// Email is the primary contact email for the user. It is used for account-related communications
	Email string `json:"email"`

	// AvatarURL is an absolute address for an image to be used as the avatar.
	AvatarURL string `json:"avatar_url"`

	// AlertStatusCMID defines a contact method ID for alert status updates.
	AlertStatusCMID string `json:"alert_status_log_contact_method_id"`

	// The Role of the user
	Role permission.Role `json:"role" store:"readonly"`
}

A User is the base information of a user of the system. Authentication details are stored separately based on the auth provider.

func (User) Normalize

func (u User) Normalize() (*User, error)

Normalize will produce a normalized/validated User struct. Will only do the validate if email is not empty

func (User) ResolveAvatarURL

func (u User) ResolveAvatarURL(fullSize bool) string

ResolveAvatarURL will resolve the user avatar URL, using the email if none is set.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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