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.

48 lines
1.4 KiB

  1. package api
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "main/controller/servers"
  6. "main/model/sysModel"
  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.CreateAuthorityPatams true "更改角色api权限"
  18. // @Success 200 {string} json "{"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.CreateAuthorityPatams true "获取权限列表"
  36. // @Success 200 {string} json "{"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. }