浏览代码

Merge pull request #538 from songzhibin97/gva_gormv2_dev

fix:创建用户初始化权限,确保用户可用
奇淼(piexlmax 3 年之前
父节点
当前提交
17904a72c5
共有 3 个文件被更改,包括 26 次插入1 次删除
  1. 3 0
      server/api/v1/sys_authority.go
  2. 4 0
      server/model/request/sys_casbin.go
  3. 19 1
      server/model/request/sys_menu.go

+ 3 - 0
server/api/v1/sys_authority.go

@@ -7,6 +7,7 @@ import (
 	"gin-vue-admin/model/response"
 	"gin-vue-admin/service"
 	"gin-vue-admin/utils"
+
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
 )
@@ -30,6 +31,8 @@ func CreateAuthority(c *gin.Context) {
 		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
 		response.FailWithMessage("创建失败"+err.Error(), c)
 	} else {
+		service.AddMenuAuthority(request.DefaultMenu(), authority.AuthorityId)
+		service.UpdateCasbin(authority.AuthorityId, request.DefaultCasbin())
 		response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c)
 	}
 }

+ 4 - 0
server/model/request/sys_casbin.go

@@ -11,3 +11,7 @@ type CasbinInReceive struct {
 	AuthorityId string       `json:"authorityId"` // 权限id
 	CasbinInfos []CasbinInfo `json:"casbinInfos"`
 }
+
+func DefaultCasbin() []CasbinInfo {
+	return []CasbinInfo{{Path: "/menu/getMenu", Method: "POST"}, {Path: "/jwt/jsonInBlacklist", Method: "POST"}}
+}

+ 19 - 1
server/model/request/sys_menu.go

@@ -1,9 +1,27 @@
 package request
 
-import "gin-vue-admin/model"
+import (
+	"gin-vue-admin/global"
+	"gin-vue-admin/model"
+)
 
 // Add menu authority info structure
 type AddMenuAuthorityInfo struct {
 	Menus       []model.SysBaseMenu
 	AuthorityId string // 角色ID
 }
+
+func DefaultMenu() []model.SysBaseMenu {
+	return []model.SysBaseMenu{{
+		GVA_MODEL: global.GVA_MODEL{ID: 1},
+		ParentId:  "0",
+		Path:      "dashboard",
+		Name:      "dashboard",
+		Component: "view/dashboard/index.vue",
+		Sort:      1,
+		Meta: model.Meta{
+			Title: "仪表盘",
+			Icon:  "setting",
+		},
+	}}
+}