Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteJob(id uint64) error
- func EnsureEnoughAdmins() error
- func GetConfigValueByKey(keyword string) (string, error)
- func GetNumberOfUsers() (int64, error)
- func HasAnyUsers() (bool, error)
- func SaveAppConfig(a *AppConfig) error
- func SaveJob(u *Job) error
- func SaveUser(u *User) error
- func SetupDB(d *gorm.DB)
- func UpdateUserPassword(password string, u *User) error
- type AppConfig
- type Job
- type Permission
- type Response
- type Role
- type Tabler
- type User
Constants ¶
const ( // Roles for users RoleAdmin = "admin" RoleUser = "customer" // PermissionViewObjects determines if a role can view standard // objects such as jobs PermissionViewObjects = "view_objects" // PermissionModifyObjects determines if a role can create and modify // standard objects. PermissionModifyObjects = "modify_objects" // PermissionModifySystem determines if a role can manage system-level // configuration. PermissionModifySystem = "modify_system" )
const DateTimeFormat = "2006-01-02 3:4 PM"
Variables ¶
var ErrModifyingOnlyAdmin = errors.New("Cannot remove the only administrator")
ErrModifyingOnlyAdmin occurs when there is an attempt to modify the only user account with the Admin role in such a way that there will be no user
Functions ¶
func EnsureEnoughAdmins ¶
func EnsureEnoughAdmins() error
EnsureEnoughAdmins ensures that there is more than one user account with the Admin role. This function is meant to be called before modifying a user account with the Admin role in a non-revokable way.
func GetConfigValueByKey ¶
GetConfigValueByKey returns the value of the given key
func GetNumberOfUsers ¶
GetNumberOfRows returns the number of rows in the specified table.
func UpdateUserPassword ¶
Types ¶
type AppConfig ¶
type Job ¶
type Job struct { ID uint64 `gorm:"default:uuid_short()"` Status jobstatus.JobStatus `json:"status" sql:"not null"` StatusText string `gorm:"-"` ApiURL string `json:"api_url" sql:"null"` CreatedAt time.Time `json:"created_at" sql:"null"` CompletedTime time.Time `json:"completed_time" sql:"null"` CompletedTimeString string `gorm:"-"` UserID int64 `json:"user_id" sql:"not null"` ScanCompleted bool `gorm:"-"` }
Job represents the job model.
func GetByIDAndUser ¶
GetByIDAndUser returns the job that the given id corresponds to. If no job is found, an error is returned.
func GetJobByID ¶
GetJobByID returns the job that the given id corresponds to. If no job is found, an error is returned.
type Permission ¶
type Permission struct { ID int64 `json:"id"` Keyword string `json:"keyword"` Name string `json:"name"` Description string `json:"description"` }
Permission represents a permission that can be assigned to a role.
type Response ¶
type Response struct { Message string `json:"message"` Success bool `json:"success"` Data interface{} `json:"data"` }
Response contains the attributes found in an API response
type Role ¶
type Role struct { ID int64 `json:"-"` Keyword string `json:"keyword"` Name string `json:"name"` Description string `json:"description"` Permissions []Permission `json:"-" gorm:"many2many:role_permissions;"` }
Role represents a role that can be assigned to a user.
func GetRoleByKeyword ¶
GetRoleByKeyword returns a role that can be assigned to a user.
type User ¶
type User struct { ID int64 `json:"id"` Username string `json:"username" sql:"not null;unique"` Name string `json:"name" sql:"not null"` Password string `json:"password" sql:"null"` Email string `json:"email" sql:"null:unique"` RoleID int64 `json:"-"` Role Role `json:"role" gorm:"association_autoupdate:false;association_autocreate:false"` }
User represents the user model
func GetUserByAPIKey ¶
GetUserByAPIKey returns the user that the given API Key corresponds to. If no user is found, an error is thrown.
func GetUserByID ¶
GetUser returns the user that the given id corresponds to. If no user is found, an error is thrown.
func GetUserByUsername ¶
GetUserByUsername returns the user that the given username corresponds to. If no user is found, an error is thrown.