2017-08-28 21:31:26 +00:00
|
|
|
module ClonesTicketArticleAttachments
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def article_attachments_clone(article)
|
|
|
|
raise Exceptions::UnprocessableEntity, 'Need form_id to attach attachments to new form.' if params[:form_id].blank?
|
|
|
|
|
|
|
|
existing_attachments = Store.list(
|
|
|
|
object: 'UploadCache',
|
2018-12-19 17:31:51 +00:00
|
|
|
o_id: params[:form_id],
|
2017-08-28 21:31:26 +00:00
|
|
|
)
|
|
|
|
attachments = []
|
|
|
|
article.attachments.each do |new_attachment|
|
|
|
|
next if new_attachment.preferences['content-alternative'] == true
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-01-25 11:35:11 +00:00
|
|
|
if article.content_type.present? && article.content_type =~ %r{text/html}i
|
|
|
|
next if new_attachment.preferences['content_disposition'].present? && new_attachment.preferences['content_disposition'] !~ /inline/
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-01-25 11:35:11 +00:00
|
|
|
if new_attachment.preferences['Content-ID'].present? && article.body.present?
|
|
|
|
next if article.body.match?(/#{Regexp.quote(new_attachment.preferences['Content-ID'])}/i)
|
|
|
|
end
|
|
|
|
end
|
2017-08-28 21:31:26 +00:00
|
|
|
already_added = false
|
|
|
|
existing_attachments.each do |existing_attachment|
|
|
|
|
next if existing_attachment.filename != new_attachment.filename || existing_attachment.size != new_attachment.size
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-08-28 21:31:26 +00:00
|
|
|
already_added = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
next if already_added == true
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-08-28 21:31:26 +00:00
|
|
|
file = Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'UploadCache',
|
|
|
|
o_id: params[:form_id],
|
|
|
|
data: new_attachment.content,
|
|
|
|
filename: new_attachment.filename,
|
2017-08-28 21:31:26 +00:00
|
|
|
preferences: new_attachment.preferences,
|
|
|
|
)
|
|
|
|
attachments.push file
|
|
|
|
end
|
|
|
|
|
|
|
|
attachments
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|