Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nizhengjia888
gin-vue-admin
提交
6dd70d2a
G
gin-vue-admin
项目概览
nizhengjia888
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6dd70d2a
编写于
4月 13, 2020
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复了api唯一key关联的bug,修复了角色删除失败的bug
上级
0cc15b5d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
22 addition
and
16 deletion
+22
-16
server/api/v1/sys_authority.go
server/api/v1/sys_authority.go
+1
-1
server/model/response/sys_casbin.go
server/model/response/sys_casbin.go
+1
-1
server/service/sys_authority.go
server/service/sys_authority.go
+1
-1
server/service/sys_casbin.go
server/service/sys_casbin.go
+12
-10
web/src/view/superAdmin/authority/components/apis.vue
web/src/view/superAdmin/authority/components/apis.vue
+7
-3
未找到文件。
server/api/v1/sys_authority.go
浏览文件 @
6dd70d2a
...
...
@@ -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
{
...
...
server/model/response/sys_casbin.go
浏览文件 @
6dd70d2a
package
response
type
PolicyPathResponse
struct
{
Paths
[]
string
`json:"paths"`
Paths
[]
map
[
string
]
string
`json:"paths"`
}
server/service/sys_authority.go
浏览文件 @
6dd70d2a
...
...
@@ -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
(
"此角色有用户正在使用禁止删除"
)
...
...
server/service/sys_casbin.go
浏览文件 @
6dd70d2a
...
...
@@ -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
path
List
return
path
Maps
}
// @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
}
web/src/view/superAdmin/authority/components/apis.vue
浏览文件 @
6dd70d2a
...
...
@@ -9,7 +9,7 @@
:props=
"apiDefaultProps"
default-expand-all
highlight-current
node-key=
"
path
"
node-key=
"
onlyId
"
ref=
"apiTree"
show-checkbox
></el-tree>
...
...
@@ -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
)
})
}
}
</
script
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录