summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-05 07:42:52 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-05 07:42:52 +0000
commit06c6de06e4d47531ebc6afef63b925ca80552339 (patch)
treecd15b26d672af8059b2c69b4e0ed3c351001b260 /app
parentba788c336d0d860043d680134c8ff05dceca52a5 (diff)
downloadredmine-06c6de06e4d47531ebc6afef63b925ca80552339.tar.gz
redmine-06c6de06e4d47531ebc6afef63b925ca80552339.zip
Last updated by colum in issue list (#6375).
git-svn-id: http://svn.redmine.org/redmine/trunk@16366 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/issue.rb26
-rw-r--r--app/models/issue_query.rb9
2 files changed, 35 insertions, 0 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 1877ca2c9..19fef95b5 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -245,6 +245,7 @@ class Issue < ActiveRecord::Base
@spent_hours = nil
@total_spent_hours = nil
@total_estimated_hours = nil
+ @last_updated_by = nil
base_reload(*args)
end
@@ -1069,6 +1070,14 @@ class Issue < ActiveRecord::Base
@relations ||= IssueRelation::Relations.new(self, (relations_from + relations_to).sort)
end
+ def last_updated_by
+ if @last_updated_by
+ @last_updated_by.presence
+ else
+ journals.reorder(:id => :desc).first.try(:user)
+ end
+ end
+
# Preloads relations for a collection of issues
def self.load_relations(issues)
if issues.any?
@@ -1132,6 +1141,23 @@ class Issue < ActiveRecord::Base
where(:ancestors => {:id => issues.map(&:id)})
end
+ # Preloads users who updated last a collection of issues
+ 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).
+ 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
+
+ issues.each do |issue|
+ journal = journals.detect {|j| j.journalized_id == issue.id}
+ issue.instance_variable_set("@last_updated_by", journal.try(:user) || '')
+ end
+ end
+ end
+
# Finds an issue relation given its id.
def find_relation(relation_id)
IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id)
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 458eea00a..88b51f593 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -43,6 +43,7 @@ class IssueQuery < Query
QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
QueryColumn.new(:closed_on, :sortable => "#{Issue.table_name}.closed_on", :default_order => 'desc'),
+ QueryColumn.new(:last_updated_by, :sortable => lambda {User.fields_for_order_statement("last_journal_user")}),
QueryColumn.new(:relations, :caption => :label_related_issues),
QueryColumn.new(:description, :inline => false)
]
@@ -298,6 +299,9 @@ class IssueQuery < Query
if has_column?(:total_spent_hours)
Issue.load_visible_total_spent_hours(issues)
end
+ if has_column?(:last_updated_by)
+ Issue.load_visible_last_updated_by(issues)
+ end
if has_column?(:relations)
Issue.load_visible_relations(issues)
end
@@ -572,6 +576,11 @@ class IssueQuery < Query
if order_options.include?('users')
joins << "LEFT OUTER JOIN #{User.table_name} ON #{User.table_name}.id = #{queried_table_name}.assigned_to_id"
end
+ if order_options.include?('last_journal_user')
+ joins << "LEFT OUTER JOIN #{Journal.table_name} ON #{Journal.table_name}.id = (SELECT MAX(#{Journal.table_name}.id) FROM #{Journal.table_name}" +
+ " WHERE #{Journal.table_name}.journalized_type='Issue' AND #{Journal.table_name}.journalized_id=#{Issue.table_name}.id AND #{Journal.visible_notes_condition(User.current, :skip_pre_condition => true)})" +
+ " LEFT OUTER JOIN #{User.table_name} last_journal_user ON last_journal_user.id = #{Journal.table_name}.user_id";
+ end
if order_options.include?('versions')
joins << "LEFT OUTER JOIN #{Version.table_name} ON #{Version.table_name}.id = #{queried_table_name}.fixed_version_id"
end