Skip to content

Commit 1772c1c

Browse files
author
奇淼(piexlmax
authored
Merge pull request #538 from songzhibin97/gva_gormv2_dev
fix:创建用户初始化权限,确保用户可用
2 parents c044fcd + a2737af commit 1772c1c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

server/api/v1/sys_authority.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"gin-vue-admin/model/response"
88
"gin-vue-admin/service"
99
"gin-vue-admin/utils"
10+
1011
"github.com/gin-gonic/gin"
1112
"go.uber.org/zap"
1213
)
@@ -30,6 +31,8 @@ func CreateAuthority(c *gin.Context) {
3031
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
3132
response.FailWithMessage("创建失败"+err.Error(), c)
3233
} else {
34+
service.AddMenuAuthority(request.DefaultMenu(), authority.AuthorityId)
35+
service.UpdateCasbin(authority.AuthorityId, request.DefaultCasbin())
3336
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c)
3437
}
3538
}

server/model/request/sys_casbin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ type CasbinInReceive struct {
1111
AuthorityId string `json:"authorityId"` // 权限id
1212
CasbinInfos []CasbinInfo `json:"casbinInfos"`
1313
}
14+
15+
func DefaultCasbin() []CasbinInfo {
16+
return []CasbinInfo{{Path: "/menu/getMenu", Method: "POST"}, {Path: "/jwt/jsonInBlacklist", Method: "POST"}}
17+
}

server/model/request/sys_menu.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
package request
22

3-
import "gin-vue-admin/model"
3+
import (
4+
"gin-vue-admin/global"
5+
"gin-vue-admin/model"
6+
)
47

58
// Add menu authority info structure
69
type AddMenuAuthorityInfo struct {
710
Menus []model.SysBaseMenu
811
AuthorityId string // 角色ID
912
}
13+
14+
func DefaultMenu() []model.SysBaseMenu {
15+
return []model.SysBaseMenu{{
16+
GVA_MODEL: global.GVA_MODEL{ID: 1},
17+
ParentId: "0",
18+
Path: "dashboard",
19+
Name: "dashboard",
20+
Component: "view/dashboard/index.vue",
21+
Sort: 1,
22+
Meta: model.Meta{
23+
Title: "仪表盘",
24+
Icon: "setting",
25+
},
26+
}}
27+
}

0 commit comments

Comments
 (0)