clones_ticket_article_attachments.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. module ClonesTicketArticleAttachments
  2. extend ActiveSupport::Concern
  3. private
  4. def article_attachments_clone(article)
  5. raise Exceptions::UnprocessableEntity, 'Need form_id to attach attachments to new form.' if params[:form_id].blank?
  6. existing_attachments = Store.list(
  7. object: 'UploadCache',
  8. o_id: params[:form_id],
  9. )
  10. attachments = []
  11. article.attachments.each do |new_attachment|
  12. next if new_attachment.preferences['Content-ID'].present?
  13. next if new_attachment.preferences['content-alternative'] == true
  14. already_added = false
  15. existing_attachments.each do |existing_attachment|
  16. next if existing_attachment.filename != new_attachment.filename || existing_attachment.size != new_attachment.size
  17. already_added = true
  18. break
  19. end
  20. next if already_added == true
  21. file = Store.add(
  22. object: 'UploadCache',
  23. o_id: params[:form_id],
  24. data: new_attachment.content,
  25. filename: new_attachment.filename,
  26. preferences: new_attachment.preferences,
  27. )
  28. attachments.push file
  29. end
  30. attachments
  31. end
  32. end