idoit_controller.rb 1.1 KB

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