Commit 7c05014f authored by jplang's avatar jplang

Fix loading of last visible journal (#1474, #6375).

git-svn-id: https://svn.redmine.org/redmine/trunk@16376 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 61f651c1
......@@ -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}
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment