You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

permission.go 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package controllers
  15. import (
  16. "encoding/json"
  17. "github.com/casbin/casibase/casdoor"
  18. )
  19. func (c *ApiController) GetPermissions() {
  20. owner := c.Input().Get("owner")
  21. permissions, err := casdoor.GetPermissions(owner)
  22. if err != nil {
  23. c.ResponseError(err.Error())
  24. return
  25. }
  26. c.ResponseOk(permissions)
  27. }
  28. func (c *ApiController) GetPermission() {
  29. id := c.Input().Get("id")
  30. permission, err := casdoor.GetPermission(id)
  31. if err != nil {
  32. c.ResponseError(err.Error())
  33. return
  34. }
  35. c.ResponseOk(permission)
  36. }
  37. func (c *ApiController) UpdatePermission() {
  38. id := c.Input().Get("id")
  39. var permission casdoor.Permission
  40. err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission)
  41. if err != nil {
  42. panic(err)
  43. }
  44. success, err := casdoor.UpdatePermission(id, &permission)
  45. if err != nil {
  46. c.ResponseError(err.Error())
  47. return
  48. }
  49. c.ResponseOk(success)
  50. }
  51. func (c *ApiController) AddPermission() {
  52. var permission casdoor.Permission
  53. err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission)
  54. if err != nil {
  55. c.ResponseError(err.Error())
  56. return
  57. }
  58. success, err := casdoor.AddPermission(&permission)
  59. if err != nil {
  60. c.ResponseError(err.Error())
  61. return
  62. }
  63. c.ResponseOk(success)
  64. }
  65. func (c *ApiController) DeletePermission() {
  66. var permission casdoor.Permission
  67. err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission)
  68. if err != nil {
  69. c.ResponseError(err.Error())
  70. return
  71. }
  72. success, err := casdoor.DeletePermission(&permission)
  73. if err != nil {
  74. c.ResponseError(err.Error())
  75. return
  76. }
  77. c.ResponseOk(success)
  78. }

基于Casbin的开源AI领域知识库平台