slas_controller.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class SlasController < ApplicationController
  3. before_action :authentication_check
  4. =begin
  5. Format:
  6. JSON
  7. Example:
  8. {
  9. "id":1,
  10. "name":"some sla",
  11. "condition":{"c_a":1,"c_b":2},
  12. "data":{"o_a":1,"o_b":2},
  13. "updated_at":"2012-09-14T17:51:53Z",
  14. "created_at":"2012-09-14T17:51:53Z",
  15. "updated_by_id":2.
  16. "created_by_id":2,
  17. }
  18. =end
  19. =begin
  20. Resource:
  21. GET /api/v1/slas.json
  22. Response:
  23. [
  24. {
  25. "id": 1,
  26. "name": "some_name1",
  27. ...
  28. },
  29. {
  30. "id": 2,
  31. "name": "some_name2",
  32. ...
  33. }
  34. ]
  35. Test:
  36. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password}
  37. =end
  38. def index
  39. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  40. if params[:full]
  41. # calendars
  42. assets = {}
  43. calendar_ids = []
  44. Calendar.all.each {|calendar|
  45. assets = calendar.assets(assets)
  46. }
  47. # slas
  48. sla_ids = []
  49. Sla.all.each {|item|
  50. sla_ids.push item.id
  51. assets = item.assets(assets)
  52. }
  53. render json: {
  54. record_ids: sla_ids,
  55. assets: assets,
  56. }, status: :ok
  57. return
  58. end
  59. model_index_render(Sla, params)
  60. end
  61. =begin
  62. Resource:
  63. GET /api/v1/slas/#{id}.json
  64. Response:
  65. {
  66. "id": 1,
  67. "name": "name_1",
  68. ...
  69. }
  70. Test:
  71. curl http://localhost/api/v1/slas/#{id}.json -v -u #{login}:#{password}
  72. =end
  73. def show
  74. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  75. model_show_render(Sla, params)
  76. end
  77. =begin
  78. Resource:
  79. POST /api/v1/slas.json
  80. Payload:
  81. {
  82. "name":"some sla",
  83. "condition":{"c_a":1,"c_b":2},
  84. "data":{"o_a":1,"o_b":2},
  85. }
  86. Response:
  87. {
  88. "id": 1,
  89. "name": "some_name",
  90. ...
  91. }
  92. Test:
  93. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"name": "some_name","active": true, "note": "some note"}'
  94. =end
  95. def create
  96. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  97. model_create_render(Sla, params)
  98. end
  99. =begin
  100. Resource:
  101. PUT /api/v1/slas/{id}.json
  102. Payload:
  103. {
  104. "name":"some sla",
  105. "condition":{"c_a":1,"c_b":2},
  106. "data":{"o_a":1,"o_b":2},
  107. }
  108. Response:
  109. {
  110. "id": 1,
  111. "name": "some_name",
  112. ...
  113. }
  114. Test:
  115. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"name": "some_name","active": true, "note": "some note"}'
  116. =end
  117. def update
  118. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  119. model_update_render(Sla, params)
  120. end
  121. =begin
  122. Resource:
  123. DELETE /api/v1/slas/{id}.json
  124. Response:
  125. {}
  126. Test:
  127. curl http://localhost/api/v1/slas.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X DELETE
  128. =end
  129. def destroy
  130. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  131. model_destory_render(Sla, params)
  132. end
  133. end