From 30f137e85a76420d872a96c30b2177f59e9706d2 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 17 七月 2023 16:13:59 +0800
Subject: [PATCH] add

---
 api/v1/authority.go |   52 ++++++++++++++++++++++++++++------------------------
 1 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/api/v1/authority.go b/api/v1/authority.go
index 32a299d..90ab274 100644
--- a/api/v1/authority.go
+++ b/api/v1/authority.go
@@ -5,12 +5,7 @@
 	"aps_crm/model/request"
 	"aps_crm/pkg/contextx"
 	"aps_crm/pkg/ecode"
-	"github.com/flipped-aurora/gin-vue-admin/server/global"
-	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
-	"github.com/flipped-aurora/gin-vue-admin/server/model/system"
-	"github.com/flipped-aurora/gin-vue-admin/server/utils"
 	"github.com/gin-gonic/gin"
-	"go.uber.org/zap"
 )
 
 type AuthorityApi struct{}
@@ -38,13 +33,15 @@
 		return
 	}
 
-	errCode = authorityService.CreateAuthority(auth)
+	errCode, auth.Id = authorityService.CreateAuthority(auth)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
 	}
 
-	//_ = menuService.AddMenuAuthority(systemReq.DefaultMenu(), authority.AuthorityId)
-	//_ = casbinService.UpdateCasbin(authority.AuthorityId, systemReq.DefaultCasbin())
+	casbinInfos := append(request.DefaultCasbin(), params.CasbinInfos...)
+
+	//_ = menuService.AddMenuAuthority(systemReq.DefaultMenu(), authority.Id)
+	_ = casbinService.UpdateCasbin(auth.Id, casbinInfos)
 
 	ctx.Ok()
 }
@@ -141,34 +138,41 @@
 //	}, "鑾峰彇鎴愬姛", c)
 //}
 
-// SetDataAuthority
+// SetMenuAuthority
 //
 //	@Tags		Authority
-//	@Summary	璁剧疆瑙掕壊璧勬簮鏉冮檺
+//	@Summary	璁剧疆瑙掕壊鑿滃崟
 //	@Security	ApiKeyAuth
 //	@accept		application/json
 //	@Produce	application/json
-//	@Param		data	body	request.AddAuthority	true	"璁剧疆瑙掕壊璧勬簮鏉冮檺"
-//	@Router		/authority/setDataAuthority [post]
-func (a *AuthorityApi) SetDataAuthority(c *gin.Context) {
-	var auth system.SysAuthority
-	err := c.ShouldBindJSON(&auth)
-	if err != nil {
-		response.FailWithMessage(err.Error(), c)
+//	@Param		data	body		request.SetAuthorityMenu	true	"璁剧疆瑙掕壊璧勬簮鏉冮檺"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/authority/setMenuAuthority [post]
+func (a *AuthorityApi) SetMenuAuthority(c *gin.Context) {
+	var params request.SetAuthorityMenu
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
 		return
 	}
-	err = utils.Verify(auth, utils.AuthorityIdVerify)
-	if err != nil {
-		response.FailWithMessage(err.Error(), c)
+
+	menus, errCode := menuService.GetMenusByIds(params.Menus)
+	if errCode != ecode.OK {
+		ctx.Fail(ecode.MenuListErr)
 		return
 	}
-	err = authorityService.SetDataAuthority(auth)
+
+	auth := model.Authority{
+		Id:    params.AuthorityId,
+		Menus: menus,
+	}
+
+	err := authorityService.SetMenuAuthority(&auth)
 	if err != nil {
-		global.GVA_LOG.Error("璁剧疆澶辫触!", zap.Error(err))
-		response.FailWithMessage("璁剧疆澶辫触"+err.Error(), c)
+		ctx.Fail(ecode.SetMenuAuthorityErr)
 		return
 	}
-	response.OkWithMessage("璁剧疆鎴愬姛", c)
+
+	ctx.Ok()
 }
 
 func checkAuthorityParams(params *request.AddAuthority) (int, model.Authority) {

--
Gitblit v1.8.0