roles: github.com/qor/roles Index | Files

package roles

import "github.com/qor/roles"

Index

Package Files

global.go permission.go permissioner.go role.go role_manager.go

Constants

const (
    // Anyone is a role for any one
    Anyone = "*"
)

Variables

var ErrPermissionDenied = errors.New("permission denied")

ErrPermissionDenied no permission error

var Global = &Role{}

Global global role instance

func HasRole Uses

func HasRole(req *http.Request, user interface{}, roles ...string) bool

HasRole check if current user has role

func MatchedRoles Uses

func MatchedRoles(req *http.Request, user interface{}) []string

MatchedRoles return defined roles from user

func Register Uses

func Register(name string, fc Checker)

Register register role with conditions

func Remove Uses

func Remove(name string)

Remove role definition from global role instance

func Reset Uses

func Reset()

Reset role definitions from global role instance

type Checker Uses

type Checker func(req *http.Request, user interface{}) bool

Checker check current request match this role or not

func Get Uses

func Get(name string) (Checker, bool)

Get role defination

type Permission Uses

type Permission struct {
    Role         *Role
    AllowedRoles map[PermissionMode][]string
    DeniedRoles  map[PermissionMode][]string
}

Permission a struct contains permission definitions

func Allow Uses

func Allow(mode PermissionMode, roles ...string) *Permission

Allow allows permission mode for roles

func Deny Uses

func Deny(mode PermissionMode, roles ...string) *Permission

Deny deny permission mode for roles

func NewPermission Uses

func NewPermission() *Permission

NewPermission initialize a new permission for default role

func (*Permission) Allow Uses

func (permission *Permission) Allow(mode PermissionMode, roles ...string) *Permission

Allow allows permission mode for roles

func (*Permission) Concat Uses

func (permission *Permission) Concat(newPermission *Permission) *Permission

Concat concat two permissions into a new one

func (*Permission) Deny Uses

func (permission *Permission) Deny(mode PermissionMode, roles ...string) *Permission

Deny deny permission mode for roles

func (Permission) HasPermission Uses

func (permission Permission) HasPermission(mode PermissionMode, roles ...interface{}) bool

HasPermission check roles has permission for mode or not

type PermissionMode Uses

type PermissionMode string

PermissionMode permission mode

const (
    // Create predefined permission mode, create permission
    Create PermissionMode = "create"
    // Read predefined permission mode, read permission
    Read PermissionMode = "read"
    // Update predefined permission mode, update permission
    Update PermissionMode = "update"
    // Delete predefined permission mode, deleted permission
    Delete PermissionMode = "delete"
    // CRUD predefined permission mode, create+read+update+delete permission
    CRUD PermissionMode = "crud"
)

type Permissioner Uses

type Permissioner interface {
    HasPermission(mode PermissionMode, roles ...interface{}) bool
}

Permissioner permissioner interface

func ConcatPermissioner Uses

func ConcatPermissioner(ps ...Permissioner) Permissioner

ConcatPermissioner concat permissioner

type Role Uses

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

Role is a struct contains all roles definitions

func New Uses

func New() *Role

New initialize a new `Role`

func (*Role) Allow Uses

func (role *Role) Allow(mode PermissionMode, roles ...string) *Permission

Allow allows permission mode for roles

func (*Role) Deny Uses

func (role *Role) Deny(mode PermissionMode, roles ...string) *Permission

Deny deny permission mode for roles

func (*Role) Get Uses

func (role *Role) Get(name string) (Checker, bool)

Get role defination

func (*Role) HasRole Uses

func (role *Role) HasRole(req *http.Request, user interface{}, roles ...string) bool

HasRole check if current user has role

func (*Role) MatchedRoles Uses

func (role *Role) MatchedRoles(req *http.Request, user interface{}) (roles []string)

MatchedRoles return defined roles from user

func (*Role) NewPermission Uses

func (role *Role) NewPermission() *Permission

NewPermission initialize permission

func (*Role) Register Uses

func (role *Role) Register(name string, fc Checker)

Register register role with conditions

func (*Role) Remove Uses

func (role *Role) Remove(name string)

Remove role definition

func (*Role) Reset Uses

func (role *Role) Reset()

Reset role definitions

type Roler Uses

type Roler interface {
    GetRoles() []string
}

Roler Roler interface

Package roles imports 3 packages (graph) and is imported by 57 packages. Updated 2017-12-02. Refresh now. Tools for package owners.