You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.0 KiB

  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  6. systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
  7. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. )
  11. type CasbinApi struct {
  12. }
  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 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  20. // @Router /casbin/UpdateCasbin [post]
  21. func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
  22. var cmr request.CasbinInReceive
  23. _ = c.ShouldBindJSON(&cmr)
  24. if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil {
  25. response.FailWithMessage(err.Error(), c)
  26. return
  27. }
  28. if err := casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil {
  29. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  30. response.FailWithMessage("更新失败", c)
  31. } else {
  32. response.OkWithMessage("更新成功", c)
  33. }
  34. }
  35. // @Tags Casbin
  36. // @Summary 获取权限列表
  37. // @Security ApiKeyAuth
  38. // @accept application/json
  39. // @Produce application/json
  40. // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
  41. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  42. // @Router /casbin/getPolicyPathByAuthorityId [post]
  43. func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) {
  44. var casbin request.CasbinInReceive
  45. _ = c.ShouldBindJSON(&casbin)
  46. if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil {
  47. response.FailWithMessage(err.Error(), c)
  48. return
  49. }
  50. paths := casbinService.GetPolicyPathByAuthorityId(casbin.AuthorityId)
  51. response.OkWithDetailed(systemRes.PolicyPathResponse{Paths: paths}, "获取成功", c)
  52. }