增加角色复制后台功能 修复swagger不能带token的问题
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
"gin-vue-admin/model/response"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// @title CreateAuthority
|
||||
@@ -19,6 +21,33 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
|
||||
return err, auth
|
||||
}
|
||||
|
||||
// @title CopyAuthority
|
||||
// @description 复制一个角色
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param copyInfo response.SysAuthorityCopyResponse
|
||||
// @return error
|
||||
// @return authority model.SysAuthority
|
||||
|
||||
func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority model.SysAuthority) {
|
||||
copyInfo.Authority.Children = []model.SysAuthority{}
|
||||
err, menus := GetMenuAuthority(copyInfo.OldAuthorityId)
|
||||
var baseMenu []model.SysBaseMenu
|
||||
for _, v := range menus {
|
||||
intNum, _ := strconv.Atoi(v.MenuId)
|
||||
v.SysBaseMenu.ID = uint(intNum)
|
||||
baseMenu = append(baseMenu, v.SysBaseMenu)
|
||||
}
|
||||
copyInfo.Authority.SysBaseMenus = baseMenu
|
||||
err = global.GVA_DB.Create(©Info.Authority).Error
|
||||
|
||||
paths := GetPolicyPathByAuthorityId(copyInfo.OldAuthorityId)
|
||||
err = UpdateCasbin(copyInfo.Authority.AuthorityId, paths)
|
||||
if err != nil {
|
||||
_ = DeleteAuthority(©Info.Authority)
|
||||
}
|
||||
return err, copyInfo.Authority
|
||||
}
|
||||
|
||||
// @title UpdateAuthority
|
||||
// @description 更改一个角色
|
||||
// @auth (2020/04/05 20:22)
|
||||
|
||||
@@ -71,13 +71,13 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod
|
||||
// @param authorityId string
|
||||
// @return []string
|
||||
|
||||
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []map[string]string) {
|
||||
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
|
||||
e := Casbin()
|
||||
list := e.GetFilteredPolicy(0, authorityId)
|
||||
for _, v := range list {
|
||||
pathMaps = append(pathMaps, map[string]string{
|
||||
"path": v[1],
|
||||
"method": v[2],
|
||||
pathMaps = append(pathMaps, request.CasbinInfo{
|
||||
Path: v[1],
|
||||
Method: v[2],
|
||||
})
|
||||
}
|
||||
return pathMaps
|
||||
|
||||
Reference in New Issue
Block a user