role

package
v0.0.0-...-3839eb7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPermissionNotFound = errors.New("permission not found")
	ErrRoleNotFound       = errors.New("role not found")
	ErrHasNoPermission    = errors.New("role has not specified permission")
)

Functions

This section is empty.

Types

type GormResolver

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

func NewGormResolver

func NewGormResolver(db *gorm.DB) GormResolver

func (GormResolver) AddRolePerm

func (g GormResolver) AddRolePerm(roleId uint, permId uint) error

func (GormResolver) CreatePerm

func (g GormResolver) CreatePerm(permInfo role.PermInfo) error

func (GormResolver) CreatePermInBatch

func (g GormResolver) CreatePermInBatch(perms []role.PermInfo) error

func (GormResolver) CreateRole

func (g GormResolver) CreateRole(roleInfo role.RoleInfo) error

func (GormResolver) CreateRoleInBatch

func (g GormResolver) CreateRoleInBatch(roles []role.RoleInfo) error

func (GormResolver) CreateRolePermBatch

func (g GormResolver) CreateRolePermBatch(roleInfo role.RoleInfo, perms []role.PermInfo) error

func (GormResolver) GetPerm

func (g GormResolver) GetPerm(permId uint) (role.PermInfo, error)

func (GormResolver) GetPermInBatch

func (g GormResolver) GetPermInBatch(ids []uint, tag string) ([]role.PermInfo, error)

func (GormResolver) GetRole

func (g GormResolver) GetRole(roleId uint) (role.RoleInfo, error)

func (GormResolver) GetRoleByCode

func (g GormResolver) GetRoleByCode(code string) (role.RoleInfo, error)

func (GormResolver) GetRoleInBatch

func (g GormResolver) GetRoleInBatch(roleIds []uint) ([]role.RoleInfo, error)

func (GormResolver) ListAllPerms

func (g GormResolver) ListAllPerms(tag string) ([]role.PermInfo, error)

func (GormResolver) ListAllRole

func (g GormResolver) ListAllRole() ([]role.RoleInfo, error)

func (GormResolver) ListPerms

func (g GormResolver) ListPerms(option role.PageOption) ([]role.PermInfo, error)

func (GormResolver) ListRole

func (g GormResolver) ListRole(option role.PageOption) ([]role.RoleInfo, error)

func (GormResolver) ListRolePerms

func (g GormResolver) ListRolePerms(roleId uint) ([]role.PermGroup, error)

func (GormResolver) MatchPerm

func (g GormResolver) MatchPerm(name, obj, act, group, tag string) (role.PermInfo, error)

func (GormResolver) RemovePerm

func (g GormResolver) RemovePerm(permId uint) error

func (GormResolver) RemoveRole

func (g GormResolver) RemoveRole(roleId uint) error

func (GormResolver) RemoveRolePerm

func (g GormResolver) RemoveRolePerm(roleId uint, permId uint) error

func (GormResolver) ResolveAny

func (g GormResolver) ResolveAny(permObj string, permAct string, roles ...string) error

func (GormResolver) UpdatePerm

func (g GormResolver) UpdatePerm(permInfo role.PermInfo) error

func (GormResolver) UpdateRole

func (g GormResolver) UpdateRole(roleInfo role.RoleInfo) error

func (GormResolver) UpdateRolePermBatch

func (g GormResolver) UpdateRolePermBatch(roleId uint, tag string, newPermIds []uint) error

type Resolver

type Resolver interface {
	GetPerm(permId uint) (role.PermInfo, error)
	GetPermInBatch(permIds []uint, tag string) ([]role.PermInfo, error)
	MatchPerm(name, obj, act, group, tag string) (role.PermInfo, error)
	CreatePerm(permInfo role.PermInfo) error
	CreatePermInBatch(permInfo []role.PermInfo) error
	ListPerms(option role.PageOption) ([]role.PermInfo, error)
	ListAllPerms(tag string) ([]role.PermInfo, error)
	UpdatePerm(permInfo role.PermInfo) error
	RemovePerm(permId uint) error

	GetRole(roleId uint) (role.RoleInfo, error)
	GetRoleInBatch(roleIds []uint) ([]role.RoleInfo, error)
	GetRoleByCode(code string) (role.RoleInfo, error)
	ListRole(option role.PageOption) ([]role.RoleInfo, error)
	ListAllRole() ([]role.RoleInfo, error)
	CreateRole(roleInfo role.RoleInfo) error
	CreateRoleInBatch(roleInfo []role.RoleInfo) error
	UpdateRole(roleInfo role.RoleInfo) error
	RemoveRole(roleId uint) error

	// ListRolePerms list all permissions belonging to specified role
	ListRolePerms(roleId uint) ([]role.PermGroup, error)
	// AddRolePerm add new permission to specified role
	AddRolePerm(roleId uint, permId uint) error
	// RemoveRolePerm remove specified permission from specified role
	RemoveRolePerm(roleId uint, permId uint) error
	// UpdateRolePermBatch update specified role permissions in batch
	// it will add and remove some permissions to make the records sync with the incoming permIds
	// if there are some permissions not in permission record which is result of ListAllPerms, it will return error
	UpdateRolePermBatch(roleId uint, tag string, permIds []uint) error
	CreateRolePermBatch(roles role.RoleInfo, perms []role.PermInfo) error

	// ResolveAny judge specified role if any role is able to access permObj by the way of permAct
	ResolveAny(permObj string, permAct string, roles ...string) error
}

Jump to

Keyboard shortcuts

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