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
1.8 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model/request"
  6. resp "gin-vue-admin/model/response"
  7. "gin-vue-admin/service"
  8. "gin-vue-admin/utils"
  9. "github.com/gin-gonic/gin"
  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 "更改角色api权限"
  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. AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
  23. if AuthorityIdVerifyErr != nil {
  24. response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
  25. return
  26. }
  27. err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
  28. if err != nil {
  29. response.FailWithMessage(fmt.Sprintf("添加规则失败,%v", err), 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 "获取权限列表"
  40. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  41. // @Router /casbin/getPolicyPathByAuthorityId [post]
  42. func GetPolicyPathByAuthorityId(c *gin.Context) {
  43. var cmr request.CasbinInReceive
  44. _ = c.ShouldBindJSON(&cmr)
  45. AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
  46. if AuthorityIdVerifyErr != nil {
  47. response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
  48. return
  49. }
  50. paths := service.GetPolicyPathByAuthorityId(cmr.AuthorityId)
  51. response.OkWithData(resp.PolicyPathResponse{Paths: paths}, c)
  52. }