diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-06 17:11:49 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-06 17:11:49 +0000 |
commit | 50fc36ec4466c49782b18e9a2546df33cd783cf3 (patch) | |
tree | 03e57a76c58d79881e672cc941cfac1c10a17b52 /app | |
parent | 47f8339e47026158dc438023b0889b9f086a43ab (diff) | |
download | redmine-50fc36ec4466c49782b18e9a2546df33cd783cf3.tar.gz redmine-50fc36ec4466c49782b18e9a2546df33cd783cf3.zip |
Merged r16467 (#25501).
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@16505 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/issue_query.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 17 | ||||
-rw-r--r-- | app/models/query.rb | 9 | ||||
-rw-r--r-- | app/models/time_entry_query.rb | 8 |
4 files changed, 27 insertions, 13 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 01302cfb0..42d6df40f 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -236,7 +236,6 @@ class IssueQuery < Query end add_custom_fields_filters(issue_custom_fields) - add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version IssueRelation::TYPES.each do |relation_type, options| @@ -255,10 +254,7 @@ class IssueQuery < Query def available_columns return @available_columns if @available_columns @available_columns = self.class.available_columns.dup - @available_columns += (project ? - project.all_issue_custom_fields : - IssueCustomField - ).visible.collect {|cf| QueryCustomFieldColumn.new(cf) } + @available_columns += issue_custom_fields.visible.collect {|cf| QueryCustomFieldColumn.new(cf) } if User.current.allowed_to?(:view_time_entries, project, :global => true) index = @available_columns.find_index {|column| column.name == :total_estimated_hours} diff --git a/app/models/project.rb b/app/models/project.rb index 42413924a..60143ea8f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -324,6 +324,7 @@ class Project < ActiveRecord::Base @shared_versions = nil @rolled_up_versions = nil @rolled_up_trackers = nil + @rolled_up_custom_fields = nil @all_issue_custom_fields = nil @all_time_entry_custom_fields = nil @to_param = nil @@ -572,6 +573,22 @@ class Project < ActiveRecord::Base end end + # Returns a scope of all custom fields enabled for issues of the project + # and its subprojects + def rolled_up_custom_fields + if leaf? + all_issue_custom_fields + else + @rolled_up_custom_fields ||= IssueCustomField. + sorted. + where("is_for_all = ? OR EXISTS (SELECT 1" + + " FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} cfp" + + " JOIN #{Project.table_name} p ON p.id = cfp.project_id" + + " WHERE cfp.custom_field_id = #{CustomField.table_name}.id" + + " AND p.lft >= ? AND p.rgt <= ?)", true, lft, rgt) + end + end + def project self end diff --git a/app/models/query.rb b/app/models/query.rb index 2d646a295..a6d32f102 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -340,6 +340,15 @@ class Query < ActiveRecord::Base @all_projects_values = values end + # Returns a scope of issue custom fields that are available as columns or filters + def issue_custom_fields + if project + project.rolled_up_custom_fields + else + IssueCustomField.all + end + end + # Adds available filters def initialize_available_filters # implemented by sub-classes diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index 148c657c0..b34a0483f 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -140,12 +140,4 @@ class TimeEntryQuery < Query end self end - - def issue_custom_fields - if project - project.all_issue_custom_fields - else - IssueCustomField.where(:is_for_all => true) - end - end end |