user

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DestTypeUser = "builtin-user"
	FieldUserID  = "user_id"

	FallbackIconURL = "builtin://user"
)

Variables

This section is empty.

Functions

func DestFromID added in v0.33.0

func DestFromID(userID string) gadb.DestV1

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 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"`
	IsFavorite bool   `json:"f,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:"-"`

	DestArgs map[string]string `json:"da,omitempty"`
	DestType string            `json:"dt,omitempty"`

	// FavoritesUserID specifies the UserID whose favorite users want to be displayed.
	FavoritesUserID string `json:"u,omitempty"`

	// FavoritesOnly controls filtering the results to those marked as favorites by FavoritesUserID.
	FavoritesOnly bool `json:"g,omitempty"`

	// FavoritesFirst indicates the user marked as favorite (by FavoritesUserID) should be returned first (before any non-favorites).
	FavoritesFirst bool `json:"f,omitempty"`
}

SearchOptions allow filtering and paginating the list of users.

func (*SearchOptions) FromNotifyOptions added in v0.33.0

func (so *SearchOptions) FromNotifyOptions(ctx context.Context, opts nfydest.SearchOptions) error

type Store

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

Store allows managing users.

func NewStore added in v0.28.0

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

NewStore will create new Store for the sql.DB. An error will be returned if statements fail to prepare.

func (*Store) AddAuthSubjectTx

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

AddAuthSubjectTx adds an auth subject for a user.

func (*Store) AuthSubjectsFunc added in v0.28.0

func (s *Store) AuthSubjectsFunc(ctx context.Context, providerID string, userIDs []string, forEachFn func(AuthSubject) error) error

AuthSubjectsFunc will call the provided forEachFn for each AuthSubject. If an error is returned by forEachFn it will stop reading subjects and be returned.

providerID, if not empty, will limit AuthSubjects to those with the same providerID. userID, if not empty, will limit AuthSubjects to those assigned to the given userID(s).

func (*Store) DeleteAuthSubjectTx

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

DeleteAuthSubjectTx removes an auth subject for a user.

If the subject does not exist, nil is returned.

func (*Store) DeleteManyTx

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

DeleteManyTx will delete multiple users within the same transaction. If tx is nil, a transaction will be started and committed before returning.

func (*Store) DisplayInfo added in v0.33.0

func (s *Store) DisplayInfo(ctx context.Context, args map[string]string) (*nfydest.DisplayInfo, error)

func (*Store) FieldLabel added in v0.33.0

func (s *Store) FieldLabel(ctx context.Context, fieldID, value string) (string, error)

func (*Store) FindAllAuthSubjectsForUser

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

FindAllAuthSubjectsForUser returns all auth subjects associated with a given userID.

func (*Store) FindMany

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

FindMany will return all users matching the provided IDs.

There is no guarantee the returned users will be in the same order or that the number of returned users matches the number of provided IDs.

func (*Store) FindOne

func (s *Store) FindOne(ctx context.Context, id string) (*User, error)

FindOne is equivalent to calling FindOneTx(ctx, nil, id, false).

func (*Store) FindOneBySubject added in v0.29.0

func (s *Store) FindOneBySubject(ctx context.Context, providerID, subjectID string) (*User, error)

FindOneBySubject will find a user matching the subjectID for the given providerID.

func (*Store) FindOneTx

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

FindOneTx will return a single user, locking the row if forUpdate is set. When `forUpdate` is true, favorite information is omitted (always false).

func (*Store) FindSomeAuthSubjectsForProvider

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

FindSomeAuthSubjectsForProvider returns up to `limit` auth subjects associated with a given providerID.

afterSubjectID can be specified for paginating responses. Results are sorted by subject id.

func (*Store) ID added in v0.33.0

func (s *Store) ID() string

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, u *User) (*User, error)

Insert is equivalent to calling InsertTx(ctx, nil, u).

func (*Store) InsertTx

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

InsertTx creates a new User.

func (*Store) Search

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

Search performs a paginated search of users with the given options.

func (*Store) SearchField added in v0.33.0

func (s *Store) SearchField(ctx context.Context, fieldID string, options nfydest.SearchOptions) (*nfydest.SearchResult, error)

func (*Store) SetAuthSubject added in v0.29.0

func (s *Store) SetAuthSubject(ctx context.Context, providerID, subjectID, userID string) error

SetAuthSubject will add or update the auth subject for the provider/subject pair to point to the provided user ID.

func (*Store) SetUserRoleTx added in v0.28.0

func (s *Store) SetUserRoleTx(ctx context.Context, tx *sql.Tx, id string, role permission.Role) error

SetUserRoleTx allows updating the role of the given user ID.

func (*Store) TypeInfo added in v0.33.0

func (s *Store) TypeInfo(ctx context.Context) (*nfydest.TypeInfo, error)

func (*Store) UpdateTx

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

UpdateTx allows updating a user name and email.

func (*Store) UserExists added in v0.27.0

func (s *Store) UserExists(ctx context.Context) (ExistanceChecker, error)

UserExists returns an ExistanceChecker.

func (*Store) ValidateField added in v0.33.0

func (s *Store) ValidateField(ctx context.Context, fieldID, value string) error

func (*Store) WithoutAuthProviderFunc added in v0.29.0

func (s *Store) WithoutAuthProviderFunc(ctx context.Context, providerID string, forEachFn func(User) error) error

WithoutAuthProviderFunc will call forEachFn for each user that is missing an auth subject for the given provider ID. If an error is returned by forEachFn it will stop reading and be returned. Favorites information will not be included (always false).

type User

type User struct {
	// ID is the unique identifier for the user
	ID string

	// Name is the full name of the user
	Name string

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

	// AvatarURL is an absolute address for an image to be used as the avatar.
	AvatarURL string

	// AlertStatusCMID defines a contact method ID for alert status updates.
	//
	// Deprecated: No longer used.
	AlertStatusCMID string

	// The Role of the user
	Role permission.Role
	// contains filtered or unexported fields
}

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

func (User) AsField added in v0.33.0

func (u User) AsField() nfydest.FieldValue

func (User) Cursor added in v0.33.0

func (u User) Cursor() (string, error)

func (User) IsUserFavorite added in v0.29.0

func (u User) IsUserFavorite() bool

IsUserFavorite returns true if a user is a favorite of the current user.

func (User) Normalize

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

Normalize will produce a normalized/validated User struct.

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