| | |
| | | "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{} |
| | |
| | | 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() |
| | | } |
| | |
| | | // }, "获取成功", 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, ¶ms) |
| | | 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) { |