Files
logbot3/internal/models/user.go
T
2018-11-11 13:18:05 +01:00

27 lines
605 B
Go

package models
// A User is the information about ID and permission for a user, usually
// the caller.
type User struct {
ID string `json:"id"`
Permissions []string `json:"permissions"`
}
// LoggedIn returns true if the user is logged-in.
func (user *User) LoggedIn() bool {
return user.ID != ""
}
// Permitted gets whether the user has this permission.
func (user *User) Permitted(permissions ...string) bool {
for _, userPermission := range user.Permissions {
for _, permission := range permissions {
if permission == userPermission {
return true
}
}
}
return false
}