user

package
v0.0.0-...-a9abf63 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Collection = "users"
)

Variables

View Source
var (
	IdKey                       = bsonutil.MustHaveTag(DBUser{}, "Id")
	FirstNameKey                = bsonutil.MustHaveTag(DBUser{}, "FirstName")
	LastNameKey                 = bsonutil.MustHaveTag(DBUser{}, "LastName")
	DispNameKey                 = bsonutil.MustHaveTag(DBUser{}, "DispName")
	EmailAddressKey             = bsonutil.MustHaveTag(DBUser{}, "EmailAddress")
	PatchNumberKey              = bsonutil.MustHaveTag(DBUser{}, "PatchNumber")
	CreatedAtKey                = bsonutil.MustHaveTag(DBUser{}, "CreatedAt")
	SettingsKey                 = bsonutil.MustHaveTag(DBUser{}, "Settings")
	APIKeyKey                   = bsonutil.MustHaveTag(DBUser{}, "APIKey")
	OnlyAPIKey                  = bsonutil.MustHaveTag(DBUser{}, "OnlyAPI")
	PubKeysKey                  = bsonutil.MustHaveTag(DBUser{}, "PubKeys")
	LoginCacheKey               = bsonutil.MustHaveTag(DBUser{}, "LoginCache")
	RolesKey                    = bsonutil.MustHaveTag(DBUser{}, "SystemRoles")
	LoginCacheTokenKey          = bsonutil.MustHaveTag(LoginCache{}, "Token")
	LoginCacheTTLKey            = bsonutil.MustHaveTag(LoginCache{}, "TTL")
	LoginCacheAccessTokenKey    = bsonutil.MustHaveTag(LoginCache{}, "AccessToken")
	LoginCacheRefreshTokenKey   = bsonutil.MustHaveTag(LoginCache{}, "RefreshToken")
	LoginCacheReauthAttemptsKey = bsonutil.MustHaveTag(LoginCache{}, "ReauthAttempts")
	PubKeyNameKey               = bsonutil.MustHaveTag(PubKey{}, "Name")
	PubKeyKey                   = bsonutil.MustHaveTag(PubKey{}, "Key")
	PubKeyNCreatedAtKey         = bsonutil.MustHaveTag(PubKey{}, "CreatedAt")
	FavoriteProjectsKey         = bsonutil.MustHaveTag(DBUser{}, "FavoriteProjects")
)
View Source
var (
	SettingsTZKey = bsonutil.MustHaveTag(UserSettings{}, "Timezone")

	UseSpruceOptionsKey = bsonutil.MustHaveTag(UserSettings{}, "UseSpruceOptions")
	SpruceV1Key         = bsonutil.MustHaveTag(UseSpruceOptions{}, "SpruceV1")
)

Functions

func ById

func ById(userId string) db.Q

func ByIds

func ByIds(userIds ...string) db.Q

func ClearLoginCache

func ClearLoginCache(user gimlet.User, all bool) error

ClearLoginCache clears a user or all users' tokens from the cache, forcibly logging them out

func Count

func Count(query db.Q) (int, error)

Count returns the number of user that satisfy the given query.

func FormatObjectID

func FormatObjectID(id string) (primitive.ObjectID, error)

func GetLoginCache

func GetLoginCache(token string, expireAfter time.Duration) (gimlet.User, bool, error)

GetLoginCache retrieve a cached user by token. It returns an error if and only if there was an error retrieving the user from the cache. It returns (<user>, true, nil) if the user is present in the cache and is valid. It returns (<user>, false, nil) if the user is present in the cache but has expired. It returns (nil, false, nil) if the user is not present in the cache.

func IsValidSubscriptionPreference

func IsValidSubscriptionPreference(in string) bool

func PutLoginCache

func PutLoginCache(g gimlet.User) (string, error)

PutLoginCache generates a token if one does not exist, and sets the TTL to now.

func UpdateAll

func UpdateAll(query interface{}, update interface{}) error

UpdateAll updates all users.

