2013-06-12 15:59:58 +00:00
|
|
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2012-07-30 12:05:46 +00:00
|
|
|
class Ticket::Article < ApplicationModel
|
2013-08-19 06:29:49 +00:00
|
|
|
include Ticket::Article::Assets
|
2013-09-25 19:50:28 +00:00
|
|
|
include Ticket::Article::HistoryLog
|
2013-09-29 21:37:49 +00:00
|
|
|
include Ticket::Article::ActivityStreamLog
|
2013-08-19 06:29:49 +00:00
|
|
|
|
2012-07-30 12:05:46 +00:00
|
|
|
belongs_to :ticket
|
|
|
|
belongs_to :ticket_article_type, :class_name => 'Ticket::Article::Type'
|
|
|
|
belongs_to :ticket_article_sender, :class_name => 'Ticket::Article::Sender'
|
|
|
|
belongs_to :created_by, :class_name => 'User'
|
2013-09-28 00:07:11 +00:00
|
|
|
after_create :attachment_check
|
2013-06-29 00:13:03 +00:00
|
|
|
after_create :notify_clients_after_create
|
|
|
|
after_update :notify_clients_after_update
|
|
|
|
after_destroy :notify_clients_after_destroy
|
2012-07-30 12:05:46 +00:00
|
|
|
|
2013-09-28 00:07:11 +00:00
|
|
|
activity_stream_support
|
2013-09-29 21:37:49 +00:00
|
|
|
|
|
|
|
history_support :ignore_attributes => {
|
|
|
|
:create_article_type_id => true,
|
|
|
|
:create_article_sender_id => true,
|
|
|
|
}
|
2013-09-28 00:07:11 +00:00
|
|
|
|
2013-03-28 23:13:15 +00:00
|
|
|
attr_accessor :attachments
|
|
|
|
|
2012-07-30 12:05:46 +00:00
|
|
|
private
|
2013-03-28 23:13:15 +00:00
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
def attachment_check
|
|
|
|
|
|
|
|
# do nothing if no attachment exists
|
|
|
|
return 1 if self.attachments == nil
|
|
|
|
|
|
|
|
# store attachments
|
|
|
|
article_store = []
|
|
|
|
self.attachments.each do |attachment|
|
|
|
|
article_store.push Store.add(
|
|
|
|
:object => 'Ticket::Article',
|
|
|
|
:o_id => self.id,
|
|
|
|
:data => attachment.store_file.data,
|
|
|
|
:filename => attachment.filename,
|
|
|
|
:preferences => attachment.preferences,
|
|
|
|
:created_by_id => self.created_by_id,
|
|
|
|
)
|
2012-07-30 12:05:46 +00:00
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
self.attachments = article_store
|
|
|
|
end
|
2012-07-30 12:05:46 +00:00
|
|
|
|
|
|
|
class Flag < ApplicationModel
|
|
|
|
end
|
|
|
|
|
|
|
|
class Sender < ApplicationModel
|
2012-10-14 21:00:33 +00:00
|
|
|
validates :name, :presence => true
|
2012-07-30 12:05:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Type < ApplicationModel
|
2012-10-14 21:00:33 +00:00
|
|
|
validates :name, :presence => true
|
2012-07-30 12:05:46 +00:00
|
|
|
end
|
|
|
|
end
|