- 角色管理初版

This commit is contained in:
gazebo
2019-08-07 18:16:44 +08:00
parent 059be1befd
commit 3639a1c7cb
14 changed files with 500 additions and 72 deletions

View File

@@ -2,6 +2,7 @@ package casbinauth
import (
"git.rosy.net.cn/jx-callback/business/authz"
"git.rosy.net.cn/jx-callback/globals"
"github.com/casbin/casbin"
)
@@ -15,30 +16,30 @@ func New(modelFile string) (authObj authz.IAuthz, err error) {
return obj, err
}
func (c *CasbinAuthz) AddStoreRole4User(userID string, storeID int) (err error) {
return c.AddRole4User(userID, authz.GenStoreRoleName(storeID))
}
func (c *CasbinAuthz) DelStoreRole4User(userID string, storeID int) (err error) {
return c.DelRole4User(userID, authz.GenStoreRoleName(storeID))
}
func (c *CasbinAuthz) AddRole4User(userID, roleName string) (err error) {
_, err = c.enforcer.AddRoleForUser(userID, roleName)
func (c *CasbinAuthz) AddRole4User(userID string, r *authz.RoleInfo) (err error) {
_, err = c.enforcer.AddRoleForUser(userID, r.GetFullName())
return err
}
func (c *CasbinAuthz) DelRole4User(userID, roleName string) (err error) {
_, err = c.enforcer.DeleteRoleForUser(userID, roleName)
func (c *CasbinAuthz) DeleteRole4User(userID string, r *authz.RoleInfo) (err error) {
_, err = c.enforcer.DeleteRoleForUser(userID, r.GetFullName())
return err
}
func (c *CasbinAuthz) GetUserRoleList(userID string) (roleList []string, err error) {
roleList, err = c.enforcer.GetRolesForUser(userID)
func (c *CasbinAuthz) GetUserRoleList(userID string) (roleList []*authz.RoleInfo, err error) {
roleNameList, err := c.enforcer.GetRolesForUser(userID)
if err == nil && len(roleNameList) > 0 {
roleList = authz.FullRoleName2RoleList(roleNameList)
}
return roleList, err
}
func (c *CasbinAuthz) GetRoleUserList(roleName string) (userIDList []string, err error) {
userIDList, err = c.enforcer.GetUsersForRole(roleName)
func (c *CasbinAuthz) GetRoleUserList(r *authz.RoleInfo) (userIDList []string, err error) {
globals.SugarLogger.Debug(r.GetFullName())
userIDList, err = c.enforcer.GetUsersForRole(r.GetFullName())
return userIDList, err
}
// func (c *CasbinAuthz) GetAllRoleList() (roleList []*authz.RoleInfo) {
// return authz.FullRoleName2RoleList(c.enforcer.GetAllRoles())
// }