casbin结构修改为三方包内部结构,避免升级冲突。

This commit is contained in:
piexlmax
2022-02-21 14:07:32 +08:00
parent 343d3aaaf2
commit 4cee98bcce
4 changed files with 3 additions and 19 deletions

View File

@@ -7,7 +7,6 @@ import (
"github.com/casbin/casbin/v2"
gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
_ "github.com/go-sql-driver/mysql"
)
@@ -26,13 +25,7 @@ func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos
casbinService.ClearCasbin(0, authorityId)
rules := [][]string{}
for _, v := range casbinInfos {
cm := system.CasbinModel{
Ptype: "p",
AuthorityId: authorityId,
Path: v.Path,
Method: v.Method,
}
rules = append(rules, []string{cm.AuthorityId, cm.Path, cm.Method})
rules = append(rules, []string{authorityId, v.Path, v.Method})
}
e := casbinService.Casbin()
success, _ := e.AddPolicies(rules)
@@ -49,7 +42,7 @@ func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos
//@return: error
func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
err := global.GVA_DB.Table("casbin_rule").Model(&system.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{
err := global.GVA_DB.Model(&gormadapter.CasbinRule{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{
"v1": newPath,
"v2": newMethod,
}).Error