templates_controller.rb 2.9 KB

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