summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-24 09:34:23 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-24 09:34:23 +0000
commit49900051ea2b404161dae568eeaec6f26bbe0c9d (patch)
tree58ac20243f4efdfd5f0baeb1e3cb0aec58b071cf /app
parent9957883c4ddf53cbbee40e8c952f0a7aa0d703ca (diff)
downloadredmine-49900051ea2b404161dae568eeaec6f26bbe0c9d.tar.gz
redmine-49900051ea2b404161dae568eeaec6f26bbe0c9d.zip
Fixed: MailHandler does not include JournalDetail for attached files (#7966).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6312 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/attachment.rb3
-rw-r--r--app/models/issue.rb11
-rw-r--r--app/models/mail_handler.rb2
3 files changed, 11 insertions, 5 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 92eb9157a..7e3a91581 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -149,7 +149,8 @@ class Attachment < ActiveRecord::Base
:file => file,
:description => attachment['description'].to_s.strip,
:author => User.current)
-
+ obj.attachments << a
+
if a.new_record?
obj.unsaved_attachments ||= []
obj.unsaved_attachments << a
diff --git a/app/models/issue.rb b/app/models/issue.rb
index b4aac4a36..48a0afb2a 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -35,7 +35,7 @@ class Issue < ActiveRecord::Base
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"],
@@ -612,8 +612,6 @@ class Issue < ActiveRecord::Base
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
@@ -842,6 +840,13 @@ class Issue < ActiveRecord::Base
end
end
end
+
+ # Callback on attachment deletion
+ def attachment_added(obj)
+ if @current_journal && !obj.new_record?
+ @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :value => obj.filename)
+ end
+ end
# Callback on attachment deletion
def attachment_removed(obj)
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 0ba8d3fd2..2cfb11698 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -200,7 +200,7 @@ class MailHandler < ActionMailer::Base
def add_attachments(obj)
if email.has_attachments?
email.attachments.each do |attachment|
- Attachment.create(:container => obj,
+ obj.attachments << Attachment.create(:container => obj,
:file => attachment,
:author => user,
:content_type => attachment.content_type)