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.

59 lines
1.9 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. "github.com/gin-gonic/gin"
  9. )
  10. // @Tags casbin
  11. // @Summary 更改角色api权限
  12. // @Security ApiKeyAuth
  13. // @accept application/json
  14. // @Produce application/json
  15. // @Param data body model.CasbinInReceive true "更改角色api权限"
  16. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  17. // @Router /casbin/UpdateCasbin [post]
  18. func UpdateCasbin(c *gin.Context) {
  19. var cmr request.CasbinInReceive
  20. _ = c.ShouldBindJSON(&cmr)
  21. err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
  22. if err != nil {
  23. response.FailWithMessage(fmt.Sprintf("添加规则失败,%v", err), c)
  24. } else {
  25. response.OkWithMessage("添加规则成功", c)
  26. }
  27. }
  28. // @Tags casbin
  29. // @Summary 获取权限列表
  30. // @Security ApiKeyAuth
  31. // @accept application/json
  32. // @Produce application/json
  33. // @Param data body model.CasbinInReceive true "获取权限列表"
  34. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  35. // @Router /casbin/getPolicyPathByAuthorityId [post]
  36. func GetPolicyPathByAuthorityId(c *gin.Context) {
  37. var cmr request.CasbinInReceive
  38. _ = c.ShouldBindJSON(&cmr)
  39. paths := service.GetPolicyPathByAuthorityId(cmr.AuthorityId)
  40. response.OkWithData(resp.PolicyPathResponse{Paths: paths}, c)
  41. }
  42. // @Tags casbin
  43. // @Summary casb RBAC RESTFUL测试路由
  44. // @Security ApiKeyAuth
  45. // @accept application/json
  46. // @Produce application/json
  47. // @Param data body model.CasbinInReceive true "获取权限列表"
  48. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  49. // @Router /casbin/CasbinTest [get]
  50. func CasbinTest(c *gin.Context) {
  51. // 测试restful以及占位符代码 随意书写
  52. pathParam := c.Param("pathParam")
  53. query := c.Query("query")
  54. response.OkDetailed(gin.H{"pathParam": pathParam, "query": query}, "获取规则成功", c)
  55. }