models

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 16 Imported by: 3 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const CreatedAt = "created_at"
View Source
const SystemUserID = "0"

Variables

View Source
var SystemUserUUID = uuid.Nil

Functions

func CountOtherUsers

func CountOtherUsers(tx *storage.Connection, instanceID, id uuid.UUID) (int, error)

CountOtherUsers counts how many other users exist besides the one provided

func DeleteInstance

func DeleteInstance(conn *storage.Connection, instance *Instance) error

func FindUserWithRefreshToken

func FindUserWithRefreshToken(tx *storage.Connection, token string) (*User, *RefreshToken, error)

FindUserWithRefreshToken finds a user from the provided refresh token.

func IsDuplicatedEmail

func IsDuplicatedEmail(tx *storage.Connection, instanceID uuid.UUID, email, aud string) (bool, error)

IsDuplicatedEmail returns whether a user exists with a matching email and audience.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns whether an error represents a "not found" error.

func Logout

func Logout(tx *storage.Connection, instanceID uuid.UUID, id uuid.UUID) error

Logout deletes all refresh tokens for a user.

func NewAuditLogEntry

func NewAuditLogEntry(tx *storage.Connection, instanceID uuid.UUID, actor *User, action AuditAction, traits map[string]interface{}) error

func TruncateAll

func TruncateAll(conn *storage.Connection) error

Types

type AuditAction

type AuditAction string
const (
	LoginAction                 AuditAction = "login"
	LogoutAction                AuditAction = "logout"
	InviteAcceptedAction        AuditAction = "invite_accepted"
	UserSignedUpAction          AuditAction = "user_signedup"
	UserInvitedAction           AuditAction = "user_invited"
	UserDeletedAction           AuditAction = "user_deleted"
	UserModifiedAction          AuditAction = "user_modified"
	UserRecoveryRequestedAction AuditAction = "user_recovery_requested"
	TokenRevokedAction          AuditAction = "token_revoked"
	TokenRefreshedAction        AuditAction = "token_refreshed"
)

type AuditLogEntry

type AuditLogEntry struct {
	InstanceID uuid.UUID `json:"-" db:"instance_id"`
	ID         uuid.UUID `json:"id" db:"id"`

	Payload JSONMap `json:"payload" db:"payload"`

	CreatedAt time.Time `json:"created_at" db:"created_at"`
}

AuditLogEntry is the database model for audit log entries.

func FindAuditLogEntries

func FindAuditLogEntries(tx *storage.Connection, instanceID uuid.UUID, filterColumns []string, filterValue string, pageParams *Pagination) ([]*AuditLogEntry, error)

func (AuditLogEntry) TableName

func (AuditLogEntry) TableName() string

type Instance

