Documentation ¶
Index ¶
- Variables
- func IsAllow(method string, access AccessLevel) bool
- type AccessLevel
- type ErrorNotFoundOrganisation
- type ErrorNotFoundRole
- type ModulesPermissions
- type Role
- type SessionBase
- type SessionInterface
- type User
- func (u *User) Clean(db *gorm.DB) error
- func (u *User) ComparePassword(password string) bool
- func (u *User) Create(db *gorm.DB) error
- func (u *User) Delete(db *gorm.DB) error
- func (User) Description() string
- func (u *User) GetPk() uint
- func (u *User) RefreshToken() (string, error)
- func (u *User) SetPK(pk interface{}) error
- func (u *User) SetPassword(password string, db *gorm.DB) error
- func (User) TableName() string
- func (u *User) Token() (string, error)
- func (u *User) Update(db *gorm.DB) error
- func (u *User) Validate() bool
Constants ¶
This section is empty.
Variables ¶
View Source
var ( HTTP_METHOD_ACCESS = map[string]AccessLevel{ http.MethodGet: READER, http.MethodHead: READER, http.MethodOptions: READER, http.MethodPost: WRITER, http.MethodPut: WRITER, http.MethodPatch: WRITER, http.MethodDelete: ADMIN, } )
View Source
var ( UserConvertersData = map[string]func(*User, interface{}, *gorm.DB) error{ "id": func(u *User, i interface{}, db *gorm.DB) error { id, err := common.ConvertToInt(i) if err != nil { return fmt.Errorf("error convert interface{}[%v] to ID(uint): %w", i, err) } u.ID = uint(id) return nil }, "email": func(u *User, i interface{}, db *gorm.DB) error { email, ok := i.(string) if !ok { return fmt.Errorf("convert interface{}[%v] to Email(string)", i) } u.Email = email return nil }, "is_active": func(u *User, i interface{}, db *gorm.DB) error { isActive, ok := i.(bool) if !ok { return fmt.Errorf("convert interface{}[%v] to IsActive(bool)", i) } u.IsActive = isActive return nil }, "is_superuser": func(u *User, i interface{}, db *gorm.DB) error { isSuperuser, ok := i.(bool) if !ok { return fmt.Errorf("convert interface{}[%v] to IsSuperuser(bool)", i) } u.IsSuperuser = isSuperuser return nil }, "role": func(u *User, i interface{}, db *gorm.DB) error { if i == nil { return nil } s := reflect.ValueOf(i) if s.Kind() != reflect.Map { return fmt.Errorf("interfaceStruct() given a non-struct type") } if s.IsNil() { return nil } roleMap, isOk := i.(map[string]interface{}) if !isOk { return fmt.Errorf("error convert map to role") } role := &Role{} if err := db.Model(&Role{}).Preload("ModulesPermissions").Where("id = ?", roleMap["id"]).First(role).Error; err == nil { u.Role = role } else { return err } return nil }, } )
Functions ¶
func IsAllow ¶
func IsAllow(method string, access AccessLevel) bool
Types ¶
type AccessLevel ¶
type AccessLevel uint
const ( ADMIN AccessLevel = 1 WRITER AccessLevel = 2 READER AccessLevel = 3 )
type ErrorNotFoundOrganisation ¶
type ErrorNotFoundOrganisation struct { }
func (*ErrorNotFoundOrganisation) Error ¶
func (e *ErrorNotFoundOrganisation) Error() string
type ErrorNotFoundRole ¶
type ErrorNotFoundRole struct { }
func (*ErrorNotFoundRole) Error ¶
func (e *ErrorNotFoundRole) Error() string
type ModulesPermissions ¶
type ModulesPermissions struct { serializers.Serializer models.BaseModel ID uint `json:"id" serializer:"read_only;" gorm:"primarykey"` Name string `json:"name" serializer:"read_only;title:Название модуля;" gorm:"column:name;uniqueIndex:idx_name_access"` Access AccessLevel `json:"access" serializer:"read_only;title:Уровень доступа;" gorm:"column:access;uniqueIndex:idx_name_access"` Roles []Role `json:"-" gorm:"many2many:roles_modules;"` }
ModulesPermissions - модель описывающая связь модуля и уровнем доступа Модуль - это лoгический слой, объединяющий в себе несолько таблиц Модуль и уровни доступа создаются при инициализации приложения, поэтому в апи не предусмотрены методы CUD для этой таблицы
func (ModulesPermissions) Description ¶
func (ModulesPermissions) Description() string
func (ModulesPermissions) TableName ¶
func (ModulesPermissions) TableName() string
type Role ¶
type Role struct { serializers.Serializer models.BaseModel ID uint `json:"id" serializer:"read_only" gorm:"primarykey"` Name string `json:"name" serializer:"required;title:Название роли;" gorm:"column:name;unique;"` ModulesPermissionsIDs []uint `json:"modulesPermissionsIds" serializer:"write_only;referenceTable:module_permissions;referencePk:id;" gorm:"-"` ModulesPermissions []ModulesPermissions `` /* 135-byte string literal not displayed */ }
func (Role) Description ¶
type SessionBase ¶
type SessionBase struct { }
func (*SessionBase) GenerateKey ¶
func (s *SessionBase) GenerateKey() (string, error)
func (*SessionBase) GetSession ¶
func (s *SessionBase) GetSession(r *http.Request) map[string]interface{}
type SessionInterface ¶
type User ¶
type User struct { serializers.Serializer models.BaseModel ID uint `json:"id" serializer:"read_only" gorm:"primarykey"` Email string `json:"email" serializer:"required;title:Емайл;" gorm:"type:varchar(100);unique;unique_index;column:email"` Lastname string `json:"lastname" serializer:"required;title:Фамилия;" gorm:"column:lastname"` Firstname string `json:"firstname" serializer:"required;title:Имя;" gorm:"column:firstname"` Middlename string `json:"middlename" serializer:"required;title:Отчество;" gorm:"column:middlename"` Phone string `json:"phone" serializer:"title:Телефон;" gorm:"type:varchar(15);column:phone"` AdditionalPhone string `` /* 146-byte string literal not displayed */ Avatar string `json:"avatar" serializer:"title:Аватар;" gorm:"column:avatar"` Password []byte `json:"password" serializer:"write_only;title:Пароль;" gorm:"type:bytea;column:password;"` IsActive bool `json:"isActive" serializer:"title:Активен;" gorm:"column:isActive;"` IsStaff bool `json:"isStaff" serializer:"title:Персонал;" gorm:"column:isStaff;"` IsSuperuser bool `json:"isSuperuser" serializer:"title:Суперпользователь;" gorm:"column:isSuperuser;"` IsDelete bool `json:"isDelete" serializer:"title:Удален;" gorm:"bit(1);column:isDelete;default:false"` RoleID typesdb.UintNullable `json:"roleId" serializer:"write_only;referenceTable:roles;referencePk:id;" gorm:"column:roleId;"` OrganisationID typesdb.UintNullable `json:"organisationId" serializer:"referenceTable:organisations;referencePk:id;" gorm:"column:organisationId;"` CreatedAt time.Time `json:"createdAt" serializer:"read_only"` UpdatedAt time.Time `json:"updatedAt" serializer:"read_only"` Role *Role `json:"role" serializer:"read_only,title:Роли;referenceField:name;" gorm:"foreignkey:RoleID;references:ID;"` }
func (*User) ComparePassword ¶
func (User) Description ¶
func (*User) RefreshToken ¶
Click to show internal directories.
Click to hide internal directories.