fix: 修复普通用户登陆之后菜单未能正常获取的问题 (#166)
This commit is contained in:
parent
e8c6bc38cb
commit
8c05e7df57
|
@ -7,6 +7,8 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- main
|
||||
release:
|
||||
types: [created,published] # 表示在创建新的 Release 时触发
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
# 可以手动触发
|
||||
|
@ -24,38 +26,35 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "::set-output name=today::$(date +'%Y-%m-%d_%H-%M')"
|
||||
- name: Inject slug/short variables
|
||||
uses: rlespinasse/github-slug-action@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Available platforms
|
||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
# 所需要的体系结构,可以在 Available platforms 步骤中获取所有的可用架构
|
||||
platforms: linux/amd64,linux/arm64/v8
|
||||
# 镜像推送时间
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
platforms: linux/arm64,linux/amd64
|
||||
# 给清单打上多个标签
|
||||
tags: |
|
||||
eryajf/go-ldap-admin-server:${{ steps.date.outputs.today }}
|
||||
eryajf/go-ldap-admin-server:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.GITHUB_REPOSITORY_NAME_PART }}:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.GITHUB_REPOSITORY_NAME_PART }}:${{ env.GITHUB_REF_NAME }}
|
|
@ -9,14 +9,6 @@ import (
|
|||
|
||||
type MenuController struct{}
|
||||
|
||||
// // List 记录列表
|
||||
// func (m *MenuController) List(c *gin.Context) {
|
||||
// req := new(request.MenuListReq)
|
||||
// Run(c, req, func() (interface{}, interface{}) {
|
||||
// return logic.Menu.List(c, req)
|
||||
// })
|
||||
// }
|
||||
|
||||
// GetTree 菜单树
|
||||
func (m *MenuController) GetTree(c *gin.Context) {
|
||||
req := new(request.MenuGetTreeReq)
|
||||
|
@ -25,6 +17,14 @@ func (m *MenuController) GetTree(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// GetUserMenuTreeByUserId 获取用户菜单树
|
||||
func (m *MenuController) GetAccessTree(c *gin.Context) {
|
||||
req := new(request.MenuGetAccessTreeReq)
|
||||
Run(c, req, func() (interface{}, interface{}) {
|
||||
return logic.Menu.GetAccessTree(c, req)
|
||||
})
|
||||
}
|
||||
|
||||
// Add 新建
|
||||
func (m *MenuController) Add(c *gin.Context) {
|
||||
req := new(request.MenuAddReq)
|
||||
|
|
|
@ -168,7 +168,6 @@ func (l MenuLogic) GetTree(c *gin.Context, req interface{}) (data interface{}, r
|
|||
return nil, ReqAssertErr
|
||||
}
|
||||
_ = c
|
||||
|
||||
menus, err := isql.Menu.List()
|
||||
if err != nil {
|
||||
return nil, tools.NewMySqlError(fmt.Errorf("获取资源列表失败: " + err.Error()))
|
||||
|
@ -178,3 +177,34 @@ func (l MenuLogic) GetTree(c *gin.Context, req interface{}) (data interface{}, r
|
|||
|
||||
return tree, nil
|
||||
}
|
||||
|
||||
// GetAccessTree 获取用户菜单树
|
||||
func (l MenuLogic) GetAccessTree(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) {
|
||||
r, ok := req.(*request.MenuGetAccessTreeReq)
|
||||
if !ok {
|
||||
return nil, ReqAssertErr
|
||||
}
|
||||
_ = c
|
||||
// 校验
|
||||
filter := tools.H{"id": r.ID}
|
||||
if !isql.User.Exist(filter) {
|
||||
return nil, tools.NewValidatorError(fmt.Errorf("该用户不存在"))
|
||||
}
|
||||
user := new(model.User)
|
||||
err := isql.User.Find(filter, user)
|
||||
if err != nil {
|
||||
return nil, tools.NewMySqlError(fmt.Errorf("在MySQL查询用户失败: " + err.Error()))
|
||||
}
|
||||
var roleIds []uint
|
||||
for _, role := range user.Roles {
|
||||
roleIds = append(roleIds, role.ID)
|
||||
}
|
||||
menus, err := isql.Menu.ListUserMenus(roleIds)
|
||||
if err != nil {
|
||||
return nil, tools.NewMySqlError(fmt.Errorf("获取资源列表失败: " + err.Error()))
|
||||
}
|
||||
|
||||
tree := isql.GenMenuTree(0, menus)
|
||||
|
||||
return tree, nil
|
||||
}
|
||||
|
|
|
@ -49,3 +49,8 @@ type MenuDeleteReq struct {
|
|||
// MenuGetTreeReq 获取菜单树结构体
|
||||
type MenuGetTreeReq struct {
|
||||
}
|
||||
|
||||
// MenuGetAccessTreeReq 获取用户菜单树
|
||||
type MenuGetAccessTreeReq struct {
|
||||
ID uint `json:"id" form:"id"`
|
||||
}
|
||||
|
|
|
@ -543,6 +543,13 @@ func InitData() {
|
|||
Remark: "获取菜单树",
|
||||
Creator: "系统",
|
||||
},
|
||||
{
|
||||
Method: "GET",
|
||||
Path: "/menu/access/tree",
|
||||
Category: "menu",
|
||||
Remark: "获取用户菜单树",
|
||||
Creator: "系统",
|
||||
},
|
||||
{
|
||||
Method: "POST",
|
||||
Path: "/menu/add",
|
||||
|
@ -667,19 +674,8 @@ func InitData() {
|
|||
"/base/changePwd",
|
||||
"/base/dashboard",
|
||||
"/user/info",
|
||||
"/user/list",
|
||||
"/user/changePwd",
|
||||
"/group/list",
|
||||
"/group/tree",
|
||||
"/group/useringroup",
|
||||
"/group/usernoingroup",
|
||||
"/role/list",
|
||||
"/role/getmenulist",
|
||||
"/role/getapilist",
|
||||
"/menu/tree",
|
||||
"/menu/list",
|
||||
"/api/list",
|
||||
"/api/tree",
|
||||
"/menu/access/tree",
|
||||
"/log/operation/list",
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ func InitMenuRoutes(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) gi
|
|||
menu.Use(middleware.CasbinMiddleware())
|
||||
{
|
||||
menu.GET("/tree", controller.Menu.GetTree)
|
||||
// menu.GET("/list", controller.Menu.List)
|
||||
menu.GET("/access/tree", controller.Menu.GetAccessTree)
|
||||
menu.POST("/add", controller.Menu.Add)
|
||||
menu.POST("/update", controller.Menu.Update)
|
||||
menu.POST("/delete", controller.Menu.Delete)
|
||||
|
|
Loading…
Reference in New Issue