2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2015-04-27 23:19:26 +00:00
|
|
|
class Ticket::Article < ApplicationModel
|
|
|
|
load 'ticket/article/assets.rb'
|
|
|
|
include Ticket::Article::Assets
|
|
|
|
load 'ticket/article/history_log.rb'
|
|
|
|
include Ticket::Article::HistoryLog
|
|
|
|
load 'ticket/article/activity_stream_log.rb'
|
|
|
|
include Ticket::Article::ActivityStreamLog
|
|
|
|
|
|
|
|
belongs_to :ticket
|
|
|
|
belongs_to :type, class_name: 'Ticket::Article::Type'
|
|
|
|
belongs_to :sender, class_name: 'Ticket::Article::Sender'
|
|
|
|
belongs_to :created_by, class_name: 'User'
|
|
|
|
belongs_to :updated_by, class_name: 'User'
|
2015-06-05 14:19:36 +00:00
|
|
|
store :preferences
|
2015-08-30 18:16:29 +00:00
|
|
|
before_create :check_subject, :check_message_id_md5
|
|
|
|
before_update :check_subject, :check_message_id_md5
|
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
notify_clients_support
|
|
|
|
|
|
|
|
activity_stream_support ignore_attributes: {
|
|
|
|
type_id: true,
|
|
|
|
sender_id: true,
|
2015-06-05 14:19:36 +00:00
|
|
|
preferences: true,
|
2015-04-27 23:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
history_support ignore_attributes: {
|
|
|
|
type_id: true,
|
|
|
|
sender_id: true,
|
2015-06-05 14:19:36 +00:00
|
|
|
preferences: true,
|
2015-04-27 23:19:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-30 20:15:23 +00:00
|
|
|
# fillup md5 of message id to search easier on very long message ids
|
|
|
|
def check_message_id_md5
|
|
|
|
return if !message_id
|
|
|
|
return if message_id_md5
|
|
|
|
self.message_id_md5 = Digest::MD5.hexdigest(message_id.to_s)
|
|
|
|
end
|
|
|
|
|
2016-05-10 13:06:51 +00:00
|
|
|
# insert inline image urls
|
|
|
|
def self.insert_urls(article, attachments)
|
|
|
|
inline_attachments = {}
|
|
|
|
article['body'].gsub!( /(<img\s(style.+?|)src=")cid:(.+?)(">)/i ) { |item|
|
|
|
|
replace = item
|
|
|
|
|
|
|
|
# look for attachment
|
|
|
|
attachments.each {|file|
|
|
|
|
next if !file.preferences['Content-ID'] || file.preferences['Content-ID'] != $3
|
|
|
|
replace = "#{$1}/api/v1/ticket_attachment/#{article['ticket_id']}/#{article['id']}/#{file.id}#{$4}"
|
|
|
|
inline_attachments[file.id] = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
replace
|
|
|
|
}
|
|
|
|
new_attachments = []
|
|
|
|
attachments.each {|file|
|
|
|
|
next if inline_attachments[file.id]
|
|
|
|
new_attachments.push file
|
|
|
|
}
|
|
|
|
article['attachments'] = new_attachments
|
|
|
|
article
|
|
|
|
end
|
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
private
|
|
|
|
|
2015-08-30 18:16:29 +00:00
|
|
|
# strip not wanted chars
|
2015-04-27 23:19:26 +00:00
|
|
|
def check_subject
|
2015-05-07 12:10:38 +00:00
|
|
|
return if !subject
|
|
|
|
subject.gsub!(/\s|\t|\r/, ' ')
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2015-01-07 21:28:15 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
class Flag < ApplicationModel
|
|
|
|
end
|
2012-07-30 12:05:46 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
class Sender < ApplicationModel
|
2016-01-15 17:22:57 +00:00
|
|
|
validates :name, presence: true
|
2015-04-27 23:19:26 +00:00
|
|
|
latest_change_support
|
|
|
|
end
|
2012-07-30 12:05:46 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
class Type < ApplicationModel
|
2016-01-15 17:22:57 +00:00
|
|
|
validates :name, presence: true
|
2015-04-27 23:19:26 +00:00
|
|
|
latest_change_support
|
2012-07-30 12:05:46 +00:00
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|