From 474e07b86316a4ace3e736e06fb072ab383860a9 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Thu, 9 Apr 2020 11:49:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=BE=91=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=80=BB=E8=BE=91=EF=BC=8C=E5=89=8D=E7=AB=AF=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/sys_api.go | 16 ++++--- server/service/sys_casbin.go | 8 ++-- web/src/view/superAdmin/api/api.vue | 43 ++++++++++++------- .../view/superAdmin/authority/authority.vue | 3 +- web/src/view/superAdmin/menu/menu.vue | 5 ++- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/server/service/sys_api.go b/server/service/sys_api.go index b704508c..6d0a8726 100644 --- a/server/service/sys_api.go +++ b/server/service/sys_api.go @@ -30,7 +30,7 @@ func CreateApi(a model.SysApi) (err error) { // @return error func DeleteApi(a model.SysApi) (err error) { err = global.GVA_DB.Delete(a).Error - ClearCasbin(1, a.Path) + ClearCasbin(1, a.Path,a.Method) return err } @@ -111,15 +111,19 @@ func GetApiById(id float64) (err error, api model.SysApi) { // @return error func UpdateApi(a model.SysApi) (err error) { var oldA model.SysApi - flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound() - if !flag { - return errors.New("存在相同api路径") - } + err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error + + if oldA.Path != a.Path || oldA.Method != a.Method{ + flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound() + if !flag { + return errors.New("存在相同api路径") + } + } if err != nil { return err } else { - err = UpdateCasbinApi(oldA.Path, a.Path) + err = UpdateCasbinApi(oldA.Path, a.Path,oldA.Method,a.Method) if err != nil { return err } else { diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index a85bb580..678ded16 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -51,9 +51,9 @@ func AddCasbin(cm model.CasbinModel) bool { // @param oldPath string // @param newPath string // @return error -func UpdateCasbinApi(oldPath string, newPath 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 = ?", oldPath).Find(&cs).Update("v1", newPath).Error + err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Update("v1", newPath).Update("v2", newMethod).Error return err } @@ -78,9 +78,9 @@ 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) + return e.RemoveFilteredPolicy(v, p...) } diff --git a/web/src/view/superAdmin/api/api.vue b/web/src/view/superAdmin/api/api.vue index 756ee3c8..6925a37d 100644 --- a/web/src/view/superAdmin/api/api.vue +++ b/web/src/view/superAdmin/api/api.vue @@ -8,8 +8,8 @@ - - + + - - - - - - + + + + + +