email_addresses_controller.rb 2.5 KB

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