Documentation ¶
Overview ¶
Package models contains all the models for the application
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGeneric is used for testing purposes and for errors handled later in the callstack ErrGeneric = errors.New("generic error") // ErrBadRequest (400) is returned for bad request (validation) ErrBadRequest = echo.NewHTTPError(400) ErrUnauthorized = echo.ErrUnauthorized )
var ValidRoles = map[uint]Role{ 1: Role{ID: 1, AccessLevel: SuperAdminRole, Name: "SUPER_ADMIN"}, 2: Role{ID: 2, AccessLevel: AdminRole, Name: "ADMIN"}, 3: Role{ID: 3, AccessLevel: AccountAdminRole, Name: "ACCOUNT_ADMIN"}, 4: Role{ID: 4, AccessLevel: TeamAdminRole, Name: "TEAM_ADMIN"}, 5: Role{ID: 5, AccessLevel: UserRole, Name: "USER_ADMIN"}, }
ValidRoles contains all valid roles mapped to their ID
Functions ¶
This section is empty.
Types ¶
type AccessRole ¶
type AccessRole uint
AccessRole represents access role type
const ( // SuperAdminRole has all permissions SuperAdminRole AccessRole = 100 // AdminRole has admin specific permissions AdminRole AccessRole = 110 // AccountAdminRole can edit account specific things AccountAdminRole AccessRole = 120 // TeamAdminRole can edit team specific things TeamAdminRole AccessRole = 130 // UserRole is a standard user UserRole AccessRole = 200 )
type Account ¶
type Account struct { Base Name string `json:"name"` Users []User `json:"users,omitempty"` Teams []Team `json:"teams,omitempty"` OwnerID uint `json:"owner_id"` }
Account represents account model
type AuthToken ¶
type AuthToken struct { Token string `json:"token"` Expires string `json:"expires"` RefreshToken string `json:"refresh_token"` }
AuthToken holds authentication token details with refresh token
type AuthUser ¶
type AuthUser struct { ID uint AccountID uint TeamID uint Username string Email string AccessLevel AccessRole }
AuthUser represents data stored in JWT token for user
type Base ¶
type Base struct { ID uint `gorm:"primary_key" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"deleted_at" sql:"index"` }
Base contains common fields for all tables
type Logger ¶
type Logger interface { // source, msg, error, params Log(echo.Context, string, string, error, map[string]interface{}) }
Logger represents logging interface
type Pagination ¶
Pagination holds paginations data
type PaginationReq ¶
PaginationReq holds pagination http fields and tags
func (*PaginationReq) NewPagination ¶
func (p *PaginationReq) NewPagination() *Pagination
NewPagination checks and converts http pagination into database pagination model
type RBACService ¶
type RBACService interface { User(echo.Context) *AuthUser EnforceRole(echo.Context, AccessRole) error EnforceUser(echo.Context, uint) error EnforceAccount(echo.Context, uint) error EnforceTeam(echo.Context, uint) error AccountCreate(echo.Context, AccessRole, uint, uint) error IsLowerRole(echo.Context, AccessRole) error }
RBACService represents role-based access control service interface
type RefreshToken ¶
RefreshToken holds authentication token details
type Role ¶
type Role struct { ID uint `json:"id"` AccessLevel AccessRole `json:"access_level"` Name string `json:"name"` }
Role model
func NewRoleFromRoleID ¶
NewRoleFromRoleID contains all valid roles
type Team ¶
type Team struct { Base Name string `json:"name"` Description string `json:"description"` AccountID uint `json:"account_id"` Users []User `json:"users"` }
Team represents account team model
type User ¶
type User struct { Base FirstName string `json:"first_name"` LastName string `json:"last_name"` Username string `json:"username"` Password string `json:"-"` Email string `json:"email"` Mobile string `json:"mobile,omitempty"` Phone string `json:"phone,omitempty"` Address string `json:"address,omitempty"` AccountID uint `json:"account_id"` TeamID uint `json:"team_id"` Role Role `json:"role,omitempty" gorm:"foreignkey:ID;association_foreignkey:RoleID;"` RoleID uint `json:"-"` Token string `json:"-"` LastLogin time.Time `json:"last_login,omitempty" gorm:"default:CURRENT_TIMESTAMP"` LastPasswordChange time.Time `json:"last_password_change,omitempty" gorm:"default:CURRENT_TIMESTAMP"` }
User represents user domain model
func (*User) ChangePassword ¶
ChangePassword updates user's password related fields
func (*User) UpdateLastLogin ¶
UpdateLastLogin updates last login field