From cfddbc51e83576c2c9e2370a532cfe7f839d9156 Mon Sep 17 00:00:00 2001 From: QM303176530 <303176530@qq.com> Date: Sat, 19 Sep 2020 23:19:18 +0800 Subject: [PATCH] =?UTF-8?q?casbin=E4=BF=AE=E6=94=B9=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/sys_casbin.go | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index 19c7721d..602594de 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -21,6 +21,7 @@ import ( func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { ClearCasbin(0, authorityId) + rules := [][]string{} for _, v := range casbinInfos { cm := model.CasbinModel{ Ptype: "p", @@ -28,24 +29,14 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { Path: v.Path, Method: v.Method, } - addflag := AddCasbin(cm) - if addflag == false { - return errors.New("存在相同api,添加失败,请联系管理员") - } + rules = append(rules, []string{cm.AuthorityId, cm.Path, cm.Method}) } - return nil -} - -// @title AddCasbin -// @description add casbin authority, 添加权限 -// @auth (2020/04/05 20:22) -// @param cm model.CasbinModel -// @return bool - -func AddCasbin(cm model.CasbinModel) bool { e := Casbin() - success, _ := e.AddPolicy(cm.AuthorityId, cm.Path, cm.Method) - return success + success, _ := e.AddPolicies(rules) + if success == false { + return errors.New("存在相同api,添加失败,请联系管理员") + } + return nil } // @title UpdateCasbinApi