casbin

package
v0.0.0-...-742f5fa Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDataScope 默认数据权限范围
	DefaultDataScope = "own"
)

Variables

This section is empty.

Functions

func AddPermissionForRole

func AddPermissionForRole(e *casbin.Enforcer, roleName, resource, action string) error

AddPermissionForRole 为角色添加权限

func AddRoleForUser

func AddRoleForUser(e *casbin.Enforcer, userID string, roleName string) error

AddRoleForUser 为用户分配角色

func CheckPermission

func CheckPermission(e *casbin.Enforcer, userID, resource, action string) (bool, error)

CheckPermission 检查用户是否有权限

func DeletePermissionForRole

func DeletePermissionForRole(e *casbin.Enforcer, roleName, resource, action string) error

DeletePermissionForRole 删除角色的权限

func DeletePermissionsForRole

func DeletePermissionsForRole(e *casbin.Enforcer, roleName string) error

DeletePermissionsForRole 删除角色的所有权限

func DeleteRoleForUser

func DeleteRoleForUser(e *casbin.Enforcer, userID string, roleName string) error

DeleteRoleForUser 删除用户的角色

func DeleteRolesForUser

func DeleteRolesForUser(e *casbin.Enforcer, userID string) error

DeleteRolesForUser 删除用户的所有角色

func GetImplicitPermissionsForUser

func GetImplicitPermissionsForUser(e *casbin.Enforcer, userID string) ([][]string, error)

GetImplicitPermissionsForUser 获取用户的所有权限(包括从角色继承的)

func GetPermissionKeysForUser

func GetPermissionKeysForUser(e *casbin.Enforcer, userID string) ([]string, error)

GetPermissionKeysForUser 获取用户的权限键列表(格式: resource:action)

func GetPermissionsForRole

func GetPermissionsForRole(e *casbin.Enforcer, roleName string) ([][]string, error)

GetPermissionsForRole 获取角色的所有权限

func GetRoleDataScope

func GetRoleDataScope(e *casbin.Enforcer, roleName string) (string, error)

GetRoleDataScope 获取角色的数据范围

func GetRolesForUser

func GetRolesForUser(e *casbin.Enforcer, userID string) ([]string, error)

GetRolesForUser 获取用户的所有角色

func GetUserDataScope

func GetUserDataScope(e *casbin.Enforcer, userID string) (string, error)

GetUserDataScope 获取用户的数据范围(取所有角色中权限最高的)

func GetUsersForRole

func GetUsersForRole(e *casbin.Enforcer, roleName string) ([]string, error)

GetUsersForRole 获取拥有某个角色的所有用户

func NewEnforcer

func NewEnforcer(modelPath string, db *gorm.DB) (*casbin.Enforcer, error)

NewEnforcer 创建并初始化 Casbin enforcer modelPath: RBAC 模型配置文件路径(如 "config/rbac_model.conf") db: GORM 数据库实例

func SetRoleDataScope

func SetRoleDataScope(e *casbin.Enforcer, roleName, dataScope string) error

SetRoleDataScope 设置角色的数据范围 dataScope 可选值: "all", "own", "dept", "custom"

Types

This section is empty.

Jump to

Keyboard shortcuts

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