Project

General

Profile

Feature #3050 » fix-journal-details-on-attachments.patch

Alex Shulgin, 2011-08-02 13:58

View differences:

app/models/attachment.rb
145 145
      attachments.each_value do |attachment|
146 146
        file = attachment['file']
147 147
        next unless file && file.size > 0
148
        a = Attachment.create(:container => obj,
149
                              :file => file,
150
                              :description => attachment['description'].to_s.strip,
151
                              :author => User.current)
148
        a = obj.attachments.create(:file => file,
149
                                   :description => attachment['description'].to_s.strip,
150
                                   :author => User.current)
152 151

  
153 152
        if a.new_record?
154 153
          obj.unsaved_attachments ||= []
app/models/issue.rb
35 35
  has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
36 36

  
37 37
  acts_as_nested_set :scope => 'root_id', :dependent => :destroy
38
  acts_as_attachable :after_remove => :attachment_removed
38
  acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
39 39
  acts_as_customizable
40 40
  acts_as_watchable
41 41
  acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
......
603 603

  
604 604
      if valid?
605 605
        attachments = Attachment.attach_files(self, params[:attachments])
606

  
607
        attachments[:files].each {|a| @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
608 606
        # TODO: Rename hook
609 607
        Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
610 608
        begin
......
834 832
    end
835 833
  end
836 834

  
837
  # Callback on attachment deletion
835
  def attachment_added(obj)
836
    @current_journal.details << JournalDetail.new(:property => 'attachment',
837
                                                  :prop_key => obj.id,
838
                                                  :value => obj.filename)
839
  end
840

  
838 841
  def attachment_removed(obj)
839 842
    journal = init_journal(User.current)
840 843
    journal.details << JournalDetail.new(:property => 'attachment',
app/models/mail_handler.rb
200 200
  def add_attachments(obj)
201 201
    if email.has_attachments? || email.multipart?
202 202
      email.attachments.each do |attachment|
203
        Attachment.create(:container => obj,
204
                          :file => attachment,
205
                          :author => user,
206
                          :content_type => attachment.content_type)
203
        obj.attachments.create(:file => attachment,
204
                               :author => user,
205
                               :content_type => attachment.content_type)
207 206
      end
208 207
    end
209 208
  end
(1-1/2)