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.

55 lines
2.0 KiB

3 years ago
  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. // @Tags Casbin
  13. // @Summary 更新角色api权限
  14. // @Security ApiKeyAuth
  15. // @accept application/json
  16. // @Produce application/json
  17. // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
  18. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  19. // @Router /casbin/UpdateCasbin [post]
  20. func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
  21. var cmr request.CasbinInReceive
  22. _ = c.ShouldBindJSON(&cmr)
  23. if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil {
  24. response.FailWithMessage(err.Error(), c)
  25. return
  26. }
  27. if err := casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil {
  28. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  29. response.FailWithMessage("更新失败", c)
  30. } else {
  31. response.OkWithMessage("更新成功", c)
  32. }
  33. }
  34. // @Tags Casbin
  35. // @Summary 获取权限列表
  36. // @Security ApiKeyAuth
  37. // @accept application/json
  38. // @Produce application/json
  39. // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
  40. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  41. // @Router /casbin/getPolicyPathByAuthorityId [post]
  42. func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) {
  43. var casbin request.CasbinInReceive
  44. _ = c.ShouldBindJSON(&casbin)
  45. if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil {
  46. response.FailWithMessage(err.Error(), c)
  47. return
  48. }
  49. paths := casbinService.GetPolicyPathByAuthorityId(casbin.AuthorityId)
  50. response.OkWithDetailed(systemRes.PolicyPathResponse{Paths: paths}, "获取成功", c)
  51. }