twisk

package
v0.0.0-...-5c3d8b3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessRole

type AccessRole int8

AccessRole represents access role type

const (
	// SuperAdminRole has all permissions
	SuperAdminRole AccessRole = iota + 1

	// AdminRole has admin specific permissions
	AdminRole

	// TenantAdminRole can edit tenant specific things
	TenantAdminRole

	// UserRole is a standard user
	UserRole
)

type AuthUser

type AuthUser struct {
	ID       int64
	TenantID int32
	Username string
	Email    string
	Role     AccessRole
}

AuthUser represents data stored in session/context for a user

type Logger

type Logger interface {
	// source, msg, error, params
	Log(context.Context, string, string, error, map[string]interface{})
}

Logger represents logging interface

type RBACService

type RBACService interface {
	EnforceRole(context.Context, AccessRole) bool
	EnforceUser(context.Context, int64) bool
	EnforceTenant(context.Context, int32) bool
	EnforceTenantAdmin(context.Context, int32) bool
	EnforceTenantAndRole(context.Context, AccessRole, int32) bool
	IsLowerRole(context.Context, AccessRole) bool
}

RBACService represents role-based access control service interface

type Role

type Role struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Role entity

type Tenant

type Tenant struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Active bool   `json:"active"`
}

Tenant table

type User

type User struct {
	ID                 int64
	FirstName          string
	LastName           string
	Username           string
	Password           string
	Email              string
	Phone              string
	Address            string
	Active             bool
	Token              string
	RoleID             int32
	TenantID           int32
	CreatedAt          time.Time
	UpdatedAt          time.Time
	DeletedAt          *time.Time
	LastLogin          *time.Time
	LastPasswordChange *time.Time
}

User represents user domain model

func (*User) BeforeInsert

func (u *User) BeforeInsert(_ orm.DB) error

BeforeInsert hooks into insert operations, setting createdAt and updatedAt to current time

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(_ orm.DB) error

BeforeUpdate hooks into update operations, setting updatedAt to current time

func (*User) Delete

func (u *User) Delete()

Delete sets deleted_at time to current_time

func (*User) Proto

func (u *User) Proto() *user.Resp

Proto converts user db to proto User

func (*User) UpdateLoginDetails

func (u *User) UpdateLoginDetails(token string)

UpdateLoginDetails updates login related fields

Jump to

Keyboard shortcuts

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