adsa-cms: github.com/mmanjoura/adsa-cms/roles Index | Files

package roles

import "github.com/mmanjoura/adsa-cms/roles"

Index

Package Files

permission.go role.go

Constants

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

Variables

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

ErrPermissionDenied no permission error

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 func(request *http.Request, user interface{}) bool)

Register register role with conditions

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 ...string) 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 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) (func(req *http.Request, currentUser interface{}) bool, bool)

Get role defination

func (*Role) MatchedRoles Uses

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

MatchedRoles return defined roles from user

func (*Role) Register Uses

func (role *Role) Register(name string, fc func(req *http.Request, currentUser interface{}) bool)

Register register role with conditions

Package roles imports 3 packages (graph) and is imported by 13 packages. Updated 2017-06-08. Refresh now. Tools for package owners.