user

package
v0.0.0-...-5f5e9cb Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 90

Documentation

Overview

Package user represents users of Evergreen.

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")
	LastScheduledTasksAtKey   = bsonutil.MustHaveTag(DBUser{}, "LastScheduledTasksAt")
	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")
	PubKeyNameKey             = bsonutil.MustHaveTag(PubKey{}, "Name")
	PubKeyKey                 = bsonutil.MustHaveTag(PubKey{}, "Key")
	PubKeyNCreatedAtKey       = bsonutil.MustHaveTag(PubKey{}, "CreatedAt")
	FavoriteProjectsKey       = bsonutil.MustHaveTag(DBUser{}, "FavoriteProjects")
	ParsleyFiltersKey         = bsonutil.MustHaveTag(DBUser{}, "ParsleyFilters")
	ParsleySettingsKey        = bsonutil.MustHaveTag(DBUser{}, "ParsleySettings")
	NumScheduledPatchTasksKey = bsonutil.MustHaveTag(DBUser{}, "NumScheduledPatchTasks")
	BetaFeaturesKey           = bsonutil.MustHaveTag(DBUser{}, "BetaFeatures")
)
View Source
var (
	SettingsTZKey             = bsonutil.MustHaveTag(UserSettings{}, "Timezone")
	UserSettingsGithubUserKey = bsonutil.MustHaveTag(UserSettings{}, "GithubUser")

	UseSpruceOptionsKey = bsonutil.MustHaveTag(UserSettings{}, "UseSpruceOptions")
	SpruceV1Key         = bsonutil.MustHaveTag(UseSpruceOptions{}, "SpruceV1")
)
View Source
var (
	GithubUserUIDKey = bsonutil.MustHaveTag(GithubUser{}, "UID")
)

Functions

func AddOrUpdateServiceUser

func AddOrUpdateServiceUser(ctx context.Context, u DBUser) error

AddOrUpdateServiceUser upserts a service user by ID. If it's a new user, it generates a new API key for the user.

func ById

func ById(userId string) db.Q

ById returns a query that matches a user by ID.

func ClearAllLoginCaches

func ClearAllLoginCaches(ctx context.Context) error

ClearAllLoginCaches clears all users' login caches, forcibly logging them out.

func ClearLoginCache

func ClearLoginCache(ctx context.Context, user gimlet.User) error

ClearLoginCache clears one user's login cache, forcibly logging them out.

func ClearUser

func ClearUser(ctx context.Context, userId string) error

ClearUser clears the users settings, roles and invalidates their login cache. It also sets their settings to use Spruce so rehires have Spruce enabled by default.

func DeleteServiceUser

func DeleteServiceUser(ctx context.Context, id string) error

DeleteServiceUser deletes a service user by ID.

func GetLoginCache

func GetLoginCache(ctx context.Context, 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(ctx context.Context, g gimlet.User) (string, error)

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

func UpdateAll

func UpdateAll(ctx context.Context, query any, update any) error

UpdateAll updates all users.

func UpdateOne

func UpdateOne(ctx context.Context, query any, update any) error

UpdateOne updates one user.

func UpsertOne

func UpsertOne(ctx context.Context, query any, update any) (*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"`
	ParsleyFilters         []parsley.Filter       `bson:"parsley_filters"`
	ParsleySettings        parsley.Settings       `bson:"parsley_settings"`
	NumScheduledPatchTasks int                    `bson:"num_scheduled_patch_tasks"`
	LastScheduledTasksAt   time.Time              `bson:"last_scheduled_tasks_at"`
	BetaFeatures           evergreen.BetaFeatures `bson:"beta_features"`
}

func Find

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

Find gets all DBUser for the given query.

func FindByGithubName

func FindByGithubName(ctx context.Context, name string) (*DBUser, error)

FindByGithubName finds a user with the given GitHub username.

func FindByGithubUID

func FindByGithubUID(ctx context.Context, uid int) (*DBUser, error)

FindByGithubUID finds a user with the given GitHub UID.

func FindByRole

func FindByRole(ctx context.Context, role string) ([]DBUser, error)

func FindBySlackUsername

func FindBySlackUsername(ctx context.Context, userName string) (*DBUser, error)

FindBySlackUsername finds a user with the given Slack Username.

func FindHumanUsersByRoles

func FindHumanUsersByRoles(ctx context.Context, roles []string) ([]DBUser, error)

FindHumanUsersByRoles returns human users that have any of the given roles.

func FindNeedsReauthorization

func FindNeedsReauthorization(ctx context.Context, reauthorizeAfter time.Duration) ([]DBUser, error)

FindNeedsReauthorization finds all users that need to be reauthorized after the given period has passed and who have not exceeded the max reauthorization attempts.

func FindOne

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

FindOne gets one DBUser for the given query.

func FindOneById

func FindOneById(ctx context.Context, id string) (*DBUser, error)

FindOneById gets a DBUser by ID.

func FindOneByToken

func FindOneByToken(ctx context.Context, token string) (*DBUser, error)

FindOneByToken gets a DBUser by cached login token.

func FindServiceUsers

func FindServiceUsers(ctx context.Context) ([]DBUser, error)

FindServiceUsers returns all API-only users.

func GetOrCreateUser

func GetOrCreateUser(ctx context.Context, userId, displayName, email, accessToken, refreshToken string, roles []string) (*DBUser, error)

GetOrCreateUser upserts a user with the given userId with the given display name, email, access token, and refresh token and returns the updated user. If no such user exists for that userId yet, it also sets the user's API key and roles.

func GetPeriodicBuildUser

func GetPeriodicBuildUser(ctx context.Context, user string) (*DBUser, error)

GetPeriodicBuild returns the matching user if applicable, and otherwise returns the default periodic build user.

func UpsertOneFromExisting

func UpsertOneFromExisting(ctx context.Context, oldUsr *DBUser, newEmail string) (*DBUser, error)

UpsertOneFromExisting creates a new user with the same necessary data as oldUsr.

func (*DBUser) AddFavoritedProject

func (u *DBUser) AddFavoritedProject(ctx context.Context, identifier string) error

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

func (*DBUser) AddPublicKey

func (u *DBUser) AddPublicKey(ctx context.Context, keyName, keyValue string) error

func (*DBUser) AddRole

func (u *DBUser) AddRole(ctx context.Context, role string) error

func (*DBUser) CheckAndUpdateSchedulingLimit

func (u *DBUser) CheckAndUpdateSchedulingLimit(ctx context.Context, maxScheduledTasks, numTasksModified int, activated bool) error

CheckAndUpdateSchedulingLimit checks if the number of tasks to be activated by the user is allowed given the global per-user hourly task scheduling limit, and updates relevant timestamp and counter info used to track the user's hourly scheduling usage. The activated parameter being false signifies the user is deactivating tasks, which frees up space in their scheduling limit.

func (*DBUser) DeleteAllRoles

func (u *DBUser) DeleteAllRoles(ctx context.Context) error

func (*DBUser) DeletePublicKey

func (u *DBUser) DeletePublicKey(ctx context.Context, keyName string) error

func (*DBUser) DeleteRoles

func (u *DBUser) DeleteRoles(ctx context.Context, roles []string) error

func (*DBUser) DisplayName

func (u *DBUser) DisplayName() string

func (*DBUser) Email

func (u *DBUser) Email() string

func (*DBUser) GeneralSubscriptionIDs

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

GeneralSubscriptionIDs returns a slice of the ids of the user's general subscriptions.

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) GetViewableProjectSettings

