]> source.dussan.org Git - redmine.git/commitdiff
Moves journals selection to Issue#visible_journals_with_index (#17632).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Jan 2017 09:34:24 +0000 (09:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 14 Jan 2017 09:34:24 +0000 (09:34 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16180 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 0b99eb526a44d85b38e2145ac68c58bd44d97f06..9dba545ddaecb4914ac6491963aa7b2acb9d8bbc 100644 (file)
@@ -93,20 +93,15 @@ class IssuesController < ApplicationController
   end
 
   def show
-    @journals = @issue.journals.
-                  preload(:details).
-                  preload(:user => :email_address).
-                  reorder(:created_on, :id).to_a
-    @journals.each_with_index {|j,i| j.indice = i+1}
-    @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
-    Journal.preload_journals_details_custom_fields(@journals)
-    @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
-    @journals.reverse! if User.current.wants_comments_in_reverse_order?
-
+    @journals = @issue.visible_journals_with_index
     @changesets = @issue.changesets.visible.preload(:repository, :user).to_a
-    @changesets.reverse! if User.current.wants_comments_in_reverse_order?
-
     @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
+
+    if User.current.wants_comments_in_reverse_order?
+      @journals.reverse!
+      @changesets.reverse!
+    end
+
     @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
     @priorities = IssuePriority.active
     @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
index 2111b0489599406a6101eadeeb4d7f97fd3c76db..a64d72e4c8a2fed5da5940ea62aa46a2276d7467 100644 (file)
@@ -813,6 +813,21 @@ class Issue < ActiveRecord::Base
     scope
   end
 
+  # Returns the journals that are visible to user with their index
+  # Used to display the issue history
+  def visible_journals_with_index(user=User.current)
+    result = journals.
+      preload(:details).
+      preload(:user => :email_address).
+      reorder(:created_on, :id).to_a
+
+    result.each_with_index {|j,i| j.indice = i+1}
+    result.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, project)
+    Journal.preload_journals_details_custom_fields(result)
+    result.select! {|journal| journal.notes? || journal.visible_details.any?}
+    result
+  end
+
   # Returns the initial status of the issue
   # Returns nil for a new issue
   def status_was