permissions

package
v0.0.0-...-b9cfb1f Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: GPL-3.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

View Source
const (
	LevelVisitor  PermissionLevel = iota
	LevelMember                   = 1
	LevelOperator                 = 2
	LevelCustom                   = 3
)

Variables

View Source
var (
	UnknownPermission = errors.New("unknown permission")
	UnknownGroup      = errors.New("unknown group")
)

Functions

This section is empty.

Types

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group is a struct used for basic permission managing. Groups can be granted a set of permissions.

func NewGroup

func NewGroup(name string, level int) *Group

NewGroup returns a new group with the given name and permission level.

func (*Group) AddPermission

func (group *Group) AddPermission(permission *Permission)

AddPermission adds a permission to the group.

func (*Group) GetName

func (group *Group) GetName() string

GetName returns the name of the group.

func (*Group) GetPermissions

func (group *Group) GetPermissions() map[string]*Permission

GetPermissions returns a name => permission map of all permissions of the group.

func (*Group) HasPermission

func (group *Group) HasPermission(permission string) bool

HasPermission checks if the group has a permission with the name.

func (*Group) InheritGroup

func (group *Group) InheritGroup(inheritedGroup *Group)

InheritGroup inherits all permissions from a group.

func (*Group) RemovePermission

func (group *Group) RemovePermission(permission string)

RemovePermission removes a permission with the given name from the group.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is a struct used to manage permissions and groups. It provides helper functions and functions to register groups and permissions.

func NewManager

func NewManager() *Manager

NewManager returns a new permission manager.

func (*Manager) AddGroup

func (manager *Manager) AddGroup(group *Group)

AddGroup adds a new group to the manager.

func (*Manager) GetDefaultGroup

func (manager *Manager) GetDefaultGroup() *Group

GetDefaultGroup returns the default group of the manager.

func (*Manager) GetGroup

func (manager *Manager) GetGroup(name string) (*Group, error)

GetGroup returns a group in the manager with the given name and an error if it could not be found.

func (*Manager) GetPermission

func (manager *Manager) GetPermission(name string) (*Permission, error)

GetPermission returns a permission by its name, and an error if it could not be found.

func (*Manager) GroupExists

func (manager *Manager) GroupExists(name string) bool

GroupExists checks if a group with the given name exists.

func (*Manager) IsPermissionRegistered

func (manager *Manager) IsPermissionRegistered(name string) bool

IsPermissionRegistered checks if a permission with the given name is registered.

func (*Manager) RegisterPermission

func (manager *Manager) RegisterPermission(permission *Permission)

RegisterPermission registers a new permission.

func (*Manager) RemoveGroup

func (manager *Manager) RemoveGroup(name string)

RemoveGroup removes a group with the given name from the manager.

func (*Manager) SetDefaultGroup

func (manager *Manager) SetDefaultGroup(group *Group)

SetDefaultGroup sets the default group of the manager.

type Permissible

type Permissible interface {
	HasPermission(string) bool
	RemovePermission(string)
	AddPermission(*Permission)
}

Permissible is an interface used to satisfy for permission holders.

type Permission

type Permission struct {
	// contains filtered or unexported fields
}

Permission is a struct with a name, a default level and children. Every child permission can in turn have its own child permissions.

func NewPermission

func NewPermission(name string, defaultLevel int) *Permission

NewPermission returns a new permission with the given name and default level.

func (*Permission) AddChild

func (permission *Permission) AddChild(child *Permission)

AddChild adds the given permission as child permission.

func (*Permission) GetChildren

func (permission *Permission) GetChildren() map[string]*Permission

GetChildren returns a name => permission child permission map of all children.

func (*Permission) GetDefaultLevel

func (permission *Permission) GetDefaultLevel() int

GetDefaultLevel returns the default level of required to be granted the permission.

func (*Permission) GetName

func (permission *Permission) GetName() string

GetName returns the name of the permission.

func (*Permission) HasChild

func (permission *Permission) HasChild(name string) bool

HasChild checks if the permission has a child with the given name.

func (*Permission) SetDefaultLevel

func (permission *Permission) SetDefaultLevel(level int)

SetDefaultLevel sets the default level of the the permission.

type PermissionLevel

type PermissionLevel byte

A Permission level is used to connect groups with permissions.

Jump to

Keyboard shortcuts

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