sys_casbin.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package system
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "go.uber.org/zap"
  6. "lcfns/model/common/response"
  7. "lcfns/model/system/request"
  8. systemRes "lcfns/model/system/response"
  9. "lcfns/utils"
  10. )
  11. type CasbinApi struct{}
  12. // UpdateCasbin
  13. // @Tags Casbin
  14. // @Summary 更新角色api权限
  15. // @Security ApiKeyAuth
  16. // @accept application/json
  17. // @Produce application/json
  18. // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
  19. // @Success 200 {object} response.Response{msg=string} "更新角色api权限"
  20. // @Router /casbin/UpdateCasbin [post]
  21. func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
  22. var cmr request.CasbinInReceive
  23. err := c.ShouldBindJSON(&cmr)
  24. if err != nil {
  25. response.FailWithMessage(err.Error(), c)
  26. return
  27. }
  28. err = utils.Verify(cmr, utils.AuthorityIdVerify)
  29. if err != nil {
  30. response.FailWithMessage(err.Error(), c)
  31. return
  32. }
  33. err = casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
  34. if err != nil {
  35. logrus.Error("更新失败!", zap.Error(err))
  36. response.FailWithMessage("更新失败", c)
  37. return
  38. }
  39. response.OkWithMessage("更新成功", c)
  40. }
  41. // GetPolicyPathByAuthorityId
  42. // @Tags Casbin
  43. // @Summary 获取权限列表
  44. // @Security ApiKeyAuth
  45. // @accept application/json
  46. // @Produce application/json
  47. // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
  48. // @Success 200 {object} response.Response{data=systemRes.PolicyPathResponse,msg=string} "获取权限列表,返回包括casbin详情列表"
  49. // @Router /casbin/getPolicyPathByAuthorityId [post]
  50. func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) {
  51. var casbin request.CasbinInReceive
  52. err := c.ShouldBindJSON(&casbin)
  53. if err != nil {
  54. response.FailWithMessage(err.Error(), c)
  55. return
  56. }
  57. err = utils.Verify(casbin, utils.AuthorityIdVerify)
  58. if err != nil {
  59. response.FailWithMessage(err.Error(), c)
  60. return
  61. }
  62. paths := casbinService.GetPolicyPathByAuthorityId(casbin.AuthorityId)
  63. response.OkWithDetailed(systemRes.PolicyPathResponse{Paths: paths}, "获取成功", c)
  64. }