idoit_controller.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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: %i[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: %i[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. ticket.with_lock do
  36. access!(ticket, 'read')
  37. ticket.preferences[:idoit] ||= {}
  38. ticket.preferences[:idoit][:object_ids] = Array(params[:object_ids]).uniq
  39. ticket.save!
  40. end
  41. render json: {
  42. result: 'ok',
  43. }
  44. end
  45. end