Documentation ¶
Index ¶
- type BaseModel
- type BaseModelSeq
- type BaseModelSeqSoftDelete
- type BaseModelSoftDelete
- type Permission
- type Role
- type User
- func (u *User) AfterSave(scope *gorm.Scope) error
- func (u *User) BeforeSave(scope *gorm.Scope) error
- func (u *User) GetDisplayName() string
- func (u *User) HasPermission(permission string, entity string) (bool, error)
- func (u *User) HasPermissionBool(permission string, entity string) bool
- func (u *User) HasPermissionTag(tag string) (bool, error)
- func (u *User) HasRole(roleID int) (bool, error)
- type UserAPIKey
- type UserPermission
- type UserProfile
- type UserRole
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct { // Default values for PostgreSQL, change it for other DBMS ID uuid.UUID `gorm:"primary_key;type:uuid;default:uuid_generate_v4()"` CreatedByID *uuid.UUID `gorm:"type:uuid"` UpdatedByID *uuid.UUID `gorm:"type:uuid"` CreatedAt *time.Time `gorm:"index;not null;default:current_timestamp"` UpdatedAt *time.Time `gorm:"index"` }
BaseModel defines the common columns that all db structs should hold, usually db structs based on this have no soft delete
type BaseModelSeq ¶
type BaseModelSeq struct { // Default values for PostgreSQL, change it for other DBMS ID int `gorm:"primary_key,auto_increment"` CreatedByID *uuid.UUID `gorm:"type:uuid"` UpdatedByID *uuid.UUID `gorm:"type:uuid"` CreatedAt *time.Time `gorm:"index;not null;default:current_timestamp"` UpdatedAt *time.Time `gorm:"index"` }
BaseModelSeq defines the common columns that all db structs should hold, with an INT key
type BaseModelSeqSoftDelete ¶
type BaseModelSeqSoftDelete struct { BaseModelSeq DeletedByID *uuid.UUID `gorm:"type:uuid"` DeletedAt *time.Time `gorm:"index"` }
BaseModelSeqSoftDelete defines the common columns that all db structs should hold, usually. This struct also defines the fields for GORM triggers to detect the entity should soft delete
type BaseModelSoftDelete ¶
type BaseModelSoftDelete struct { BaseModel DeletedByID *uuid.UUID `gorm:"type:uuid"` DeletedAt *time.Time `gorm:"index"` }
BaseModelSoftDelete defines the common columns that all db structs should hold, usually. This struct also defines the fields for GORM triggers to detect the entity should soft delete
type Permission ¶
type Permission struct { BaseModelSeq Tag string `gorm:"not null;unique_index"` Description string `gorm:"size:1024"` }
Permission defines a permission scope for the user
type Role ¶
type Role struct { BaseModelSeq Name string `gorm:"not null"` Description string `gorm:"size:1024"` ParentRoles []Role `gorm:"many2many:role_parents;association_jointable_foreignkey:parent_role_id"` ChildRoles []Role `gorm:"many2many:role_parents;association_jointable_foreignkey:role_id"` Permissions []Permission `gorm:"many2many:role_permissions;association_autoupdate:false;association_autocreate:false"` }
Role defines a role for the user
type User ¶
type User struct { BaseModelSoftDelete // We don't to actually delete the users, audit Email string `gorm:"not null;index"` Password string Name *string `gorm:"null"` NickName *string FirstName *string LastName *string Location *string AvatarURL *string `gorm:"size:1024"` Description *string `gorm:"size:1024"` UserProfiles []UserProfile `gorm:"association_autocreate:false;association_autoupdate:false"` Roles []Role `gorm:"many2many:user_roles;association_autocreate:false;association_autoupdate:false"` Permissions []Permission `gorm:"many2many:user_permissions;association_autocreate:false;association_autoupdate:false"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false"` }
User defines a user for the app
func (*User) BeforeSave ¶
BeforeSave hook for User
func (*User) GetDisplayName ¶
GetDisplayName returns the displayName if not nil, or the first + last name
func (*User) HasPermission ¶
HasPermission verifies if user has a specific permission
func (*User) HasPermissionBool ¶
HasPermissionBool verifies if user has a specific permission - returns t/f
func (*User) HasPermissionTag ¶
HasPermissionTag verifies if user has a specific permission tag
type UserAPIKey ¶
type UserAPIKey struct { BaseModelSeq Name string User User `gorm:"association_autocreate:false;association_autoupdate:false"` UserID uuid.UUID `gorm:"not null;index"` APIKey string `gorm:"size:128;unique_index"` Permissions []Permission `gorm:"many2many:user_api_key_permissions;association_autocreate:false;association_autoupdate:false"` }
UserAPIKey generated api keys for the users
func (*UserAPIKey) BeforeSave ¶
func (k *UserAPIKey) BeforeSave(scope *gorm.Scope) error
BeforeSave hook for UserAPIKey
type UserPermission ¶
UserPermission relation between an user and its permissions
type UserProfile ¶
type UserProfile struct { BaseModelSeq Email string `gorm:"unique_index:idx_email_provider_external_user_id"` UserID uuid.UUID `gorm:"not null;index"` User User `gorm:"association_autocreate:false;association_autoupdate:false"` Provider string `gorm:"not null;index;unique_index:idx_email_provider_external_user_id;default:'DB'"` // DB means database or no ExternalUserID ExternalUserID string `gorm:"not null;index;unique_index:idx_email_provider_external_user_id"` // User ID Name string NickName string FirstName string LastName string Location string `gorm:"size:512"` AvatarURL string `gorm:"size:1024"` Description string `gorm:"size:1024"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false"` }
UserProfile saves all the related OAuth Profiles