models

package
v0.0.0-...-e10842c Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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()"`
	CreatedAt *time.Time `gorm:"index;not null;default:current_timestamp"`
	UpdatedAt *time.Time `gorm:"index;not null;default:current_timestamp"`
}

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        uint       `gorm:"primary_key,auto_increment"`
	CreatedAt *time.Time `gorm:"index;not null;default:current_timestamp"`
	UpdatedAt *time.Time `gorm:"index;not null;default:current_timestamp"`
}

BaseModelSeq defines the common columns that all db structs should hold, with an INT key

type BaseModelSeqSoftDelete

type BaseModelSeqSoftDelete struct {
	BaseModelSeq
	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
	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;unique_index"`
	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;unique;index"`
	FirstName           *string
	LastName            *string
	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"`
}

User defines a user for the service

func GothUserToDBUser

func GothUserToDBUser(i *goth.User, update bool, ids ...string) (o *User, err error)

GothUserToDBUser transforms [user] goth to db model

func (*User) BeforeSave

func (u *User) BeforeSave(db *gorm.DB) error

BeforeSave hook for User

func (*User) CanUpdate

func (u *User) CanUpdate(id string) (bool, error)

CanUpdate verifies if user can update if owner - returns t/f

func (*User) HasPermission

func (u *User) HasPermission(permission string, entity string) (bool, error)

HasPermission verifies if user has a specific permission

func (*User) HasPermissionTag

func (u *User) HasPermissionTag(tag string) (bool, error)

HasPermissionTag verifies if user has a specific permission tag

func (*User) HasRole

func (u *User) HasRole(roleID int) (bool, error)

HasRole verifies if user possesses a role

type UserAPIKey

type UserAPIKey struct {
	BaseModelSeqSoftDelete
	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;default:uuid_generate_v4()"`
	Permissions []Permission `gorm:"many2many:user_api_key_permissions;association_autocreate:false;association_autoupdate:false"`
}

UserAPIKey generated api keys for the users

type UserPermission

type UserPermission struct {
	UserID       uuid.UUID `gorm:"index"`
	PermissionID int       `gorm:"index"`
}

UserPermission relation between an user and its permissions

type UserProfile

type UserProfile struct {
	BaseModelSeq
	Email          string    `gorm:"uniqueIndex: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
	FirstName      string
	LastName       string
	AvatarURL      string `gorm:"size:1024"`
	Description    string `gorm:"size:1024"`
}

UserProfile saves all the related OAuth Profiles

func GothUserToDBUserProfile

func GothUserToDBUserProfile(i *goth.User, update bool, ids ...int) (o *UserProfile, err error)

GothUserToDBUserProfile transforms [user] goth to db model

type UserRole

type UserRole struct {
	UserID uuid.UUID `gorm:"index"`
	RoleID int       `gorm:"index"`
}

UserRole relation between an user and its roles

Jump to

Keyboard shortcuts

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