1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package system
- import (
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "go.uber.org/zap"
- "lcfns/model/common/response"
- "lcfns/model/system/request"
- systemRes "lcfns/model/system/response"
- "lcfns/utils"
- )
- type CasbinApi struct{}
- // UpdateCasbin
- // @Tags Casbin
- // @Summary 更新角色api权限
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
- // @Success 200 {object} response.Response{msg=string} "更新角色api权限"
- // @Router /casbin/UpdateCasbin [post]
- func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
- var cmr request.CasbinInReceive
- err := c.ShouldBindJSON(&cmr)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err = utils.Verify(cmr, utils.AuthorityIdVerify)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err = casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
- if err != nil {
- logrus.Error("更新失败!", zap.Error(err))
- response.FailWithMessage("更新失败", c)
- return
- }
- response.OkWithMessage("更新成功", c)
- }
- // GetPolicyPathByAuthorityId
- // @Tags Casbin
- // @Summary 获取权限列表
- // @Security ApiKeyAuth
- // @accept application/json
- // @Produce application/json
- // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
- // @Success 200 {object} response.Response{data=systemRes.PolicyPathResponse,msg=string} "获取权限列表,返回包括casbin详情列表"
- // @Router /casbin/getPolicyPathByAuthorityId [post]
- func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) {
- var casbin request.CasbinInReceive
- err := c.ShouldBindJSON(&casbin)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err = utils.Verify(casbin, utils.AuthorityIdVerify)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- paths := casbinService.GetPolicyPathByAuthorityId(casbin.AuthorityId)
- response.OkWithDetailed(systemRes.PolicyPathResponse{Paths: paths}, "获取成功", c)
- }
|