Documentation ¶
Overview ¶
Package user represents users of Evergreen.
Index ¶
- Constants
- Variables
- func AddOrUpdateServiceUser(u DBUser) error
- func ById(userId string) db.Q
- func ClearAllLoginCaches() error
- func ClearLoginCache(user gimlet.User) error
- func ClearUser(userId string) error
- func DeleteServiceUser(ctx context.Context, id string) error
- func GetLoginCache(token string, expireAfter time.Duration) (gimlet.User, bool, error)
- func GetSlackMemberId(username string) (string, error)
- func IsValidSubscriptionPreference(in string) bool
- func PutLoginCache(g gimlet.User) (string, error)
- func UpdateAll(query interface{}, update interface{}) error
- func UpdateOne(query interface{}, update interface{}) error
- func UpsertOne(query interface{}, update interface{}) (*adb.ChangeInfo, error)
- type DBUser
- func Find(query db.Q) ([]DBUser, error)
- func FindByGithubName(name string) (*DBUser, error)
- func FindByGithubUID(uid int) (*DBUser, error)
- func FindByRole(role string) ([]DBUser, error)
- func FindBySlackUsername(userName string) (*DBUser, error)
- func FindHumanUsersByRoles(roles []string) ([]DBUser, error)
- func FindNeedsReauthorization(reauthorizeAfter time.Duration) ([]DBUser, error)
- func FindOne(query db.Q) (*DBUser, error)
- func FindOneById(id string) (*DBUser, error)
- func FindOneByToken(token string) (*DBUser, error)
- func FindServiceUsers() ([]DBUser, error)
- func GetOrCreateUser(userId, displayName, email, accessToken, refreshToken string, roles []string) (*DBUser, error)
- func GetPatchUser(gitHubUID int) (*DBUser, error)
- func GetPeriodicBuildUser(user string) (*DBUser, error)
- func UpsertOneFromExisting(oldUsr *DBUser, newEmail string) (*DBUser, error)
- func (u *DBUser) AddFavoritedProject(identifier string) error
- func (u *DBUser) AddPublicKey(keyName, keyValue string) error
- func (u *DBUser) AddRole(role string) error
- func (u *DBUser) CheckAndUpdateSchedulingLimit(maxScheduledTasks, numTasksModified int, activated bool) error
- func (u *DBUser) DeleteAllRoles() error
- func (u *DBUser) DeletePublicKey(keyName string) error
- func (u *DBUser) DeleteRoles(roles []string) error
- func (u *DBUser) DisplayName() string
- func (u *DBUser) Email() string
- func (u *DBUser) GeneralSubscriptionIDs() []string
- func (u *DBUser) GetAPIKey() string
- func (u *DBUser) GetAccessToken() string
- func (u *DBUser) GetPublicKey(keyname string) (string, error)
- func (u *DBUser) GetRefreshToken() string
- func (u *DBUser) GetRegion() string
- func (u *DBUser) GetViewableProjectSettings(ctx context.Context) ([]string, error)
- func (u *DBUser) GetViewableProjects(ctx context.Context) ([]string, error)
- func (u *DBUser) HasPermission(opts gimlet.PermissionOpts) bool
- func (u *DBUser) HasProjectCreatePermission() (bool, error)
- func (u *DBUser) IncPatchNumber() (int, error)
- func (u *DBUser) Insert() error
- func (u *DBUser) IsNil() bool
- func (u *DBUser) MarshalBSON() ([]byte, error)
- func (u *DBUser) PublicKeys() []PubKey
- func (u *DBUser) RemoveFavoriteProject(identifier string) error
- func (u *DBUser) RemoveRole(role string) error
- func (u *DBUser) Roles() []string
- func (u *DBUser) UnmarshalBSON(in []byte) error
- func (u *DBUser) UpdateAPIKey(newKey string) error
- func (u *DBUser) UpdateBetaFeatures(betaFeatures evergreen.BetaFeatures) error
- func (u *DBUser) UpdateParsleySettings(settings parsley.Settings) error
- func (u *DBUser) UpdatePublicKey(targetKeyName, newKeyName, newKeyValue string) error
- func (u *DBUser) UpdateSettings(settings UserSettings) error
- func (u *DBUser) Username() string
- type GithubUser
- type LoginCache
- type NotificationPreferences
- type PubKey
- type UseSpruceOptions
- type UserSettings
- type UserSubscriptionPreference
Constants ¶
const (
Collection = "users"
)
Variables ¶
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") )
var ( SettingsTZKey = bsonutil.MustHaveTag(UserSettings{}, "Timezone") UserSettingsGithubUserKey = bsonutil.MustHaveTag(UserSettings{}, "GithubUser") UseSpruceOptionsKey = bsonutil.MustHaveTag(UserSettings{}, "UseSpruceOptions") SpruceV1Key = bsonutil.MustHaveTag(UseSpruceOptions{}, "SpruceV1") )
var (
GithubUserUIDKey = bsonutil.MustHaveTag(GithubUser{}, "UID")
)
Functions ¶
func AddOrUpdateServiceUser ¶
AddOrUpdateServiceUser upserts a service user by ID. If it's a new user, it generates a new API key for the user.
func ClearAllLoginCaches ¶
func ClearAllLoginCaches() error
ClearAllLoginCaches clears all users' login caches, forcibly logging them out.
func ClearLoginCache ¶
ClearLoginCache clears one user's login cache, forcibly logging them out.
func ClearUser ¶
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 ¶
DeleteServiceUser deletes a service user by ID.
func GetLoginCache ¶
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 GetSlackMemberId ¶
func PutLoginCache ¶
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"` 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 FindByGithubName ¶
FindByGithubName finds a user with the given GitHub username.
func FindByGithubUID ¶
FindByGithubUID finds a user with the given GitHub UID.
func FindByRole ¶
func FindBySlackUsername ¶
FindBySlackUsername finds a user with the given Slack Username.
func FindHumanUsersByRoles ¶
FindHumanUsersByRoles returns human users that have any of the given roles.
func FindNeedsReauthorization ¶
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 FindOneByToken ¶
FindOneByToken gets a DBUser by cached login token.
func FindServiceUsers ¶
FindServiceUsers returns all API-only users.
func GetOrCreateUser ¶
func GetOrCreateUser(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 GetPatchUser ¶
GetPatchUser gets a user from their GitHub UID. If no such user is found, it defaults to the global GitHub pull request user.
func GetPeriodicBuildUser ¶
GetPeriodicBuild returns the matching user if applicable, and otherwise returns the default periodic build user.
func UpsertOneFromExisting ¶
UpsertOneFromExisting creates a new user with the same necessary data as oldUsr.
func (*DBUser) AddFavoritedProject ¶
AddFavoritedProject adds a project ID to the user favorites in user DB model
func (*DBUser) AddPublicKey ¶
func (*DBUser) CheckAndUpdateSchedulingLimit ¶
func (u *DBUser) CheckAndUpdateSchedulingLimit(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 (*DBUser) DeletePublicKey ¶
func (*DBUser) DeleteRoles ¶
func (*DBUser) DisplayName ¶
func (*DBUser) GeneralSubscriptionIDs ¶
GeneralSubscriptionIDs returns a slice of the ids of the user's general subscriptions.
func (*DBUser) GetAccessToken ¶
func (*DBUser) GetRefreshToken ¶
func (*DBUser) GetViewableProjectSettings ¶
GetViewableProjects returns the lists of projects/repos the user can view settings for.
func (*DBUser) GetViewableProjects ¶
GetViewableProjects returns the lists of projects the user can view.
func (*DBUser) HasPermission ¶
func (u *DBUser) HasPermission(opts gimlet.PermissionOpts) bool
func (*DBUser) HasProjectCreatePermission ¶
HasProjectCreatePermission returns true if the user is an admin for any existing project.
func (*DBUser) IncPatchNumber ¶
IncPatchNumber increases the count for the user's patch submissions by one, and then returns the new count.
func (*DBUser) MarshalBSON ¶
func (*DBUser) PublicKeys ¶
func (*DBUser) RemoveFavoriteProject ¶
RemoveFavoriteProject removes a project ID from the user favorites in user DB model
func (*DBUser) RemoveRole ¶
func (*DBUser) UnmarshalBSON ¶
func (*DBUser) UpdateAPIKey ¶
UpdateAPIKey updates the API key stored for the user.
func (*DBUser) UpdateBetaFeatures ¶
func (u *DBUser) UpdateBetaFeatures(betaFeatures evergreen.BetaFeatures) error
UpdateBetaFeatures updates a user's beta feature settings.
func (*DBUser) UpdateParsleySettings ¶
UpdateParsleySettings updates a user's settings for Parsley.
func (*DBUser) UpdatePublicKey ¶
func (*DBUser) UpdateSettings ¶
func (u *DBUser) UpdateSettings(settings UserSettings) error
UpdateSettings updates the user's settings.
type GithubUser ¶
type LoginCache ¶
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 UseSpruceOptions ¶
type UseSpruceOptions struct { 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 HasUsedMainlineCommitsBefore bool `json:"has_used_mainline_commits_before" bson:"has_used_mainline_commits_before"` // used to know whether or not to display spruce mainline commits 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"` SlackMemberId string `bson:"slack_member_id,omitempty" json:"slack_member_id,omitempty"` Notifications NotificationPreferences `bson:"notifications,omitempty" json:"notifications,omitempty"` 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"` }
type UserSubscriptionPreference ¶
type UserSubscriptionPreference string
const ( PreferenceEmail UserSubscriptionPreference = event.EmailSubscriberType PreferenceSlack UserSubscriptionPreference = event.SlackSubscriberType PreferenceNone UserSubscriptionPreference = event.SubscriberTypeNone )