macros_controller.rb 2.2 KB

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