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.

47 lines
1.5 KiB

  1. package api
  2. import (
  3. "fmt"
  4. "gin-vue-admin/controller/servers"
  5. "gin-vue-admin/model/sysModel"
  6. "github.com/gin-gonic/gin"
  7. )
  8. type CasbinInReceive struct {
  9. AuthorityId string `json:"authorityId"`
  10. Paths []string `json:paths`
  11. }
  12. // @Tags casbin
  13. // @Summary 更改角色api权限
  14. // @Security ApiKeyAuth
  15. // @accept application/json
  16. // @Produce application/json
  17. // @Param data body api.CreateAuthorityParams true "更改角色api权限"
  18. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  19. // @Router /casbin/casbinPUpdata [post]
  20. func CasbinPUpdata(c *gin.Context) {
  21. var cmr CasbinInReceive
  22. _ = c.ShouldBind(&cmr)
  23. err := new(sysModel.CasbinModel).CasbinPUpdata(cmr.AuthorityId, cmr.Paths)
  24. if err != nil {
  25. servers.ReportFormat(c, false, fmt.Sprintf("添加规则失败,%v", err), gin.H{})
  26. } else {
  27. servers.ReportFormat(c, true, "添加规则成功", gin.H{})
  28. }
  29. }
  30. // @Tags casbin
  31. // @Summary 获取权限列表
  32. // @Security ApiKeyAuth
  33. // @accept application/json
  34. // @Produce application/json
  35. // @Param data body api.CreateAuthorityParams true "获取权限列表"
  36. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  37. // @Router /casbin/getPolicyPathByAuthorityId [post]
  38. func GetPolicyPathByAuthorityId(c *gin.Context) {
  39. var cmr CasbinInReceive
  40. _ = c.ShouldBind(&cmr)
  41. paths := new(sysModel.CasbinModel).GetPolicyPathByAuthorityId(cmr.AuthorityId)
  42. servers.ReportFormat(c, true, "获取规则成功", gin.H{"paths": paths})
  43. }