Documentation ¶
Index ¶
- type AuthSubject
- type ExistanceChecker
- type SearchCursor
- type SearchOptions
- type Store
- func (s *Store) AddAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error
- func (s *Store) AuthSubjectsFunc(ctx context.Context, providerID string, userIDs []string, ...) error
- func (s *Store) DeleteAuthSubjectTx(ctx context.Context, tx *sql.Tx, a *AuthSubject) error
- func (s *Store) DeleteManyTx(ctx context.Context, tx *sql.Tx, ids []string) error
- func (s *Store) FindAllAuthSubjectsForUser(ctx context.Context, userID string) ([]AuthSubject, error)
- func (s *Store) FindMany(ctx context.Context, ids []string) ([]User, error)
- func (s *Store) FindOne(ctx context.Context, id string) (*User, error)
- func (s *Store) FindOneBySubject(ctx context.Context, providerID, subjectID string) (*User, error)
- func (s *Store) FindOneTx(ctx context.Context, tx *sql.Tx, id string, forUpdate bool) (*User, error)
- func (s *Store) FindSomeAuthSubjectsForProvider(ctx context.Context, limit int, afterSubjectID, providerID string) ([]AuthSubject, error)
- func (s *Store) Insert(ctx context.Context, u *User) (*User, error)
- func (s *Store) InsertTx(ctx context.Context, tx *sql.Tx, u *User) (*User, error)
- func (s *Store) Search(ctx context.Context, opts *SearchOptions) ([]User, error)
- func (s *Store) SetAuthSubject(ctx context.Context, providerID, subjectID, userID string) error
- func (s *Store) SetUserRoleTx(ctx context.Context, tx *sql.Tx, id string, role permission.Role) error
- func (s *Store) UpdateTx(ctx context.Context, tx *sql.Tx, u *User) error
- func (s *Store) UserExists(ctx context.Context) (ExistanceChecker, error)
- func (s *Store) WithoutAuthProviderFunc(ctx context.Context, providerID string, forEachFn func(User) error) error
- type User
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 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 ¶
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"` // 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.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store allows managing users.
func NewStore ¶ added in v0.28.0
NewStore will create new Store for the sql.DB. An error will be returned if statements fail to prepare.
func (*Store) AddAuthSubjectTx ¶
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 ¶
DeleteAuthSubjectTx removes an auth subject for a user.
If the subject does not exist, nil is returned.
func (*Store) DeleteManyTx ¶
DeleteManyTx will delete multiple users within the same transaction. If tx is nil, a transaction will be started and committed before returning.
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 ¶
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) FindOneBySubject ¶ added in v0.29.0
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) SetAuthSubject ¶ added in v0.29.0
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) UserExists ¶ added in v0.27.0
func (s *Store) UserExists(ctx context.Context) (ExistanceChecker, error)
UserExists returns an ExistanceChecker.
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) IsUserFavorite ¶ added in v0.29.0
IsUserFavorite returns true if a user is a favorite of the current user.
func (User) ResolveAvatarURL ¶
ResolveAvatarURL will resolve the user avatar URL, using the email if none is set.