Project

General

Profile

Defect #33290 » 0001-stop-db-access-on-class-definition-v2.patch

Kevin Fischer, 2021-02-05 11:54

View differences:

app/models/query.rb
20 20
require 'redmine/sort_criteria'
21 21

  
22 22
class QueryColumn
23
  attr_accessor :name, :groupable, :totalable, :default_order
24
  attr_writer   :sortable
23
  attr_accessor :name, :totalable, :default_order
24
  attr_writer   :sortable, :groupable
25 25
  include Redmine::I18n
26 26

  
27 27
  def initialize(name, options={})
28 28
    self.name = name
29 29
    self.sortable = options[:sortable]
30 30
    self.groupable = options[:groupable] || false
31
    if groupable == true
32
      self.groupable = name.to_s
33
    end
34 31
    self.totalable = options[:totalable] || false
35 32
    self.default_order = options[:default_order]
36 33
    @inline = options.key?(:inline) ? options[:inline] : true
......
49 46
    end
50 47
  end
51 48

  
49
  def groupable?
50
    @groupable
51
  end
52

  
52 53
  # Returns true if the column is sortable, otherwise false
53 54
  def sortable?
54 55
    !@sortable.nil?
......
82 83
  def css_classes
83 84
    name
84 85
  end
86

  
87
  def group_by_statement
88
    name.to_s
89
  end
85 90
end
86 91

  
87 92
class TimestampQueryColumn < QueryColumn
88
  def groupable
89
    if @groupable
90
      Redmine::Database.timestamp_to_date(sortable, User.current.time_zone)
91
    end
93
  def groupable?
94
    group_by_statement.present?
95
  end
96

  
97
  def group_by_statement
98
    Redmine::Database.timestamp_to_date(sortable, User.current.time_zone)
92 99
  end
93 100

  
94 101
  def group_value(object)
......
121 128
  def initialize(custom_field, options={})
122 129
    self.name = "cf_#{custom_field.id}".to_sym
123 130
    self.sortable = custom_field.order_statement || false
124
    self.groupable = custom_field.group_statement || false
125 131
    self.totalable = options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable?
126 132
    @inline = custom_field.full_width_layout? ? false : true
127 133
    @cf = custom_field
128 134
  end
129 135

  
136
  def groupable?
137
    group_by_statement.present?
138
  end
139

  
140
  def group_by_statement
141
    @cf.group_statement
142
  end
143

  
130 144
  def caption
131 145
    @cf.name
132 146
  end
......
741 755

  
742 756
  # Returns an array of columns that can be used to group the results
743 757
  def groupable_columns
744
    available_columns.select {|c| c.groupable}
758
    available_columns.select {|c| c.groupable?}
745 759
  end
746 760

  
747 761
  # Returns a Hash of columns and the key for sorting
......
889 903
  end
890 904

  
891 905
  def group_by_column
892
    groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by}
906
    groupable_columns.detect {|c| c.groupable? && c.name.to_s == group_by}
893 907
  end
894 908

  
895 909
  def group_by_statement
896
    group_by_column.try(:groupable)
910
    group_by_column.try(:group_by_statement)
897 911
  end
898 912

  
899 913
  def project_statement
(2-2/2)