macros_controller.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class MacrosController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "name":"some text_module",
  11. "perform":{
  12. "ticket.priority_id": 5,
  13. "ticket.state_id": 2,
  14. },
  15. "active":true,
  16. "updated_at":"2012-09-14T17:51:53Z",
  17. "created_at":"2012-09-14T17:51:53Z",
  18. "updated_by_id":2,
  19. "created_by_id":2,
  20. }
  21. =end
  22. =begin
  23. Resource:
  24. GET /api/v1/macros.json
  25. Response:
  26. [
  27. {
  28. "id": 1,
  29. "name": "some_name1",
  30. ...
  31. },
  32. {
  33. "id": 2,
  34. "name": "some_name2",
  35. ...
  36. }
  37. ]
  38. Test:
  39. curl http://localhost/api/v1/macros.json -v -u #{login}:#{password}
  40. =end
  41. def index
  42. model_index_render(policy_scope(Macro), params)
  43. end
  44. =begin
  45. Resource:
  46. GET /api/v1/macros/#{id}.json
  47. Response:
  48. {
  49. "id": 1,
  50. "name": "name_1",
  51. ...
  52. }
  53. Test:
  54. curl http://localhost/api/v1/macros/#{id}.json -v -u #{login}:#{password}
  55. =end
  56. def show
  57. model_show_render(policy_scope(Macro), params)
  58. end
  59. =begin
  60. Resource:
  61. POST /api/v1/macros.json
  62. Payload:
  63. {
  64. "name": "some name",
  65. "perform":{
  66. "ticket.priority_id": 5,
  67. "ticket.state_id": 2,
  68. },
  69. "active":true,
  70. }
  71. Response:
  72. {
  73. "id": 1,
  74. "name": "some_name",
  75. ...
  76. }
  77. Test:
  78. curl http://localhost/api/v1/macros.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  79. =end
  80. def create
  81. model_create_render(Macro, params)
  82. end
  83. =begin
  84. Resource:
  85. PUT /api/v1/macros/{id}.json
  86. Payload:
  87. {
  88. "name": "some name",
  89. "perform":{
  90. "ticket.priority_id": 5,
  91. "ticket.state_id": 2,
  92. },
  93. "active":true,
  94. }
  95. Response:
  96. {
  97. "id": 1,
  98. "name": "some_name",
  99. ...
  100. }
  101. Test:
  102. curl http://localhost/api/v1/macros.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  103. =end
  104. def update
  105. model_update_render(Macro, params)
  106. end
  107. =begin
  108. Resource:
  109. DELETE /api/v1/macros/{id}.json
  110. Response:
  111. {}
  112. Test:
  113. curl http://localhost/api/v1/macros.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  114. =end
  115. def destroy
  116. model_destroy_render(Macro, params)
  117. end
  118. end