func (u *DBUser) GetViewableProjectSettings(ctx context.Context) ([]string, error)

GetViewableProjects returns the lists of projects/repos the user can view settings for.

func (*DBUser) GetViewableProjects

func (u *DBUser) GetViewableProjects(ctx context.Context) ([]string, error)

GetViewableProjects returns the lists of projects the user can view.

func (*DBUser) HasDistroCreatePermission

func (u *DBUser) HasDistroCreatePermission(ctx context.Context) bool

HasDistroCreatePermission returns true if the user has permission to create distros. This can also operate as a check for whether the user is a distro admin, since only distro admins can create new distros.

func (*DBUser) HasPermission

func (u *DBUser) HasPermission(ctx context.Context, opts gimlet.PermissionOpts) bool

func (*DBUser) HasProjectCreatePermission

func (u *DBUser) HasProjectCreatePermission(ctx context.Context) (bool, error)

HasProjectCreatePermission returns true if the user is an admin for any existing project.

func (*DBUser) IncPatchNumber

func (u *DBUser) IncPatchNumber(ctx context.Context) (int, error)

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

func (*DBUser) Insert

func (u *DBUser) Insert(ctx context.Context) error

func (*DBUser) IsAPIOnly

func (u *DBUser) IsAPIOnly() bool

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(ctx context.Context, identifier string) error

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

func (*DBUser) RemoveRole

func (u *DBUser) RemoveRole(ctx context.Context, role string) error

func (*DBUser) Roles

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

func (*DBUser) UnmarshalBSON

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

func (*DBUser) UpdateAPIKey

func (u *DBUser) UpdateAPIKey(ctx context.Context, newKey string) error

UpdateAPIKey updates the API key stored for the user.

func (*DBUser) UpdateBetaFeatures

func (u *DBUser) UpdateBetaFeatures(ctx context.Context, betaFeatures evergreen.BetaFeatures) error

UpdateBetaFeatures updates a user's beta feature settings.

func (*DBUser) UpdateParsleySettings

func (u *DBUser) UpdateParsleySettings(ctx context.Context, settings parsley.Settings) error

UpdateParsleySettings updates a user's settings for Parsley.

func (*DBUser) UpdatePublicKey

func (u *DBUser) UpdatePublicKey(ctx context.Context, targetKeyName, newKeyName, newKeyValue string) error

func (*DBUser) UpdateSettings

func (u *DBUser) UpdateSettings(ctx context.Context, settings UserSettings) error

UpdateSettings updates the user's settings.

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,omitempty"`
	TTL          time.Time `bson:"ttl,omitempty"`
	AccessToken  string    `bson:"access_token,omitempty"`
	RefreshToken string    `bson:"refresh_token,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:"-"`
}

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 {
	SpruceV1 bool `json:"spruce_v1" bson:"spruce_v1"` // represents users opted into the new Evergreen UI
}

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"`
	SlackMemberId    string                  `bson:"slack_member_id,omitempty" json:"slack_member_id,omitempty"`
	Notifications    NotificationPreferences `bson:"notifications,omitempty" json:"notifications"`
	UseSpruceOptions UseSpruceOptions        `json:"use_spruce_options" bson:"use_spruce_options"`
	DateFormat       string                  `json:"date_format" bson:"date_format"`
	TimeFormat       string                  `json:"time_format" bson:"time_format"`
}

Jump to

Keyboard shortcuts

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