Project

General

Profile

Feature #3050 » fix-receiving-new-issues-with-attachments.patch

Alex Shulgin, 2011-08-09 10:24

View differences:

app/models/issue.rb
833 833
  end
834 834

  
835 835
  def attachment_added(obj)
836
    init_journal(User.current) unless @current_journal
836 837
    @current_journal.details << JournalDetail.new(:property => 'attachment',
837 838
                                                  :prop_key => obj.id,
838 839
                                                  :value => obj.filename)
839 840
  end
840 841

  
841 842
  def attachment_removed(obj)
842
    journal = init_journal(User.current)
843
    journal.details << JournalDetail.new(:property => 'attachment',
844
                                         :prop_key => obj.id,
845
                                         :old_value => obj.filename)
846
    journal.save
843
    init_journal(User.current) unless @current_journal
844
    @current_journal.details << JournalDetail.new(:property => 'attachment',
845
                                                  :prop_key => obj.id,
846
                                                  :old_value => obj.filename)
847
    # Currently, this is only triggered from attachments#destroy, so
848
    # there's no one else to save the issue's journal.
849
    @current_journal.save
847 850
  end
848 851

  
849 852
  # Default assignment based on category
app/models/mail_handler.rb
138 138
    # add To and Cc as watchers before saving so the watchers can reply to Redmine
139 139
    add_watchers(issue)
140 140
    issue.save!
141
    add_attachments(issue)
141

  
142
    if add_attachments(issue)
143
      # Adding attachments to a new issue creates a journal.  We need
144
      # to save the record to trigger an issue update mail.
145
      issue.save!
146
    end
142 147
    logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
143 148
    issue
144 149
  end
......
198 203
  end
199 204

  
200 205
  def add_attachments(obj)
206
    added = false
201 207
    if email.has_attachments? || email.multipart?
202 208
      email.attachments.each do |attachment|
203 209
        obj.attachments.create(:file => attachment,
204 210
                               :author => user,
205 211
                               :content_type => attachment.content_type)
212
        added = true
206 213
      end
207 214
    end
215
    added
208 216
  end
209 217

  
210 218
  # Adds To and Cc as watchers of the given object if the sender has the
(2-2/2)