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.

57 lines
2.0 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // @Tags casbin
  9. // @Summary 更改角色api权限
  10. // @Security ApiKeyAuth
  11. // @accept application/json
  12. // @Produce application/json
  13. // @Param data body sysModel.CasbinInReceive true "更改角色api权限"
  14. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  15. // @Router /casbin/UpdateCasbin [post]
  16. func UpdateCasbin(c *gin.Context) {
  17. var cmr model.CasbinInReceive
  18. _ = c.ShouldBindJSON(&cmr)
  19. err := new(model.CasbinModel).UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
  20. if err != nil {
  21. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("添加规则失败,%v", err), c)
  22. } else {
  23. response.Result(response.SUCCESS, gin.H{}, "添加规则成功", c)
  24. }
  25. }
  26. // @Tags casbin
  27. // @Summary 获取权限列表
  28. // @Security ApiKeyAuth
  29. // @accept application/json
  30. // @Produce application/json
  31. // @Param data body sysModel.CasbinInReceive true "获取权限列表"
  32. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  33. // @Router /casbin/getPolicyPathByAuthorityId [post]
  34. func GetPolicyPathByAuthorityId(c *gin.Context) {
  35. var cmr model.CasbinInReceive
  36. _ = c.ShouldBindJSON(&cmr)
  37. paths := new(model.CasbinModel).GetPolicyPathByAuthorityId(cmr.AuthorityId)
  38. response.Result(response.SUCCESS, gin.H{"paths": paths}, "获取规则成功", c)
  39. }
  40. // @Tags casbin
  41. // @Summary casb RBAC RESTFUL测试路由
  42. // @Security ApiKeyAuth
  43. // @accept application/json
  44. // @Produce application/json
  45. // @Param data body sysModel.CasbinInReceive true "获取权限列表"
  46. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  47. // @Router /casbin/CasbinTest [get]
  48. func CasbinTest(c *gin.Context) {
  49. // 测试restful以及占位符代码 随意书写
  50. pathParam := c.Param("pathParam")
  51. query := c.Query("query")
  52. response.Result(response.SUCCESS, gin.H{"pathParam": pathParam, "query": query}, "获取规则成功", c)
  53. }