]> source.dussan.org Git - redmine.git/commitdiff
Fixed: unable to add a file to an issue without entering a note.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 19 Oct 2007 19:09:47 +0000 (19:09 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 19 Oct 2007 19:09:47 +0000 (19:09 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@853 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/issue.rb
app/models/journal.rb

index fc35d8d8a2333a083ee32f251b808d71211631bc..bad778e670309a3f2b9fbe73767686582660e522 100644 (file)
@@ -94,21 +94,19 @@ class IssuesController < ApplicationController
   end
   
   def add_note
-    unless params[:notes].empty?
-      journal = @issue.init_journal(self.logged_in_user, params[:notes])
-      if @issue.save
-        params[:attachments].each { |file|
-          next unless file.size > 0
-          a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
-          journal.details << JournalDetail.new(:property => 'attachment',
-                                               :prop_key => a.id,
-                                               :value => a.filename) unless a.new_record?
-        } if params[:attachments] and params[:attachments].is_a? Array
-        flash[:notice] = l(:notice_successful_update)
-        Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
-        redirect_to :action => 'show', :id => @issue
-        return
-      end
+    journal = @issue.init_journal(User.current, params[:notes])
+    params[:attachments].each { |file|
+      next unless file.size > 0
+      a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
+      journal.details << JournalDetail.new(:property => 'attachment',
+                                           :prop_key => a.id,
+                                           :value => a.filename) unless a.new_record?
+    } if params[:attachments] and params[:attachments].is_a? Array
+    if journal.save
+      flash[:notice] = l(:notice_successful_update)
+      Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
+      redirect_to :action => 'show', :id => @issue
+      return
     end
     show
   end
index 7730cfd7ab91d390f4ceadd4ad14b60052e515a3..026ce1211e7632be98abb83981c6052b4d55278c 100644 (file)
@@ -98,8 +98,10 @@ class Issue < ActiveRecord::Base
                                                       :old_value => @custom_values_before_change[c.custom_field_id],
                                                       :value => c.value)
       }      
-      @current_journal.save unless @current_journal.details.empty? and @current_journal.notes.empty?
+      @current_journal.save
     end
+    # Save the issue even if the journal is not saved (because empty)
+    true
   end
   
   def after_save
index 6e7632e7387535d7e2ca33b1c3aea42175be937e..a68988a7b7c21b246f2321bd9fc61d4187371163 100644 (file)
@@ -28,4 +28,9 @@ class Journal < ActiveRecord::Base
                      :include => :issue,
                      :project_key => "#{Issue.table_name}.project_id",
                      :date_column => "#{Issue.table_name}.created_on"
+  
+  def save
+    # Do not save an empty journal
+    (details.empty? && notes.blank?) ? false : super
+  end
 end