Documentation ¶
Index ¶
- func AddOrUpdateTenantRole(userID uint, tenantID int, role string, includedPermissions string, ...)
- func AddOrUpdateUserMeta(userID uint, metaKey string, metaValue string, isUnique bool) error
- func CreateUser(user *User) (uint, error)
- func DeleteTenant(tenantID uint)
- func DeleteUser(userID uint)
- func DeleteUserMeta(userID uint, metaKey string)
- func DeleteUserTenantRole(userID uint, tenantID uint)
- func FormatUserMeta(userMeta []UserMeta) map[string]string
- func GetTenants() map[uint]string
- func GetUserMetaValue(userID uint, metaKey string, tenantID int) (string, error)
- func GetUserTenants(userID uint) map[uint]string
- func GetUserTenantsPermissions(roles []UserTenantRole) map[int][]string
- func Init()
- func UpdateTenant(tenantID uint, updatedTenant *Tenant)
- func UpdateUser(userID uint, updateUser *User)
- func UserExists(userId uint, tenantId int) bool
- type Permission
- type Role
- type RolesResponse
- type Tenant
- type User
- type UserMeta
- type UserTenantRole
- type UserWithRole
- type UsersFilterFields
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddOrUpdateTenantRole ¶
func AddOrUpdateTenantRole(userID uint, tenantID int, role string, includedPermissions string, excludedPermissions string)
AddOrUpdateTenantRole - update user role in a tenant
func AddOrUpdateUserMeta ¶
AddOrUpdateUserMeta - add/update user meta
func DeleteUserMeta ¶
DeleteUserMeta - permanently delete a meta
func DeleteUserTenantRole ¶
DeleteUserTenantRole - permanently delete a user role in a tenant
func FormatUserMeta ¶
FormatUserMeta - formats user data
func GetUserMetaValue ¶
GetUserMetaValue - get user meta
func GetUserTenants ¶
GetUserTenants - get tenants thst user has role in
func GetUserTenantsPermissions ¶
func GetUserTenantsPermissions(roles []UserTenantRole) map[int][]string
GetUserTenantsPermissions - get user permissions in tenants
func Init ¶
func Init()
Init - initials connection to db and do migrations and seeds admin and tenant data
func UpdateTenant ¶
UpdateTenant - update single tenant
func UserExists ¶
UserExists - check if user has any role in a tenant
Types ¶
type Permission ¶
Permission - permission structure
type RolesResponse ¶
type RolesResponse struct { Roles []Role Permissions []Permission }
RolesResponse - response type of a role
func Roles ¶
func Roles() RolesResponse
Roles - returns roles that are declared hardcoded and added in config
type Tenant ¶
type Tenant struct { ID uint `gorm:"primary_key"` Name string `gorm:"type:varchar(32);not null"` Status int `gorm:"type:int(1);not null;index"` }
Tenant - tenant structure
func CreateTenant ¶
CreateTenant - create a new tenant
type User ¶
type User struct { gorm.Model Username string `gorm:"type:varchar(32);unique_index;not null"` Password string `gorm:"type:varchar(64);not null"` Email string `gorm:"type:varchar(32);unique"` DisplayName string `gorm:"type:varchar(32)"` Status int `gorm:"type:int(3);not null;index;default:1"` UserMetas []UserMeta UserTenantRoles []UserTenantRole }
User - user structure
func GetUserByUsername ¶
GetUserByUsername - get user data by username
type UserMeta ¶
type UserMeta struct { ID uint `gorm:"primary_key"` UserID uint `gorm:"index;not null"` MetaKey string `gorm:"type:varchar(255);not null;index"` MetaValue string `gorm:"type:longtext;not null"` }
UserMeta - user meta structure
type UserTenantRole ¶
type UserTenantRole struct { gorm.Model UserID uint `gorm:"index;not null"` TenantID uint `gorm:"index;not null"` Role string `gorm:"type:varchar(32);not null;index"` IncludedPermissions string `gorm:"type:varchar(512)"` ExcludedPermissions string `gorm:"type:varchar(512)"` }
UserTenantRole - user tenant role structure
type UserWithRole ¶
type UserWithRole struct { ID uint CreatedAt time.Time UpdatedAt time.Time Username string Email string DisplayName string Status int Role string }
UserWithRole - user data + role data
func GetUsers ¶
func GetUsers(args UsersFilterFields, tenantID int) []UserWithRole
GetUsers - get users by filters