]> source.dussan.org Git - redmine.git/commitdiff
Fix loading of last visible journal (#1474, #6375).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 5 Mar 2017 11:05:50 +0000 (11:05 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 5 Mar 2017 11:05:50 +0000 (11:05 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16376 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/functional/issues_controller_test.rb

index 1fd84210dd618c150facb24e5ebeb1abaced9c52..d8dce76b4e694e38f05870535c41993705ffc9f1 100644 (file)
@@ -1154,11 +1154,13 @@ class Issue < ActiveRecord::Base
   def self.load_visible_last_updated_by(issues, user=User.current)
      if issues.any?
       issue_ids = issues.map(&:id)
-      journals = Journal.joins(issue: :project).preload(:user).
+      journal_ids = Journal.joins(issue: :project).
         where(:journalized_type => 'Issue', :journalized_id => issue_ids).
-        where("#{Journal.table_name}.id = (SELECT MAX(j.id) FROM #{Journal.table_name} j" +
-              " WHERE j.journalized_type='Issue' AND j.journalized_id=#{Journal.table_name}.journalized_id" +
-              " AND #{Journal.visible_notes_condition(user, :skip_pre_condition => true)})").to_a
+        where(Journal.visible_notes_condition(user, :skip_pre_condition => true)).
+        group(:journalized_id).
+        maximum(:id).
+        values
+      journals = Journal.where(:id => journal_ids).to_a
 
       issues.each do |issue|
         journal = journals.detect {|j| j.journalized_id == issue.id}
@@ -1171,12 +1173,14 @@ class Issue < ActiveRecord::Base
   def self.load_visible_last_notes(issues, user=User.current)
     if issues.any?
       issue_ids = issues.map(&:id)
-      journals = Journal.joins(issue: :project).
+      journal_ids = Journal.joins(issue: :project).
         where(:journalized_type => 'Issue', :journalized_id => issue_ids).
-        where("#{Journal.table_name}.id = (SELECT MAX(j.id) FROM #{Journal.table_name} j" +
-              " WHERE j.journalized_type='Issue' AND j.journalized_id=#{Journal.table_name}.journalized_id" +
-              " AND j.notes <> ''" +
-              " AND #{Journal.visible_notes_condition(user, :skip_pre_condition => true)})").to_a
+        where(Journal.visible_notes_condition(user, :skip_pre_condition => true)).
+        where.not(notes: '').
+        group(:journalized_id).
+        maximum(:id).
+        values
+      journals = Journal.where(:id => journal_ids).to_a
 
       issues.each do |issue|
         journal = journals.detect {|j| j.journalized_id == issue.id}
index 63ac34fddf5cd3dc83f7abe89b896fd65891e1d4..f120baba2451db413d1eefb33751e74a3482202d 100644 (file)
@@ -986,6 +986,7 @@ class IssuesControllerTest < Redmine::ControllerTest
   end
 
   def test_index_with_last_notes_column_should_display_private_notes_with_permission_only
+    journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Public notes', :user_id => 1)
     journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
     @request.session[:user_id] = 2
 
@@ -997,7 +998,7 @@ class IssuesControllerTest < Redmine::ControllerTest
 
     get :index, :set_filter => 1, :c => %w(subject last_notes)
     assert_response :success
-    assert_select 'td.last_notes[colspan="3"]', :text => 'A comment with inline image:  and a reference to #1 and r2.'
+    assert_select 'td.last_notes[colspan="3"]', :text => 'Public notes'
   end
 
   def test_index_with_description_and_last_notes_columns_should_display_column_name