Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Owner
- type Owners
- type PermissionInterface
- type Permissions
- func (p Permissions) Add(title string, description string, parentID int64) (int64, error)
- func (p Permissions) AddPath(path string, description []string) (int64, error)
- func (p Permissions) Assign(role RoleInterface, permission PermissionInterface) (int64, error)
- func (p Permissions) Children(id int64) ([]path, error)
- func (p Permissions) Count() (int64, error)
- func (p Permissions) Depth(id int64) (int64, error)
- func (p Permissions) Descendants(absolute bool, id int64) ([]path, error)
- func (p Permissions) Edit(id int64, title, description string) error
- func (p Permissions) GetDescription(id int64) (string, error)
- func (p Permissions) GetPath(id int64) (string, error)
- func (p Permissions) GetPermissionID(permission PermissionInterface) (int64, error)
- func (p Permissions) GetTitle(id int64) (string, error)
- func (p Permissions) ParentNode(id int64) (int64, error)
- func (p Permissions) Reset(ensure bool) error
- func (p Permissions) ResetAssignments(ensure bool) error
- func (p Permissions) ReturnID(entity string) (int64, error)
- func (p Permissions) TitleID(title string) (int64, error)
- func (p Permissions) Unassign(role RoleInterface, permission PermissionInterface) error
- type Rbac
- func (r *Rbac) AddOwnerExtension(name string, extension Owners) error
- func (r Rbac) Assign(role RoleInterface, permission PermissionInterface) (int64, error)
- func (r Rbac) Check(permission PermissionInterface, userID UserInterface) (bool, error)
- func (r *Rbac) DB() *sql.DB
- func (r *Rbac) OwnerExtension(name string) Owners
- func (r Rbac) Permissions() *Permissions
- func (r Rbac) Reset(ensure bool)
- func (r Rbac) Roles() *Roles
- func (r Rbac) Unassign(role RoleInterface, permission PermissionInterface) error
- func (r Rbac) Users() Owners
- type Role
- type RoleInterface
- type Roles
- func (r Roles) Add(title string, description string, parentID int64) (int64, error)
- func (r Roles) AddPath(path string, description []string) (int64, error)
- func (r Roles) Assign(role RoleInterface, permission PermissionInterface) (int64, error)
- func (r Roles) Children(id int64) ([]path, error)
- func (r Roles) Count() (int64, error)
- func (r Roles) Depth(id int64) (int64, error)
- func (r Roles) Descendants(absolute bool, id int64) ([]path, error)
- func (r Roles) Edit(id int64, title, description string) error
- func (r Roles) GetDescription(id int64) (string, error)
- func (r Roles) GetPath(id int64) (string, error)
- func (r Roles) GetRoleID(role RoleInterface) (int64, error)
- func (r Roles) GetTitle(id int64) (string, error)
- func (r Roles) HasPermission(role RoleInterface, permission PermissionInterface) (bool, error)
- func (r Roles) ParentNode(id int64) (int64, error)
- func (r Roles) Permissions(role RoleInterface) ([]permission, error)
- func (r Roles) Remove(role RoleInterface, recursive bool) error
- func (r Roles) Reset(ensure bool) error
- func (r Roles) ResetAssignments(ensure bool) error
- func (r Roles) ReturnID(entity string) (int64, error)
- func (r Roles) TitleID(title string) (int64, error)
- func (r Roles) Unassign(role RoleInterface, permission PermissionInterface) error
- func (r Roles) UnassignPermissions(role RoleInterface) error
- func (r Roles) UnassignUsers(role RoleInterface) error
- type UserInterface
- type Users
- func (u Users) AllRoles(userID Owner, _ interface{}) ([]Role, error)
- func (u Users) Assign(role RoleInterface, userID Owner, _ interface{}) (int64, error)
- func (u Users) HasRole(role RoleInterface, userID Owner) (bool, error)
- func (u Users) ResetAssignments(ensure bool) error
- func (u Users) RoleCount(userID Owner) (int64, error)
- func (u Users) Table() string
- func (u Users) Unassign(role RoleInterface, userID Owner) error
Constants ¶
const ( Left string = "lft" Right = "rght" )
Left column name in sql scheme Right column name in sql scheme
Variables ¶
var ( ErrTitleNotFound = errors.New("title not found") ErrPathNotFound = errors.New("path not found") )
Error messages for a invalid title name.
var (
ErrPermissionNotFound = errors.New("permission not found")
)
var (
ErrRowRequired = errors.New("role cannot be nil")
)
Error messages for Roles
var ErrUserRequired = errors.New("user id is a required argument")
Functions ¶
This section is empty.
Types ¶
type Owners ¶
type Owners interface { Assign(role RoleInterface, owner Owner, meta interface{}) (int64, error) HasRole(role RoleInterface, owner Owner) (bool, error) Unassign(role RoleInterface, owner Owner) error AllRoles(owner Owner, meta interface{}) ([]Role, error) RoleCount(owner Owner) (int64, error) ResetAssignments(ensure bool) error Table() string }
type Permissions ¶
type Permissions struct {
// contains filtered or unexported fields
}
func (Permissions) AddPath ¶
func (p Permissions) AddPath(path string, description []string) (int64, error)
func (Permissions) Assign ¶
func (p Permissions) Assign(role RoleInterface, permission PermissionInterface) (int64, error)
func (Permissions) Children ¶
func (p Permissions) Children(id int64) ([]path, error)
func (Permissions) Count ¶
func (p Permissions) Count() (int64, error)
func (Permissions) Descendants ¶
func (p Permissions) Descendants(absolute bool, id int64) ([]path, error)
func (Permissions) GetDescription ¶
func (p Permissions) GetDescription(id int64) (string, error)
func (Permissions) GetPermissionID ¶
func (p Permissions) GetPermissionID(permission PermissionInterface) (int64, error)
func (Permissions) ParentNode ¶
func (p Permissions) ParentNode(id int64) (int64, error)
func (Permissions) Reset ¶
func (p Permissions) Reset(ensure bool) error
func (Permissions) ResetAssignments ¶
func (p Permissions) ResetAssignments(ensure bool) error
func (Permissions) Unassign ¶
func (p Permissions) Unassign(role RoleInterface, permission PermissionInterface) error
type Rbac ¶
type Rbac struct {
// contains filtered or unexported fields
}
func (*Rbac) AddOwnerExtension ¶
func (Rbac) Assign ¶
func (r Rbac) Assign(role RoleInterface, permission PermissionInterface) (int64, error)
Assign a role to a permission. Returns true if successful, false if unsuccessful.
func (Rbac) Check ¶
func (r Rbac) Check(permission PermissionInterface, userID UserInterface) (bool, error)
Check whether a user has a permission or not. Returns true if a user has a permission, false if otherwise.
func (*Rbac) OwnerExtension ¶
func (Rbac) Permissions ¶
func (r Rbac) Permissions() *Permissions
Permissions exposes underlaying permissions struct
func (Rbac) Reset ¶
Reset all roles, permissions and assignments. Ensure is a required boolean parameter. If true is not passed an fatal will be thrown.
func (Rbac) Unassign ¶
func (r Rbac) Unassign(role RoleInterface, permission PermissionInterface) error
Unassign a Role-Permission relation.
type Roles ¶
type Roles struct {
// contains filtered or unexported fields
}
func (Roles) Assign ¶
func (r Roles) Assign(role RoleInterface, permission PermissionInterface) (int64, error)
Assign a role to a permission (or vice-verse). Returns true if successful, false if association already exists.
func (Roles) Descendants ¶
Descendants returns descendants of an Entity, with their depths in integer.
func (Roles) HasPermission ¶
func (r Roles) HasPermission(role RoleInterface, permission PermissionInterface) (bool, error)
HasPermission checks to see if a Role has a Permission or not.
func (Roles) Permissions ¶
func (r Roles) Permissions(role RoleInterface) ([]permission, error)
func (Roles) Remove ¶
func (r Roles) Remove(role RoleInterface, recursive bool) error
Remove Roles from system. If set to true, all descendants of the Permission will also be removed.
func (Roles) ResetAssignments ¶
func (Roles) Unassign ¶
func (r Roles) Unassign(role RoleInterface, permission PermissionInterface) error
Unassign a Role-Permission relation.
func (Roles) UnassignPermissions ¶
func (r Roles) UnassignPermissions(role RoleInterface) error
func (Roles) UnassignUsers ¶
func (r Roles) UnassignUsers(role RoleInterface) error
type Users ¶
type Users struct {
// contains filtered or unexported fields
}
func (Users) Assign ¶
func (u Users) Assign(role RoleInterface, userID Owner, _ interface{}) (int64, error)
Assigns a role to a user
func (Users) HasRole ¶
func (u Users) HasRole(role RoleInterface, userID Owner) (bool, error)
Checks to see whether a UserInterface has a Role or not.