refactor🎨: 优化角色修改时循环AddNamedPolicy

This commit is contained in:
wenjianzhang committed 2021-08-19 19:04:03 +08:00
1 parent 2441412714
commit 386c620b48
1 file changed
+11 -2
+11 -2
View File
@@ -142,12 +142,21 @@ func (e *SysRole) Update(c *dto.SysRoleUpdateReq, cb *casbin.SyncedEnforcer) err
e.Log.Errorf("delete policy error:%s", err)
return err
}
mp:=make(map [string] interface{} ,0)
polices := make([][]string, 0)
for _, menu := range mlist {
for _, api := range menu.SysApi {
_, err = cb.AddNamedPolicy("p", model.RoleKey, api.Path, api.Action)
if mp[model.RoleKey+"-"+api.Path+"-"+api.Action] != "" {
mp[model.RoleKey+"-"+api.Path+"-"+api.Action] = ""
//_, err = cb.AddNamedPolicy("p", model.RoleKey, api.Path, api.Action)
polices = append(polices, []string{model.RoleKey, api.Path, api.Action})
}
}
}
_, err = cb.AddNamedPolicies("p", polices)
if err != nil {
return err
}
_ = cb.SavePolicy()
return nil
}