func UpdateOne

func UpdateOne(query interface{}, update interface{}) error

UpdateOne updates one user.

func UpsertOne

func UpsertOne(query interface{}, update interface{}) (*adb.ChangeInfo, error)

UpsertOne upserts a user.

Types

type DBUser

type DBUser struct {
	Id               string       `bson:"_id"`
	FirstName        string       `bson:"first_name"`
	LastName         string       `bson:"last_name"`
	DispName         string       `bson:"display_name"`
	EmailAddress     string       `bson:"email"`
	PatchNumber      int          `bson:"patch_number"`
	PubKeys          []PubKey     `bson:"public_keys" json:"public_keys"`
	CreatedAt        time.Time    `bson:"created_at"`
	Settings         UserSettings `bson:"settings"`
	APIKey           string       `bson:"apikey"`
	SystemRoles      []string     `bson:"roles"`
	LoginCache       LoginCache   `bson:"login_cache,omitempty"`
	FavoriteProjects []string     `bson:"favorite_projects"`
	OnlyAPI          bool         `bson:"only_api,omitempty"`
}

func Find

func Find(query db.Q) ([]DBUser, error)

Find gets all DBUser for the given query.

func FindByGithubName

func FindByGithubName(name string) (*DBUser, error)

func FindByGithubUID

func FindByGithubUID(uid int) (*DBUser, error)

func FindNeedsReauthorization

func FindNeedsReauthorization(reauthorizeAfter time.Duration, maxAttempts int) ([]DBUser, error)

FindNeedsReauthorization finds all users need to be reauthorized after the given period has passed.

func FindOne

func FindOne(query db.Q) (*DBUser, error)

FindOne gets one DBUser for the given query.

func FindOneById

func FindOneById(id string) (*DBUser, error)

FindOneById gets a DBUser by ID.

func FindOneByToken

func FindOneByToken(token string) (*DBUser, error)

FindOneByToken gets a DBUser by cached login token.

func GetPatchUser

func GetPatchUser(gitHubUID int) (*DBUser, error)

func (*DBUser) AddFavoritedProject

func (u *DBUser) AddFavoritedProject(identifier string) error

AddFavoritedProject adds a project ID to the user favorites in user DB model

func (*DBUser) AddPublicKey

func (u *DBUser) AddPublicKey(keyName, keyValue string) error

func (*DBUser) AddRole

func (u *DBUser) AddRole(role string) error

func (*DBUser) DeleteAllRoles

func (u *DBUser) DeleteAllRoles() error

func (*DBUser) DeletePublicKey

func (u *DBUser) DeletePublicKey(keyName string) error

func (*DBUser) DeleteRoles

func (u *DBUser) DeleteRoles(roles []string) error

func (*DBUser) DisplayName

func (u *DBUser) DisplayName() string

func (*DBUser) Email

func (u *DBUser) Email() string

func (*DBUser) GetAPIKey

func (u *DBUser) GetAPIKey() string

func (*DBUser) GetAccessToken

func (u *DBUser) GetAccessToken() string

func (*DBUser) GetPublicKey

func (u *DBUser) GetPublicKey(keyname string) (string, error)

func (*DBUser) GetRefreshToken

func (u *DBUser) GetRefreshToken() string

func (*DBUser) GetRegion

func (u *DBUser) GetRegion() string

func (*DBUser) HasPermission

func (u *DBUser) HasPermission(opts gimlet.PermissionOpts) bool

func (*DBUser) IncPatchNumber

func (u *DBUser) IncPatchNumber() (int, error)

IncPatchNumber increases the count for the user's patch submissions by one, and then returns the new count.

func (*DBUser) IncReauthAttempts

func (u *DBUser) IncReauthAttempts() error

IncReauthAttempts increases the number of attempted reauths for this user.

func (*DBUser) Insert

func (u *DBUser) Insert() error

func (*DBUser) IsNil

func (u *DBUser) IsNil() bool

func (*DBUser) MarshalBSON

