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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/util"
  18. "github.com/casdoor/casdoor-go-sdk/casdoorsdk"
  19. )
  20. func (c *ApiController) GetPermissions() {
  21. permissions, err := casdoorsdk.GetPermissions()
  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. _, name := util.GetOwnerAndNameFromId(id)
  31. permission, err := casdoorsdk.GetPermission(name)
  32. if err != nil {
  33. c.ResponseError(err.Error())
  34. return
  35. }
  36. c.ResponseOk(permission)
  37. }
  38. func (c *ApiController) UpdatePermission() {
  39. var permission casdoorsdk.Permission
  40. err := json.Unmarshal(c.Ctx.Input.RequestBody, &permission)
  41. if err != nil {
  42. panic(err)
  43. }
  44. success, err := casdoorsdk.UpdatePermission(&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 casdoorsdk.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 := casdoorsdk.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 casdoorsdk.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 := casdoorsdk.DeletePermission(&permission)
  73. if err != nil {
  74. c.ResponseError(err.Error())
  75. return
  76. }
  77. c.ResponseOk(success)
  78. }