type Instance struct {
	ID uuid.UUID `json:"id" db:"id"`
	// Netlify UUID
	UUID uuid.UUID `json:"uuid,omitempty" db:"uuid"`

	BaseConfig *conf.Configuration `json:"config" db:"raw_base_config"`

	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

func GetInstance

func GetInstance(tx *storage.Connection, instanceID uuid.UUID) (*Instance, error)

GetInstance finds an instance by ID

func GetInstanceByUUID

func GetInstanceByUUID(tx *storage.Connection, uuid uuid.UUID) (*Instance, error)

func (*Instance) Config

func (i *Instance) Config() (*conf.Configuration, error)

Config loads the the base configuration values with defaults.

func (Instance) TableName

func (Instance) TableName() string

func (*Instance) UpdateConfig

func (i *Instance) UpdateConfig(tx *storage.Connection, config *conf.Configuration) error

UpdateConfig updates the base config

type InstanceNotFoundError

type InstanceNotFoundError struct{}

InstanceNotFoundError represents when an instance is not found.

func (InstanceNotFoundError) Error

func (e InstanceNotFoundError) Error() string

type JSONMap

type JSONMap map[string]interface{}

func (JSONMap) Scan

func (j JSONMap) Scan(src interface{}) error

func (JSONMap) Value

func (j JSONMap) Value() (driver.Value, error)

type Pagination

type Pagination struct {
	Page    uint64
	PerPage uint64
	Count   uint64
}

func (*Pagination) Offset

func (p *Pagination) Offset() uint64

type RefreshToken

type RefreshToken struct {
	InstanceID uuid.UUID `json:"-" db:"instance_id"`
	ID         int64     `db:"id"`

	Token string `db:"token"`

	UserID uuid.UUID `db:"user_id"`

	Revoked   bool      `db:"revoked"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

RefreshToken is the database model for refresh tokens.

func GrantAuthenticatedUser

func GrantAuthenticatedUser(tx *storage.Connection, user *User) (*RefreshToken, error)

GrantAuthenticatedUser creates a refresh token for the provided user.

func GrantRefreshTokenSwap

func GrantRefreshTokenSwap(tx *storage.Connection, user *User, token *RefreshToken) (*RefreshToken, error)

GrantRefreshTokenSwap swaps a refresh token for a new one, revoking the provided token.

func (RefreshToken) TableName

func (RefreshToken) TableName() string

type RefreshTokenNotFoundError

type RefreshTokenNotFoundError struct{}

RefreshTokenNotFoundError represents when a refresh token is not found.

func (RefreshTokenNotFoundError) Error

type SortDirection

type SortDirection string
const Ascending SortDirection = "ASC"
const Descending SortDirection = "DESC"

type SortField

type SortField struct {
	Name string
	Dir  SortDirection
}

type SortParams

type SortParams struct {
	Fields []SortField
}

type User

type User struct {
	InstanceID uuid.UUID `json:"-" db:"instance_id"`
	ID         uuid.UUID `json:"id" db:"id"`

	Aud               string     `json:"aud" db:"aud"`
	Role              string     `json:"role" db:"role"`
	Email             string     `json:"email" db:"email"`
	EncryptedPassword string     `json:"-" db:"encrypted_password"`
	ConfirmedAt       *time.Time `json:"confirmed_at,omitempty" db:"confirmed_at"`
	InvitedAt         *time.Time `json:"invited_at,omitempty" db:"invited_at"`

	ConfirmationToken  string     `json:"-" db:"confirmation_token"`
	ConfirmationSentAt *time.Time `json:"confirmation_sent_at,omitempty" db:"confirmation_sent_at"`

	RecoveryToken  string     `json:"-" db:"recovery_token"`
	RecoverySentAt *time.Time `json:"recovery_sent_at,omitempty" db:"recovery_sent_at"`

	EmailChangeToken  string     `json:"-" db:"email_change_token"`
	EmailChange       string     `json:"new_email,omitempty" db:"email_change"`
	EmailChangeSentAt *time.Time `json:"email_change_sent_at,omitempty" db:"email_change_sent_at"`

	LastSignInAt *time.Time `json:"last_sign_in_at,omitempty" db:"last_sign_in_at"`

	AppMetaData  JSONMap `json:"app_metadata" db:"raw_app_meta_data"`
	UserMetaData JSONMap `json:"user_metadata" db:"raw_user_meta_data"`

	IsSuperAdmin bool `json:"-" db:"is_super_admin"`

	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

User respresents a registered user with email/password authentication

func FindUserByConfirmationToken

func FindUserByConfirmationToken(tx *storage.Connection, token string) (*User, error)

FindUserByConfirmationToken finds users with the matching confirmation token.

func FindUserByEmailAndAudience

func FindUserByEmailAndAudience(tx *storage.Connection, instanceID uuid.UUID, email, aud string) (*User, error)

FindUserByEmailAndAudience finds a user with the matching email and audience.

func FindUserByID

func FindUserByID(tx *storage.Connection, id uuid.UUID) (*User, error)

FindUserByID finds a user matching the provided ID.

func FindUserByInstanceIDAndID

func FindUserByInstanceIDAndID(tx *storage.Connection, instanceID, id uuid.UUID) (*User, error)

FindUserByInstanceIDAndID finds a user matching the provided ID.

func FindUserByRecoveryToken

func FindUserByRecoveryToken(tx *storage.Connection, token string) (*User, error)

FindUserByRecoveryToken finds a user with the matching recovery token.

func FindUsersInAudience

func FindUsersInAudience(tx *storage.Connection, instanceID uuid.UUID, aud string, pageParams *Pagination, sortParams *SortParams, filter string) ([]*User, error)

FindUsersInAudience finds users with the matching audience.

func NewSystemUser

func NewSystemUser(instanceID uuid.UUID, aud string) *User

func NewUser

func NewUser(instanceID uuid.UUID, email, password, aud string, userData map[string]interface{}) (*User, error)

NewUser initializes a new user from an email, password and user data.

func (*User) Authenticate

func (u *User) Authenticate(password string) bool

Authenticate a user from a password

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *pop.Connection) error

func (*User) BeforeSave

func (u *User) BeforeSave(tx *pop.Connection) error

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(tx *pop.Connection) error

func (*User) Confirm

func (u *User) Confirm(tx *storage.Connection) error

Confirm resets the confimation token and the confirm timestamp

func (*User) ConfirmEmailChange

func (u *User) ConfirmEmailChange(tx *storage.Connection) error

ConfirmEmailChange confirm the change of email for a user

func (*User) HasRole

func (u *User) HasRole(roleName string) bool

HasRole returns true when the users role is set to roleName

func (*User) IsConfirmed

func (u *User) IsConfirmed() bool

IsConfirmed checks if a user has already being registered and confirmed.

func (*User) Recover

func (u *User) Recover(tx *storage.Connection) error

Recover resets the recovery token

func (*User) SetEmail

func (u *User) SetEmail(tx *storage.Connection, email string) error

func (*User) SetRole

func (u *User) SetRole(tx *storage.Connection, roleName string) error

SetRole sets the users Role to roleName

func (User) TableName

func (User) TableName() string

func (*User) UpdateAppMetaData

func (u *User) UpdateAppMetaData(tx *storage.Connection, updates map[string]interface{}) error

UpdateAppMetaData updates all app data from a map of updates

func (*User) UpdatePassword

func (u *User) UpdatePassword(tx *storage.Connection, password string) error

func (*User) UpdateUserMetaData

func (u *User) UpdateUserMetaData(tx *storage.Connection, updates map[string]interface{}) error

UpdateUserMetaData sets all user data from a map of updates, ensuring that it doesn't override attributes that are not in the provided map.

type UserNotFoundError

type UserNotFoundError struct{}

UserNotFoundError represents when a user is not found.

func (UserNotFoundError) Error

func (e UserNotFoundError) Error() string

Jump to

Keyboard shortcuts

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