func (u *DBUser) MarshalBSON() ([]byte, error)

func (*DBUser) PublicKeys

func (u *DBUser) PublicKeys() []PubKey

func (*DBUser) RemoveFavoriteProject

func (u *DBUser) RemoveFavoriteProject(identifier string) error

RemoveFavoriteProject removes a project ID from the user favorites in user DB model

func (*DBUser) RemoveRole

func (u *DBUser) RemoveRole(role string) error

func (*DBUser) Roles

func (u *DBUser) Roles() []string

func (*DBUser) UnmarshalBSON

func (u *DBUser) UnmarshalBSON(in []byte) error

func (*DBUser) Username

func (u *DBUser) Username() string

type GithubUser

type GithubUser struct {
	UID         int    `bson:"uid,omitempty" json:"uid,omitempty"`
	LastKnownAs string `bson:"last_known_as,omitempty" json:"last_known_as,omitempty"`
}

type LoginCache

type LoginCache struct {
	Token          string    `bson:"token"`
	TTL            time.Time `bson:"ttl"`
	AccessToken    string    `bson:"access_token,omitempty"`
	RefreshToken   string    `bson:"refresh_token,omitempty"`
	ReauthAttempts int       `bson:"reauth_attempts,omitempty"`
}

type NotificationPreferences

type NotificationPreferences struct {
	BuildBreak            UserSubscriptionPreference `bson:"build_break" json:"build_break"`
	BuildBreakID          string                     `bson:"build_break_id,omitempty" json:"-"`
	PatchFinish           UserSubscriptionPreference `bson:"patch_finish" json:"patch_finish"`
	PatchFinishID         string                     `bson:"patch_finish_id,omitempty" json:"-"`
	PatchFirstFailure     UserSubscriptionPreference `bson:"patch_first_failure,omitempty" json:"patch_first_failure"`
	PatchFirstFailureID   string                     `bson:"patch_first_failure_id,omitempty" json:"-"`
	SpawnHostExpiration   UserSubscriptionPreference `bson:"spawn_host_expiration" json:"spawn_host_expiration"`
	SpawnHostExpirationID string                     `bson:"spawn_host_expiration_id,omitempty" json:"-"`
	SpawnHostOutcome      UserSubscriptionPreference `bson:"spawn_host_outcome" json:"spawn_host_outcome"`
	SpawnHostOutcomeID    string                     `bson:"spawn_host_outcome_id,omitempty" json:"-"`
	CommitQueue           UserSubscriptionPreference `bson:"commit_queue" json:"commit_queue"`
	CommitQueueID         string                     `bson:"commit_queue_id,omitempty" json:"-"`
}

type PubKey

type PubKey struct {
	Name      string    `bson:"name" json:"name"`
	Key       string    `bson:"key" json:"key"`
	CreatedAt time.Time `bson:"created_at" json:"created_at"`
}

type UseSpruceOptions

type UseSpruceOptions struct {
	PatchPage           bool `json:"patch_page" bson:"patch_page"`                         // deprecated - do not use
	SpruceV1            bool `json:"spruce_v1" bson:"spruce_v1"`                           // represents users opted into the new Evergreen UI
	HasUsedSpruceBefore bool `json:"has_used_spruce_before" bson:"has_used_spruce_before"` // used to know whether or not to display spruce welcome modal
}

type UserSettings

type UserSettings struct {
	Timezone         string                  `json:"timezone" bson:"timezone"`
	Region           string                  `json:"region" bson:"region"`
	GithubUser       GithubUser              `json:"github_user" bson:"github_user,omitempty"`
	SlackUsername    string                  `bson:"slack_username,omitempty" json:"slack_username,omitempty"`
	Notifications    NotificationPreferences `bson:"notifications,omitempty" json:"notifications,omitempty"`
	UseSpruceOptions UseSpruceOptions        `json:"use_spruce_options" bson:"use_spruce_options"`
}

type UserSubscriptionPreference

type UserSubscriptionPreference string

Jump to

Keyboard shortcuts

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