Documentation ¶
Index ¶
- Constants
- Variables
- func ById(userId string) db.Q
- func ByIds(userIds ...string) db.Q
- func ClearLoginCache(user gimlet.User, all bool) error
- func Count(query db.Q) (int, error)
- func FormatObjectID(id string) (primitive.ObjectID, error)
- func GetLoginCache(token string, expireAfter time.Duration) (gimlet.User, bool, error)
- func GetRoleManager() gimlet.RoleManager
- 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 (u *DBUser) AddPublicKey(keyName, keyValue string) error
- func (u *DBUser) AddRole(role string) error
- func (u *DBUser) DeletePublicKey(keyName string) error
- func (u *DBUser) DisplayName() string
- func (u *DBUser) Email() string
- func (u *DBUser) GetAPIKey() string
- func (u *DBUser) GetPublicKey(keyname string) (string, error)
- func (u *DBUser) HasPermission(resource, permission string, requiredLevel int) (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) RemoveRole(role string) error
- func (u *DBUser) Roles() []string
- func (u *DBUser) UnmarshalBSON(in []byte) error
- func (u *DBUser) Username() string
- type GithubUser
- type LoginCache
- type NotificationPreferences
- type PubKey
- type UseSpruceOptions
- type UserSettings
- type UserSubscriptionPreference
Constants ¶
const ( RoleCollection = "roles" ScopeCollection = "scopes" )
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") SettingsKey = bsonutil.MustHaveTag(DBUser{}, "Settings") APIKeyKey = bsonutil.MustHaveTag(DBUser{}, "APIKey") 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") PubKeyNameKey = bsonutil.MustHaveTag(PubKey{}, "Name") PubKeyKey = bsonutil.MustHaveTag(PubKey{}, "Key") PubKeyNCreatedAtKey = bsonutil.MustHaveTag(PubKey{}, "CreatedAt") )
var (
SettingsTZKey = bsonutil.MustHaveTag(UserSettings{}, "Timezone")
)
Functions ¶
func ClearLoginCache ¶
ClearLoginCache clears a user or all users' tokens from the cache, forcibly logging them out
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 GetRoleManager ¶
func GetRoleManager() gimlet.RoleManager
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"` // contains filtered or unexported fields }
func FindByGithubUID ¶
func FindOneByToken ¶
FindOneByToken gets a DBUser by cached login token.
func GetPatchUser ¶
func (*DBUser) AddPublicKey ¶
func (*DBUser) DeletePublicKey ¶
func (*DBUser) DisplayName ¶
func (*DBUser) HasPermission ¶
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) RemoveRole ¶
func (*DBUser) UnmarshalBSON ¶
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:"-"` 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 {
PatchPage bool `json:"patch_page" bson:"patch_page"`
}
type UserSettings ¶
type UserSettings struct { Timezone string `json:"timezone" bson:"timezone"` 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
const ( PreferenceEmail UserSubscriptionPreference = event.EmailSubscriberType PreferenceSlack UserSubscriptionPreference = event.SlackSubscriberType )