ticket_shared_draft_zoom_controller.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TicketSharedDraftZoomController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def show
  5. object = ticket.shared_draft
  6. render json: {
  7. shared_draft_id: object&.id,
  8. assets: object&.assets,
  9. }
  10. end
  11. def update
  12. if ticket.shared_draft.present?
  13. object = ticket.shared_draft
  14. object.update! draft_params
  15. else
  16. object = ticket.create_shared_draft! draft_params
  17. end
  18. object.attach_upload_cache params[:form_id]
  19. render json: {
  20. shared_draft_id: object.id,
  21. assets: object.assets,
  22. }
  23. end
  24. def destroy
  25. object = ticket.shared_draft
  26. object.destroy!
  27. render json: {
  28. shared_draft_id: object.id
  29. }
  30. end
  31. def import_attachments
  32. new_attachments = ticket.shared_draft.clone_attachments 'UploadCache', params[:form_id]
  33. render json: {
  34. attachments: new_attachments
  35. }
  36. end
  37. private
  38. def ticket
  39. Ticket.find params[:ticket_id]
  40. end
  41. def draft_params
  42. params.permit ticket_attributes: {}, new_article: {}
  43. end
  44. end