From b4b45e106074ac2bad7ff93105c479a77bed4de4 Mon Sep 17 00:00:00 2001 From: rainyan Date: Mon, 13 Apr 2020 10:48:14 +0800 Subject: [PATCH 1/3] update README.md You can see sample APIs in user management module. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9031d6c2..5be9405e 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ go run main.go; - Configuration management: The configuration file can be modified in the web page (the test environment does not provide this function). - Rich text editor: Embed MarkDown editor function. - Conditional search: Add an example of conditional search. -- Restful example: refer to customer management function and apidcustomer group. +- Restful example: You can see sample APIs in user management module. ``` fontend code file: src\view\superAdmin\api\api.vue From b51e7529759bca2c69cf0f075f31d715902c8ea1 Mon Sep 17 00:00:00 2001 From: rainyan Date: Mon, 13 Apr 2020 10:51:22 +0800 Subject: [PATCH 2/3] Update README-zh_CN.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 可以参考用户管理模块中的示例API。 --- README-zh_CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-zh_CN.md b/README-zh_CN.md index 518d3edc..68a0bb3c 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -180,7 +180,7 @@ go run main.go; - 配置管理:配置文件可前台修改(测试环境不开放此功能)。 - 富文本编辑器:MarkDown编辑器功能嵌入。 - 条件搜索:增加条件搜索示例。 -- restful示例:参考客户管理功能,customer组api。 +- restful示例:可以参考用户管理模块中的示例API。 ``` 前端文件参考: src\view\superAdmin\api\api.vue 后台文件参考: model\dnModel\api.go From 6dd70d2a7604797c7596db65e05d79f58fddf753 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Mon, 13 Apr 2020 17:45:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86api=E5=94=AF?= =?UTF-8?q?=E4=B8=80key=E5=85=B3=E8=81=94=E7=9A=84bug=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=E8=A7=92=E8=89=B2=E5=88=A0=E9=99=A4=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_authority.go | 2 +- server/model/response/sys_casbin.go | 2 +- server/service/sys_authority.go | 2 +- server/service/sys_casbin.go | 22 ++++++++++--------- .../superAdmin/authority/components/apis.vue | 10 ++++++--- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/server/api/v1/sys_authority.go b/server/api/v1/sys_authority.go index 690d3a7d..48a845ad 100644 --- a/server/api/v1/sys_authority.go +++ b/server/api/v1/sys_authority.go @@ -41,7 +41,7 @@ func DeleteAuthority(c *gin.Context) { var a model.SysAuthority _ = c.ShouldBindJSON(&a) //删除角色之前需要判断是否有用户正在使用此角色 - err := service.DeleteAuthority(a) + err := service.DeleteAuthority(&a) if err != nil { response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c) } else { diff --git a/server/model/response/sys_casbin.go b/server/model/response/sys_casbin.go index 3f41c164..a1be69ab 100644 --- a/server/model/response/sys_casbin.go +++ b/server/model/response/sys_casbin.go @@ -1,5 +1,5 @@ package response type PolicyPathResponse struct { - Paths []string `json:"paths"` + Paths []map[string]string `json:"paths"` } diff --git a/server/service/sys_authority.go b/server/service/sys_authority.go index 6f8dab4b..39788fea 100644 --- a/server/service/sys_authority.go +++ b/server/service/sys_authority.go @@ -24,7 +24,7 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut // @param auth model.SysAuthority // @return error // 删除角色 -func DeleteAuthority(auth model.SysAuthority) (err error) { +func DeleteAuthority(auth *model.SysAuthority) (err error) { err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).Find(&model.SysUser{}).Error if err == nil { err = errors.New("此角色有用户正在使用禁止删除") diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index b9e8f528..29b1e26f 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -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 -} \ No newline at end of file +} diff --git a/web/src/view/superAdmin/authority/components/apis.vue b/web/src/view/superAdmin/authority/components/apis.vue index 7b62e953..bb56046d 100644 --- a/web/src/view/superAdmin/authority/components/apis.vue +++ b/web/src/view/superAdmin/authority/components/apis.vue @@ -9,7 +9,7 @@ :props="apiDefaultProps" default-expand-all highlight-current - node-key="path" + node-key="onlyId" ref="apiTree" show-checkbox > @@ -44,6 +44,7 @@ export default { const apiObj = new Object() apis && apis.map(item => { + item.onlyId = "p:"+item.path+"m:"+item.method if (apiObj.hasOwnProperty(item.apiGroup)) { apiObj[item.apiGroup].push(item) } else { @@ -85,13 +86,16 @@ export default { // 获取api并整理成树结构 const res2 = await getAllApis() const apis = res2.data.apis + this.apiTreeData = this.buildApiTree(apis) - const res = await getPolicyPathByAuthorityId({ authorityId: this.row.authorityId }) this.activeUserId = this.row.authorityId - this.apiTreeIds = res.data.paths || [] + this.apiTreeIds = [] + res.data.paths&&res.data.paths.map(item=>{ + this.apiTreeIds.push("p:"+item.path+"m:"+item.method) + }) } }