Skip to content

Commit a2551e8

Browse files
committed
fix:创建用户初始化权限,确保用户可用
修改了: - server/api/v1/sys_authority.go - server/model/request/sys_casbin.go - server/model/request/sys_menu.go
1 parent 0cd3555 commit a2551e8

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
package request
22

3-
import "gin-vue-admin/model"
3+
import (
4+
"gin-vue-admin/model"
5+
)
46

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

0 commit comments

Comments
 (0)