admins

package
v0.0.0-...-9135915 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const SuperUserRoleName = "superuser"

Variables

Functions

This section is empty.

Types

type Admin

type Admin struct {
	ID            int64          `bson:"id, omitempty"`
	Role          *Role          `bson:"role,omitempty"`
	Notifications *Notifications `bson:"notifications,omitempty"`
}

func (*Admin) HadScopes

func (a *Admin) HadScopes(scopes ...Scope) bool

func (*Admin) Recipient

func (a *Admin) Recipient() string

type AdminNotFound

type AdminNotFound int64

func (AdminNotFound) Error

func (e AdminNotFound) Error() string

type AdminsRepo

type AdminsRepo interface {
	Create(ctx context.Context, admins ...*Admin) ([]*Admin, error)
	CreateIfNotExists(ctx context.Context, admins ...*Admin) ([]*Admin, error)
	AssignRoleByID(ctx context.Context, roleName string, adminID int64) (*Admin, error)
	AssignRoleByIDs(ctx context.Context, roleName string, adminIDs ...int64) ([]*Admin, error)
	GetAll(ctx context.Context) ([]*Admin, error)
	GetAllShouldBeNotifiedAbout(ctx context.Context, notificationType NotificationType) ([]*Admin, error)
	GetByID(ctx context.Context, adminID int64) (*Admin, error)
	GetByIDs(ctx context.Context, adminIDs ...int64) ([]*Admin, error)
	GetRoleByID(ctx context.Context, adminID int64) (*Role, error)
	HasScopesByID(ctx context.Context, adminID int64, scopes ...Scope) (bool, error)
	DeleteByIDs(ctx context.Context, adminIDs ...int64) error
}

type NotificationType

type NotificationType string
const (
	StatusNotificationType NotificationType = "status"
)

type Notifications

type Notifications struct {
	Status []NotifierType `bson:"status,omitempty"`
}

type NotifierType

type NotifierType string
const (
	TelegramNotifier NotifierType = "telegram"
)

type Role

type Role struct {
	Name   string `bson:"name,omitempty"`
	Scopes Scopes `bson:"scopes,omitempty"`
}

func NewRole

func NewRole(name string, scopes ...Scope) *Role

func (*Role) HasScopes

func (r *Role) HasScopes(scopes ...Scope) bool

func (*Role) MarshalBSON

func (r *Role) MarshalBSON() ([]byte, error)

func (*Role) UnmarshalBSON

func (r *Role) UnmarshalBSON(data []byte) error

type RolesRepo

type RolesRepo interface {
	Create(ctx context.Context, roles ...*Role) ([]*Role, error)
	CreateIfNotExists(ctx context.Context, roles ...*Role) ([]*Role, error)
	GetAll(ctx context.Context) ([]*Role, error)
	GetByName(ctx context.Context, name string) (*Role, error)
	GetByNames(ctx context.Context, names ...string) ([]*Role, error)
	AddScopes(ctx context.Context, scopes []Scope, names ...string) ([]*Role, error)
	SetScopes(ctx context.Context, scopes []Scope, names ...string) ([]*Role, error)
	DeleteByNames(ctx context.Context, names ...string) error
}

type Scope

type Scope string
const (
	AdminsScope     Scope = "admins"
	AdminsReadScope Scope = "admins.read"
	StatsScope      Scope = "stats"
)

func (Scope) Implies

func (s Scope) Implies() Scopes

type Scopes

type Scopes map[Scope]struct{}

func NewScopes

func NewScopes(scopes ...Scope) Scopes

func (Scopes) Has

func (s Scopes) Has(scopes ...Scope) bool

func (Scopes) Implies

func (s Scopes) Implies() Scopes

func (Scopes) MarshalBSON

func (s Scopes) MarshalBSON() ([]byte, error)

func (Scopes) UnmarshalBSON

func (s Scopes) UnmarshalBSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL