2024-08-14 10:36:43 +00:00
|
|
|
package models
|
|
|
|
|
2024-10-09 17:07:38 +00:00
|
|
|
import (
|
|
|
|
"git.sch9.ru/new_gate/ms-auth/pkg/utils"
|
|
|
|
)
|
2024-08-14 10:36:43 +00:00
|
|
|
|
|
|
|
type Role int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
RoleSpectator Role = 0
|
|
|
|
RoleParticipant Role = 1
|
|
|
|
RoleModerator Role = 2
|
|
|
|
RoleAdmin Role = 3
|
|
|
|
)
|
|
|
|
|
|
|
|
func (role Role) IsAdmin() bool {
|
|
|
|
return role == RoleAdmin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (role Role) IsModerator() bool {
|
|
|
|
return role == RoleModerator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (role Role) IsParticipant() bool {
|
|
|
|
return role == RoleParticipant
|
|
|
|
}
|
|
|
|
|
|
|
|
func (role Role) IsSpectator() bool {
|
|
|
|
return role == RoleSpectator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (role Role) AtLeast(other Role) bool {
|
|
|
|
return role >= other
|
|
|
|
}
|
|
|
|
|
|
|
|
func (role Role) AtMost(other Role) bool {
|
|
|
|
return role <= other
|
|
|
|
}
|
|
|
|
|
|
|
|
func (role Role) Valid() error {
|
|
|
|
switch role {
|
|
|
|
case RoleSpectator, RoleParticipant, RoleModerator, RoleAdmin:
|
|
|
|
return nil
|
|
|
|
}
|
2024-10-09 17:07:38 +00:00
|
|
|
return utils.ErrBadRole
|
2024-08-14 10:36:43 +00:00
|
|
|
}
|