sys_casbin.go 2.0 KB

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