idoit_controller.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class Integration::IdoitController < ApplicationController
  3. prepend_before_action -> { authentication_check(permission: ['agent.integration.idoit', 'admin.integration.idoit']) }, except: [:verify, :query, :update]
  4. prepend_before_action -> { authentication_check(permission: ['admin.integration.idoit']) }, only: [:verify]
  5. prepend_before_action -> { authentication_check(permission: ['ticket.agent']) }, only: [:query, :update]
  6. def verify
  7. response = ::Idoit.verify(params[:api_token], params[:endpoint], params[:client_id])
  8. render json: {
  9. result: 'ok',
  10. response: response,
  11. }
  12. rescue => e
  13. logger.error e
  14. render json: {
  15. result: 'failed',
  16. message: e.message,
  17. }
  18. end
  19. def query
  20. response = ::Idoit.query(params[:method], params[:filter])
  21. render json: {
  22. result: 'ok',
  23. response: response,
  24. }
  25. rescue => e
  26. logger.error e
  27. render json: {
  28. result: 'failed',
  29. message: e.message,
  30. }
  31. end
  32. def update
  33. params[:object_ids] ||= []
  34. ticket = Ticket.find(params[:ticket_id])
  35. access!(ticket, 'read')
  36. ticket.preferences[:idoit] ||= {}
  37. ticket.preferences[:idoit][:object_ids] ||= []
  38. ticket.preferences[:idoit][:object_ids].concat(params[:object_ids])
  39. ticket.save!
  40. render json: {
  41. result: 'ok',
  42. }
  43. end
  44. end