修复了api唯一key关联的bug,修复了角色删除失败的bug

This commit is contained in:
pixel
2020-04-13 17:45:33 +08:00
parent 959aa9cd38
commit f68947d50e
5 changed files with 22 additions and 16 deletions

View File

@@ -17,7 +17,7 @@ import (
// @param authorityId string
// @param casbinInfos []CasbinInfo
// @return error
func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
ClearCasbin(0, authorityId)
for _, v := range casbinInfos {
cm := model.CasbinModel{
@@ -40,7 +40,7 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
// @auth 2020/04/05 20:22
// @param cm model.CasbinModel
// @return bool
func AddCasbin(cm model.CasbinModel) bool {
func AddCasbin(cm model.CasbinModel) bool {
e := Casbin()
return e.AddPolicy(cm.AuthorityId, cm.Path, cm.Method)
}
@@ -53,9 +53,9 @@ func AddCasbin(cm model.CasbinModel) bool {
// @param oldMethod string
// @param newMethod string
// @return error
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
var cs []model.CasbinModel
err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Updates(map[string]string{
err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Find(&cs).Updates(map[string]string{
"v1": newPath,
"v2": newMethod,
}).Error
@@ -67,14 +67,16 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMetho
// @auth 2020/04/05 20:22
// @param authorityId string
// @return []string
func GetPolicyPathByAuthorityId(authorityId string) []string {
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []map[string]string) {
e := Casbin()
var pathList []string
list := e.GetFilteredPolicy(0, authorityId)
for _, v := range list {
pathList = append(pathList, v[1])
pathMaps = append(pathMaps, map[string]string{
"path": v[1],
"method": v[2],
})
}
return pathList
return pathMaps
}
// @title ClearCasbin
@@ -83,7 +85,7 @@ func GetPolicyPathByAuthorityId(authorityId string) []string {
// @param v int
// @param p string
// @return bool
func ClearCasbin(v int, p ...string) bool {
func ClearCasbin(v int, p ...string) bool {
e := Casbin()
return e.RemoveFilteredPolicy(v, p...)
@@ -123,4 +125,4 @@ func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
name2 := args[1].(string)
return (bool)(ParamsMatch(name1, name2)), nil
}
}