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.

54 lines
1.7 KiB

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