permissions

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAdminRole     = `account:admin`
	DefaultRole          = `general`
	AnonymousDefaultRole = `anonymous`
)

Variables

View Source
var (
	// CtxPermissionManagerObject reference to the permission manager
	CtxPermissionManagerObject = struct{ s string }{"permissionmanager"}
)
View Source
var (
	// ErrUndefinedRole if not found
	ErrUndefinedRole = errors.New(`undefined role`)
)

Functions

func WithManager

func WithManager(ctx context.Context, manager *Manager) context.Context

WithManager puts permission manager to context

Types

type DBRoleLoader

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

DBRoleLoader provides roles from database

func (*DBRoleLoader) ListRoles

func (l *DBRoleLoader) ListRoles(ctx context.Context) []rbac.Role

ListRoles returns all roles from database

type ExtData

type ExtData struct {
	ID          uint64 `json:"id"`
	Title       string `json:"title"`
	AccessLevel int    `json:"access_level"`
}

ExtData permission data

type Manager

type Manager struct {
	*rbac.Manager
}

Manager provides methods to control and cache permissions

func FromContext

func FromContext(ctx context.Context) *Manager

FromContext permission manager object

func NewManager

func NewManager(conn *gorm.DB, cacheLifetime time.Duration) *Manager

NewManager object to control roles

func NewTestManager

func NewTestManager(ctx context.Context) *Manager

NewTestManager with all permissions

func (*Manager) AsOneRole

func (mng *Manager) AsOneRole(ctx context.Context, isAdmin bool, filter func(context.Context, rbac.Role) bool, id ...uint64) (rbac.Role, error)

AsOneRole returns new role object from one or more IDs

func (*Manager) DefaultRole

func (mng *Manager) DefaultRole(ctx context.Context) rbac.Role

DefaultRole returns default role

func (*Manager) RoleByID

func (mng *Manager) RoleByID(ctx context.Context, id uint64) (rbac.Role, error)

RoleByID returns role by ID and reload data if necessary

Jump to

Keyboard shortcuts

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