Feature #3050 » fix-journal-details-on-attachments.patch
| app/models/attachment.rb | ||
|---|---|---|
|
attachments.each_value do |attachment|
|
||
|
file = attachment['file']
|
||
|
next unless file && file.size > 0
|
||
|
a = Attachment.create(:container => obj,
|
||
|
:file => file,
|
||
|
:description => attachment['description'].to_s.strip,
|
||
|
:author => User.current)
|
||
|
a = obj.attachments.create(:file => file,
|
||
|
:description => attachment['description'].to_s.strip,
|
||
|
:author => User.current)
|
||
|
if a.new_record?
|
||
|
obj.unsaved_attachments ||= []
|
||
| app/models/issue.rb | ||
|---|---|---|
|
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
|
||
|
acts_as_nested_set :scope => 'root_id', :dependent => :destroy
|
||
|
acts_as_attachable :after_remove => :attachment_removed
|
||
|
acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
|
||
|
acts_as_customizable
|
||
|
acts_as_watchable
|
||
|
acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
|
||
| ... | ... | |
|
if valid?
|
||
|
attachments = Attachment.attach_files(self, params[:attachments])
|
||
|
attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
|
||
|
# TODO: Rename hook
|
||
|
Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
|
||
|
begin
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
# Callback on attachment deletion
|
||
|
def attachment_added(obj)
|
||
|
@current_journal.details << JournalDetail.new(:property => 'attachment',
|
||
|
:prop_key => obj.id,
|
||
|
:value => obj.filename)
|
||
|
end
|
||
|
def attachment_removed(obj)
|
||
|
journal = init_journal(User.current)
|
||
|
journal.details << JournalDetail.new(:property => 'attachment',
|
||
| app/models/mail_handler.rb | ||
|---|---|---|
|
def add_attachments(obj)
|
||
|
if email.has_attachments? || email.multipart?
|
||
|
email.attachments.each do |attachment|
|
||
|
Attachment.create(:container => obj,
|
||
|
:file => attachment,
|
||
|
:author => user,
|
||
|
:content_type => attachment.content_type)
|
||
|
obj.attachments.create(:file => attachment,
|
||
|
:author => user,
|
||
|
:content_type => attachment.content_type)
|
||
|
end
|
||
|
end
|
||
|
end
|
||