##// END OF EJS Templates
Added a "Member of Role" to the issues filters. #5869...
Eric Davis -
r3964:41f8d043eb29
parent child
Show More
@@ -1,615 +1,638
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class QueryColumn
19 19 attr_accessor :name, :sortable, :groupable, :default_order
20 20 include Redmine::I18n
21 21
22 22 def initialize(name, options={})
23 23 self.name = name
24 24 self.sortable = options[:sortable]
25 25 self.groupable = options[:groupable] || false
26 26 if groupable == true
27 27 self.groupable = name.to_s
28 28 end
29 29 self.default_order = options[:default_order]
30 30 @caption_key = options[:caption] || "field_#{name}"
31 31 end
32 32
33 33 def caption
34 34 l(@caption_key)
35 35 end
36 36
37 37 # Returns true if the column is sortable, otherwise false
38 38 def sortable?
39 39 !sortable.nil?
40 40 end
41 41
42 42 def value(issue)
43 43 issue.send name
44 44 end
45 45 end
46 46
47 47 class QueryCustomFieldColumn < QueryColumn
48 48
49 49 def initialize(custom_field)
50 50 self.name = "cf_#{custom_field.id}".to_sym
51 51 self.sortable = custom_field.order_statement || false
52 52 if %w(list date bool int).include?(custom_field.field_format)
53 53 self.groupable = custom_field.order_statement
54 54 end
55 55 self.groupable ||= false
56 56 @cf = custom_field
57 57 end
58 58
59 59 def caption
60 60 @cf.name
61 61 end
62 62
63 63 def custom_field
64 64 @cf
65 65 end
66 66
67 67 def value(issue)
68 68 cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
69 69 cv && @cf.cast_value(cv.value)
70 70 end
71 71 end
72 72
73 73 class Query < ActiveRecord::Base
74 74 class StatementInvalid < ::ActiveRecord::StatementInvalid
75 75 end
76 76
77 77 belongs_to :project
78 78 belongs_to :user
79 79 serialize :filters
80 80 serialize :column_names
81 81 serialize :sort_criteria, Array
82 82
83 83 attr_protected :project_id, :user_id
84 84
85 85 validates_presence_of :name, :on => :save
86 86 validates_length_of :name, :maximum => 255
87 87
88 88 @@operators = { "=" => :label_equals,
89 89 "!" => :label_not_equals,
90 90 "o" => :label_open_issues,
91 91 "c" => :label_closed_issues,
92 92 "!*" => :label_none,
93 93 "*" => :label_all,
94 94 ">=" => :label_greater_or_equal,
95 95 "<=" => :label_less_or_equal,
96 96 "<t+" => :label_in_less_than,
97 97 ">t+" => :label_in_more_than,
98 98 "t+" => :label_in,
99 99 "t" => :label_today,
100 100 "w" => :label_this_week,
101 101 ">t-" => :label_less_than_ago,
102 102 "<t-" => :label_more_than_ago,
103 103 "t-" => :label_ago,
104 104 "~" => :label_contains,
105 105 "!~" => :label_not_contains }
106 106
107 107 cattr_reader :operators
108 108
109 109 @@operators_by_filter_type = { :list => [ "=", "!" ],
110 110 :list_status => [ "o", "=", "!", "c", "*" ],
111 111 :list_optional => [ "=", "!", "!*", "*" ],
112 112 :list_subprojects => [ "*", "!*", "=" ],
113 113 :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
114 114 :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
115 115 :string => [ "=", "~", "!", "!~" ],
116 116 :text => [ "~", "!~" ],
117 117 :integer => [ "=", ">=", "<=", "!*", "*" ] }
118 118
119 119 cattr_reader :operators_by_filter_type
120 120
121 121 @@available_columns = [
122 122 QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
123 123 QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
124 124 QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue),
125 125 QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
126 126 QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
127 127 QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
128 128 QueryColumn.new(:author),
129 129 QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
130 130 QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
131 131 QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
132 132 QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true),
133 133 QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
134 134 QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
135 135 QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
136 136 QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
137 137 QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
138 138 ]
139 139 cattr_reader :available_columns
140 140
141 141 def initialize(attributes = nil)
142 142 super attributes
143 143 self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} }
144 144 end
145 145
146 146 def after_initialize
147 147 # Store the fact that project is nil (used in #editable_by?)
148 148 @is_for_all = project.nil?
149 149 end
150 150
151 151 def validate
152 152 filters.each_key do |field|
153 153 errors.add label_for(field), :blank unless
154 154 # filter requires one or more values
155 155 (values_for(field) and !values_for(field).first.blank?) or
156 156 # filter doesn't require any value
157 157 ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
158 158 end if filters
159 159 end
160 160
161 161 def editable_by?(user)
162 162 return false unless user
163 163 # Admin can edit them all and regular users can edit their private queries
164 164 return true if user.admin? || (!is_public && self.user_id == user.id)
165 165 # Members can not edit public queries that are for all project (only admin is allowed to)
166 166 is_public && !@is_for_all && user.allowed_to?(:manage_public_queries, project)
167 167 end
168 168
169 169 def available_filters
170 170 return @available_filters if @available_filters
171 171
172 172 trackers = project.nil? ? Tracker.find(:all, :order => 'position') : project.rolled_up_trackers
173 173
174 174 @available_filters = { "status_id" => { :type => :list_status, :order => 1, :values => IssueStatus.find(:all, :order => 'position').collect{|s| [s.name, s.id.to_s] } },
175 175 "tracker_id" => { :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] } },
176 176 "priority_id" => { :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] } },
177 177 "subject" => { :type => :text, :order => 8 },
178 178 "created_on" => { :type => :date_past, :order => 9 },
179 179 "updated_on" => { :type => :date_past, :order => 10 },
180 180 "start_date" => { :type => :date, :order => 11 },
181 181 "due_date" => { :type => :date, :order => 12 },
182 182 "estimated_hours" => { :type => :integer, :order => 13 },
183 183 "done_ratio" => { :type => :integer, :order => 14 }}
184 184
185 185 user_values = []
186 186 user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
187 187 if project
188 188 user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] }
189 189 else
190 190 project_ids = Project.all(:conditions => Project.visible_by(User.current)).collect(&:id)
191 191 if project_ids.any?
192 192 # members of the user's projects
193 193 user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort.collect{|s| [s.name, s.id.to_s] }
194 194 end
195 195 end
196 196 @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty?
197 197 @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty?
198 198
199 199 group_values = Group.all.collect {|g| [g.name, g.id] }
200 200 @available_filters["member_of_group"] = { :type => :list_optional, :order => 6, :values => group_values } unless group_values.empty?
201
202 role_values = Role.givable.collect {|r| [r.name, r.id] }
203 @available_filters["assigned_to_role"] = { :type => :list_optional, :order => 7, :values => role_values } unless role_values.empty?
201 204
202 205 if User.current.logged?
203 206 @available_filters["watcher_id"] = { :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]] }
204 207 end
205 208
206 209 if project
207 210 # project specific filters
208 211 unless @project.issue_categories.empty?
209 212 @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
210 213 end
211 214 unless @project.shared_versions.empty?
212 215 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
213 216 end
214 217 unless @project.descendants.active.empty?
215 218 @available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.descendants.visible.collect{|s| [s.name, s.id.to_s] } }
216 219 end
217 220 add_custom_fields_filters(@project.all_issue_custom_fields)
218 221 else
219 222 # global filters for cross project issue list
220 223 system_shared_versions = Version.visible.find_all_by_sharing('system')
221 224 unless system_shared_versions.empty?
222 225 @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
223 226 end
224 227 add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
225 228 # project filter
226 229 project_values = Project.all(:conditions => Project.visible_by(User.current), :order => 'lft').map do |p|
227 230 pre = (p.level > 0 ? ('--' * p.level + ' ') : '')
228 231 ["#{pre}#{p.name}",p.id.to_s]
229 232 end
230 233 @available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values}
231 234 end
232 235 @available_filters
233 236 end
234 237
235 238 def add_filter(field, operator, values)
236 239 # values must be an array
237 240 return unless values and values.is_a? Array # and !values.first.empty?
238 241 # check if field is defined as an available filter
239 242 if available_filters.has_key? field
240 243 filter_options = available_filters[field]
241 244 # check if operator is allowed for that filter
242 245 #if @@operators_by_filter_type[filter_options[:type]].include? operator
243 246 # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
244 247 # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
245 248 #end
246 249 filters[field] = {:operator => operator, :values => values }
247 250 end
248 251 end
249 252
250 253 def add_short_filter(field, expression)
251 254 return unless expression
252 255 parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first
253 256 add_filter field, (parms[0] || "="), [parms[1] || ""]
254 257 end
255 258
256 259 # Add multiple filters using +add_filter+
257 260 def add_filters(fields, operators, values)
258 261 fields.each do |field|
259 262 add_filter(field, operators[field], values[field])
260 263 end
261 264 end
262 265
263 266 def has_filter?(field)
264 267 filters and filters[field]
265 268 end
266 269
267 270 def operator_for(field)
268 271 has_filter?(field) ? filters[field][:operator] : nil
269 272 end
270 273
271 274 def values_for(field)
272 275 has_filter?(field) ? filters[field][:values] : nil
273 276 end
274 277
275 278 def label_for(field)
276 279 label = available_filters[field][:name] if available_filters.has_key?(field)
277 280 label ||= field.gsub(/\_id$/, "")
278 281 end
279 282
280 283 def available_columns
281 284 return @available_columns if @available_columns
282 285 @available_columns = Query.available_columns
283 286 @available_columns += (project ?
284 287 project.all_issue_custom_fields :
285 288 IssueCustomField.find(:all)
286 289 ).collect {|cf| QueryCustomFieldColumn.new(cf) }
287 290 end
288 291
289 292 def self.available_columns=(v)
290 293 self.available_columns = (v)
291 294 end
292 295
293 296 def self.add_available_column(column)
294 297 self.available_columns << (column) if column.is_a?(QueryColumn)
295 298 end
296 299
297 300 # Returns an array of columns that can be used to group the results
298 301 def groupable_columns
299 302 available_columns.select {|c| c.groupable}
300 303 end
301 304
302 305 # Returns a Hash of columns and the key for sorting
303 306 def sortable_columns
304 307 {'id' => "#{Issue.table_name}.id"}.merge(available_columns.inject({}) {|h, column|
305 308 h[column.name.to_s] = column.sortable
306 309 h
307 310 })
308 311 end
309 312
310 313 def columns
311 314 if has_default_columns?
312 315 available_columns.select do |c|
313 316 # Adds the project column by default for cross-project lists
314 317 Setting.issue_list_default_columns.include?(c.name.to_s) || (c.name == :project && project.nil?)
315 318 end
316 319 else
317 320 # preserve the column_names order
318 321 column_names.collect {|name| available_columns.find {|col| col.name == name}}.compact
319 322 end
320 323 end
321 324
322 325 def column_names=(names)
323 326 if names
324 327 names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
325 328 names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym }
326 329 # Set column_names to nil if default columns
327 330 if names.map(&:to_s) == Setting.issue_list_default_columns
328 331 names = nil
329 332 end
330 333 end
331 334 write_attribute(:column_names, names)
332 335 end
333 336
334 337 def has_column?(column)
335 338 column_names && column_names.include?(column.name)
336 339 end
337 340
338 341 def has_default_columns?
339 342 column_names.nil? || column_names.empty?
340 343 end
341 344
342 345 def sort_criteria=(arg)
343 346 c = []
344 347 if arg.is_a?(Hash)
345 348 arg = arg.keys.sort.collect {|k| arg[k]}
346 349 end
347 350 c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, o == 'desc' ? o : 'asc']}
348 351 write_attribute(:sort_criteria, c)
349 352 end
350 353
351 354 def sort_criteria
352 355 read_attribute(:sort_criteria) || []
353 356 end
354 357
355 358 def sort_criteria_key(arg)
356 359 sort_criteria && sort_criteria[arg] && sort_criteria[arg].first
357 360 end
358 361
359 362 def sort_criteria_order(arg)
360 363 sort_criteria && sort_criteria[arg] && sort_criteria[arg].last
361 364 end
362 365
363 366 # Returns the SQL sort order that should be prepended for grouping
364 367 def group_by_sort_order
365 368 if grouped? && (column = group_by_column)
366 369 column.sortable.is_a?(Array) ?
367 370 column.sortable.collect {|s| "#{s} #{column.default_order}"}.join(',') :
368 371 "#{column.sortable} #{column.default_order}"
369 372 end
370 373 end
371 374
372 375 # Returns true if the query is a grouped query
373 376 def grouped?
374 377 !group_by.blank?
375 378 end
376 379
377 380 def group_by_column
378 381 groupable_columns.detect {|c| c.name.to_s == group_by}
379 382 end
380 383
381 384 def group_by_statement
382 385 group_by_column.groupable
383 386 end
384 387
385 388 def project_statement
386 389 project_clauses = []
387 390 if project && !@project.descendants.active.empty?
388 391 ids = [project.id]
389 392 if has_filter?("subproject_id")
390 393 case operator_for("subproject_id")
391 394 when '='
392 395 # include the selected subprojects
393 396 ids += values_for("subproject_id").each(&:to_i)
394 397 when '!*'
395 398 # main project only
396 399 else
397 400 # all subprojects
398 401 ids += project.descendants.collect(&:id)
399 402 end
400 403 elsif Setting.display_subprojects_issues?
401 404 ids += project.descendants.collect(&:id)
402 405 end
403 406 project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
404 407 elsif project
405 408 project_clauses << "#{Project.table_name}.id = %d" % project.id
406 409 end
407 410 project_clauses << Project.allowed_to_condition(User.current, :view_issues)
408 411 project_clauses.join(' AND ')
409 412 end
410 413
411 414 def statement
412 415 # filters clauses
413 416 filters_clauses = []
414 417 filters.each_key do |field|
415 418 next if field == "subproject_id"
416 419 v = values_for(field).clone
417 420 next unless v and !v.empty?
418 421 operator = operator_for(field)
419 422
420 423 # "me" value subsitution
421 424 if %w(assigned_to_id author_id watcher_id).include?(field)
422 425 v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me")
423 426 end
424 427
425 428 sql = ''
426 429 if field =~ /^cf_(\d+)$/
427 430 # custom field
428 431 db_table = CustomValue.table_name
429 432 db_field = 'value'
430 433 is_custom_filter = true
431 434 sql << "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} WHERE "
432 435 sql << sql_for_field(field, operator, v, db_table, db_field, true) + ')'
433 436 elsif field == 'watcher_id'
434 437 db_table = Watcher.table_name
435 438 db_field = 'user_id'
436 439 sql << "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND "
437 440 sql << sql_for_field(field, '=', v, db_table, db_field) + ')'
438 441 elsif field == "member_of_group" # named field
439 442 if operator == '*' # Any group
440 443 groups = Group.all
441 444 members_of_groups = groups.collect(&:user_ids).flatten.compact.collect(&:to_s)
442 445 operator = '=' # Override the operator since we want to find by assigned_to
443 446 elsif operator == "!*"
444 447 groups = Group.all
445 448 members_of_groups = groups.collect(&:user_ids).flatten.compact.collect(&:to_s)
446 449 operator = '!' # Override the operator since we want to find by assigned_to
447 450 else
448 451 groups = Group.find_all_by_id(v)
449 452 members_of_groups = groups.collect(&:user_ids).flatten.compact.collect(&:to_s)
450 453 end
451 454
452 455 sql << '(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')'
453 456
457 elsif field == "assigned_to_role" # named field
458 if operator == "*" # Any Role
459 roles = Role.givable
460 operator = '=' # Override the operator since we want to find by assigned_to
461 elsif operator == "!*" # No role
462 roles = Role.givable
463 operator = '!' # Override the operator since we want to find by assigned_to
464 else
465 roles = Role.givable.find_all_by_id(v)
466 end
467 roles ||= []
468
469 members_of_roles = roles.inject([]) {|user_ids, role|
470 if role && role.members
471 user_ids << role.members.collect(&:user_id)
472 end
473 user_ids.flatten.uniq.compact
474 }.sort.collect(&:to_s)
475
476 sql << '(' + sql_for_field("assigned_to_id", operator, members_of_roles, Issue.table_name, "assigned_to_id", false) + ')'
454 477 else
455 478 # regular field
456 479 db_table = Issue.table_name
457 480 db_field = field
458 481 sql << '(' + sql_for_field(field, operator, v, db_table, db_field) + ')'
459 482 end
460 483 filters_clauses << sql
461 484
462 485 end if filters and valid?
463 486
464 487 (filters_clauses << project_statement).join(' AND ')
465 488 end
466 489
467 490 # Returns the issue count
468 491 def issue_count
469 492 Issue.count(:include => [:status, :project], :conditions => statement)
470 493 rescue ::ActiveRecord::StatementInvalid => e
471 494 raise StatementInvalid.new(e.message)
472 495 end
473 496
474 497 # Returns the issue count by group or nil if query is not grouped
475 498 def issue_count_by_group
476 499 r = nil
477 500 if grouped?
478 501 begin
479 502 # Rails will raise an (unexpected) RecordNotFound if there's only a nil group value
480 503 r = Issue.count(:group => group_by_statement, :include => [:status, :project], :conditions => statement)
481 504 rescue ActiveRecord::RecordNotFound
482 505 r = {nil => issue_count}
483 506 end
484 507 c = group_by_column
485 508 if c.is_a?(QueryCustomFieldColumn)
486 509 r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
487 510 end
488 511 end
489 512 r
490 513 rescue ::ActiveRecord::StatementInvalid => e
491 514 raise StatementInvalid.new(e.message)
492 515 end
493 516
494 517 # Returns the issues
495 518 # Valid options are :order, :offset, :limit, :include, :conditions
496 519 def issues(options={})
497 520 order_option = [group_by_sort_order, options[:order]].reject {|s| s.blank?}.join(',')
498 521 order_option = nil if order_option.blank?
499 522
500 523 Issue.find :all, :include => ([:status, :project] + (options[:include] || [])).uniq,
501 524 :conditions => Query.merge_conditions(statement, options[:conditions]),
502 525 :order => order_option,
503 526 :limit => options[:limit],
504 527 :offset => options[:offset]
505 528 rescue ::ActiveRecord::StatementInvalid => e
506 529 raise StatementInvalid.new(e.message)
507 530 end
508 531
509 532 # Returns the journals
510 533 # Valid options are :order, :offset, :limit
511 534 def journals(options={})
512 535 Journal.find :all, :include => [:details, :user, {:issue => [:project, :author, :tracker, :status]}],
513 536 :conditions => statement,
514 537 :order => options[:order],
515 538 :limit => options[:limit],
516 539 :offset => options[:offset]
517 540 rescue ::ActiveRecord::StatementInvalid => e
518 541 raise StatementInvalid.new(e.message)
519 542 end
520 543
521 544 # Returns the versions
522 545 # Valid options are :conditions
523 546 def versions(options={})
524 547 Version.find :all, :include => :project,
525 548 :conditions => Query.merge_conditions(project_statement, options[:conditions])
526 549 rescue ::ActiveRecord::StatementInvalid => e
527 550 raise StatementInvalid.new(e.message)
528 551 end
529 552
530 553 private
531 554
532 555 # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+
533 556 def sql_for_field(field, operator, value, db_table, db_field, is_custom_filter=false)
534 557 sql = ''
535 558 case operator
536 559 when "="
537 560 sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
538 561 when "!"
539 562 sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
540 563 when "!*"
541 564 sql = "#{db_table}.#{db_field} IS NULL"
542 565 sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
543 566 when "*"
544 567 sql = "#{db_table}.#{db_field} IS NOT NULL"
545 568 sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
546 569 when ">="
547 570 sql = "#{db_table}.#{db_field} >= #{value.first.to_i}"
548 571 when "<="
549 572 sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
550 573 when "o"
551 574 sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
552 575 when "c"
553 576 sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
554 577 when ">t-"
555 578 sql = date_range_clause(db_table, db_field, - value.first.to_i, 0)
556 579 when "<t-"
557 580 sql = date_range_clause(db_table, db_field, nil, - value.first.to_i)
558 581 when "t-"
559 582 sql = date_range_clause(db_table, db_field, - value.first.to_i, - value.first.to_i)
560 583 when ">t+"
561 584 sql = date_range_clause(db_table, db_field, value.first.to_i, nil)
562 585 when "<t+"
563 586 sql = date_range_clause(db_table, db_field, 0, value.first.to_i)
564 587 when "t+"
565 588 sql = date_range_clause(db_table, db_field, value.first.to_i, value.first.to_i)
566 589 when "t"
567 590 sql = date_range_clause(db_table, db_field, 0, 0)
568 591 when "w"
569 592 from = l(:general_first_day_of_week) == '7' ?
570 593 # week starts on sunday
571 594 ((Date.today.cwday == 7) ? Time.now.at_beginning_of_day : Time.now.at_beginning_of_week - 1.day) :
572 595 # week starts on monday (Rails default)
573 596 Time.now.at_beginning_of_week
574 597 sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
575 598 when "~"
576 599 sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
577 600 when "!~"
578 601 sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
579 602 end
580 603
581 604 return sql
582 605 end
583 606
584 607 def add_custom_fields_filters(custom_fields)
585 608 @available_filters ||= {}
586 609
587 610 custom_fields.select(&:is_filter?).each do |field|
588 611 case field.field_format
589 612 when "text"
590 613 options = { :type => :text, :order => 20 }
591 614 when "list"
592 615 options = { :type => :list_optional, :values => field.possible_values, :order => 20}
593 616 when "date"
594 617 options = { :type => :date, :order => 20 }
595 618 when "bool"
596 619 options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
597 620 else
598 621 options = { :type => :string, :order => 20 }
599 622 end
600 623 @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
601 624 end
602 625 end
603 626
604 627 # Returns a SQL clause for a date or datetime field.
605 628 def date_range_clause(table, field, from, to)
606 629 s = []
607 630 if from
608 631 s << ("#{table}.#{field} > '%s'" % [connection.quoted_date((Date.yesterday + from).to_time.end_of_day)])
609 632 end
610 633 if to
611 634 s << ("#{table}.#{field} <= '%s'" % [connection.quoted_date((Date.today + to).to_time.end_of_day)])
612 635 end
613 636 s.join(' AND ')
614 637 end
615 638 end
@@ -1,916 +1,917
1 1 en:
2 2 # Text direction: Left-to-Right (ltr) or Right-to-Left (rtl)
3 3 direction: ltr
4 4 date:
5 5 formats:
6 6 # Use the strftime parameters for formats.
7 7 # When no format has been given, it uses default.
8 8 # You can provide other formats here if you like!
9 9 default: "%m/%d/%Y"
10 10 short: "%b %d"
11 11 long: "%B %d, %Y"
12 12
13 13 day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
14 14 abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
15 15
16 16 # Don't forget the nil at the beginning; there's no such thing as a 0th month
17 17 month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
18 18 abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
19 19 # Used in date_select and datime_select.
20 20 order: [ :year, :month, :day ]
21 21
22 22 time:
23 23 formats:
24 24 default: "%m/%d/%Y %I:%M %p"
25 25 time: "%I:%M %p"
26 26 short: "%d %b %H:%M"
27 27 long: "%B %d, %Y %H:%M"
28 28 am: "am"
29 29 pm: "pm"
30 30
31 31 datetime:
32 32 distance_in_words:
33 33 half_a_minute: "half a minute"
34 34 less_than_x_seconds:
35 35 one: "less than 1 second"
36 36 other: "less than {{count}} seconds"
37 37 x_seconds:
38 38 one: "1 second"
39 39 other: "{{count}} seconds"
40 40 less_than_x_minutes:
41 41 one: "less than a minute"
42 42 other: "less than {{count}} minutes"
43 43 x_minutes:
44 44 one: "1 minute"
45 45 other: "{{count}} minutes"
46 46 about_x_hours:
47 47 one: "about 1 hour"
48 48 other: "about {{count}} hours"
49 49 x_days:
50 50 one: "1 day"
51 51 other: "{{count}} days"
52 52 about_x_months:
53 53 one: "about 1 month"
54 54 other: "about {{count}} months"
55 55 x_months:
56 56 one: "1 month"
57 57 other: "{{count}} months"
58 58 about_x_years:
59 59 one: "about 1 year"
60 60 other: "about {{count}} years"
61 61 over_x_years:
62 62 one: "over 1 year"
63 63 other: "over {{count}} years"
64 64 almost_x_years:
65 65 one: "almost 1 year"
66 66 other: "almost {{count}} years"
67 67
68 68 number:
69 69 # Default format for numbers
70 70 format:
71 71 separator: "."
72 72 delimiter: ""
73 73 precision: 3
74 74 human:
75 75 format:
76 76 delimiter: ""
77 77 precision: 1
78 78 storage_units:
79 79 format: "%n %u"
80 80 units:
81 81 byte:
82 82 one: "Byte"
83 83 other: "Bytes"
84 84 kb: "KB"
85 85 mb: "MB"
86 86 gb: "GB"
87 87 tb: "TB"
88 88
89 89
90 90 # Used in array.to_sentence.
91 91 support:
92 92 array:
93 93 sentence_connector: "and"
94 94 skip_last_comma: false
95 95
96 96 activerecord:
97 97 errors:
98 98 messages:
99 99 inclusion: "is not included in the list"
100 100 exclusion: "is reserved"
101 101 invalid: "is invalid"
102 102 confirmation: "doesn't match confirmation"
103 103 accepted: "must be accepted"
104 104 empty: "can't be empty"
105 105 blank: "can't be blank"
106 106 too_long: "is too long (maximum is {{count}} characters)"
107 107 too_short: "is too short (minimum is {{count}} characters)"
108 108 wrong_length: "is the wrong length (should be {{count}} characters)"
109 109 taken: "has already been taken"
110 110 not_a_number: "is not a number"
111 111 not_a_date: "is not a valid date"
112 112 greater_than: "must be greater than {{count}}"
113 113 greater_than_or_equal_to: "must be greater than or equal to {{count}}"
114 114 equal_to: "must be equal to {{count}}"
115 115 less_than: "must be less than {{count}}"
116 116 less_than_or_equal_to: "must be less than or equal to {{count}}"
117 117 odd: "must be odd"
118 118 even: "must be even"
119 119 greater_than_start_date: "must be greater than start date"
120 120 not_same_project: "doesn't belong to the same project"
121 121 circular_dependency: "This relation would create a circular dependency"
122 122 cant_link_an_issue_with_a_descendant: "An issue can not be linked to one of its subtasks"
123 123
124 124 actionview_instancetag_blank_option: Please select
125 125
126 126 general_text_No: 'No'
127 127 general_text_Yes: 'Yes'
128 128 general_text_no: 'no'
129 129 general_text_yes: 'yes'
130 130 general_lang_name: 'English'
131 131 general_csv_separator: ','
132 132 general_csv_decimal_separator: '.'
133 133 general_csv_encoding: ISO-8859-1
134 134 general_pdf_encoding: ISO-8859-1
135 135 general_first_day_of_week: '7'
136 136
137 137 notice_account_updated: Account was successfully updated.
138 138 notice_account_invalid_creditentials: Invalid user or password
139 139 notice_account_password_updated: Password was successfully updated.
140 140 notice_account_wrong_password: Wrong password
141 141 notice_account_register_done: Account was successfully created. To activate your account, click on the link that was emailed to you.
142 142 notice_account_unknown_email: Unknown user.
143 143 notice_can_t_change_password: This account uses an external authentication source. Impossible to change the password.
144 144 notice_account_lost_email_sent: An email with instructions to choose a new password has been sent to you.
145 145 notice_account_activated: Your account has been activated. You can now log in.
146 146 notice_successful_create: Successful creation.
147 147 notice_successful_update: Successful update.
148 148 notice_successful_delete: Successful deletion.
149 149 notice_successful_connection: Successful connection.
150 150 notice_file_not_found: The page you were trying to access doesn't exist or has been removed.
151 151 notice_locking_conflict: Data has been updated by another user.
152 152 notice_not_authorized: You are not authorized to access this page.
153 153 notice_email_sent: "An email was sent to {{value}}"
154 154 notice_email_error: "An error occurred while sending mail ({{value}})"
155 155 notice_feeds_access_key_reseted: Your RSS access key was reset.
156 156 notice_api_access_key_reseted: Your API access key was reset.
157 157 notice_failed_to_save_issues: "Failed to save {{count}} issue(s) on {{total}} selected: {{ids}}."
158 158 notice_failed_to_save_members: "Failed to save member(s): {{errors}}."
159 159 notice_no_issue_selected: "No issue is selected! Please, check the issues you want to edit."
160 160 notice_account_pending: "Your account was created and is now pending administrator approval."
161 161 notice_default_data_loaded: Default configuration successfully loaded.
162 162 notice_unable_delete_version: Unable to delete version.
163 163 notice_unable_delete_time_entry: Unable to delete time log entry.
164 164 notice_issue_done_ratios_updated: Issue done ratios updated.
165 165
166 166 error_can_t_load_default_data: "Default configuration could not be loaded: {{value}}"
167 167 error_scm_not_found: "The entry or revision was not found in the repository."
168 168 error_scm_command_failed: "An error occurred when trying to access the repository: {{value}}"
169 169 error_scm_annotate: "The entry does not exist or can not be annotated."
170 170 error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
171 171 error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.'
172 172 error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
173 173 error_can_not_delete_custom_field: Unable to delete custom field
174 174 error_can_not_delete_tracker: "This tracker contains issues and can't be deleted."
175 175 error_can_not_remove_role: "This role is in use and can not be deleted."
176 176 error_can_not_reopen_issue_on_closed_version: 'An issue assigned to a closed version can not be reopened'
177 177 error_can_not_archive_project: This project can not be archived
178 178 error_issue_done_ratios_not_updated: "Issue done ratios not updated."
179 179 error_workflow_copy_source: 'Please select a source tracker or role'
180 180 error_workflow_copy_target: 'Please select target tracker(s) and role(s)'
181 181 error_unable_delete_issue_status: 'Unable to delete issue status'
182 182 error_unable_to_connect: "Unable to connect ({{value}})"
183 183 warning_attachments_not_saved: "{{count}} file(s) could not be saved."
184 184
185 185 mail_subject_lost_password: "Your {{value}} password"
186 186 mail_body_lost_password: 'To change your password, click on the following link:'
187 187 mail_subject_register: "Your {{value}} account activation"
188 188 mail_body_register: 'To activate your account, click on the following link:'
189 189 mail_body_account_information_external: "You can use your {{value}} account to log in."
190 190 mail_body_account_information: Your account information
191 191 mail_subject_account_activation_request: "{{value}} account activation request"
192 192 mail_body_account_activation_request: "A new user ({{value}}) has registered. The account is pending your approval:"
193 193 mail_subject_reminder: "{{count}} issue(s) due in the next {{days}} days"
194 194 mail_body_reminder: "{{count}} issue(s) that are assigned to you are due in the next {{days}} days:"
195 195 mail_subject_wiki_content_added: "'{{page}}' wiki page has been added"
196 196 mail_body_wiki_content_added: "The '{{page}}' wiki page has been added by {{author}}."
197 197 mail_subject_wiki_content_updated: "'{{page}}' wiki page has been updated"
198 198 mail_body_wiki_content_updated: "The '{{page}}' wiki page has been updated by {{author}}."
199 199
200 200 gui_validation_error: 1 error
201 201 gui_validation_error_plural: "{{count}} errors"
202 202
203 203 field_name: Name
204 204 field_description: Description
205 205 field_summary: Summary
206 206 field_is_required: Required
207 207 field_firstname: Firstname
208 208 field_lastname: Lastname
209 209 field_mail: Email
210 210 field_filename: File
211 211 field_filesize: Size
212 212 field_downloads: Downloads
213 213 field_author: Author
214 214 field_created_on: Created
215 215 field_updated_on: Updated
216 216 field_field_format: Format
217 217 field_is_for_all: For all projects
218 218 field_possible_values: Possible values
219 219 field_regexp: Regular expression
220 220 field_min_length: Minimum length
221 221 field_max_length: Maximum length
222 222 field_value: Value
223 223 field_category: Category
224 224 field_title: Title
225 225 field_project: Project
226 226 field_issue: Issue
227 227 field_status: Status
228 228 field_notes: Notes
229 229 field_is_closed: Issue closed
230 230 field_is_default: Default value
231 231 field_tracker: Tracker
232 232 field_subject: Subject
233 233 field_due_date: Due date
234 234 field_assigned_to: Assignee
235 235 field_priority: Priority
236 236 field_fixed_version: Target version
237 237 field_user: User
238 238 field_principal: Principal
239 239 field_role: Role
240 240 field_homepage: Homepage
241 241 field_is_public: Public
242 242 field_parent: Subproject of
243 243 field_is_in_roadmap: Issues displayed in roadmap
244 244 field_login: Login
245 245 field_mail_notification: Email notifications
246 246 field_admin: Administrator
247 247 field_last_login_on: Last connection
248 248 field_language: Language
249 249 field_effective_date: Date
250 250 field_password: Password
251 251 field_new_password: New password
252 252 field_password_confirmation: Confirmation
253 253 field_version: Version
254 254 field_type: Type
255 255 field_host: Host
256 256 field_port: Port
257 257 field_account: Account
258 258 field_base_dn: Base DN
259 259 field_attr_login: Login attribute
260 260 field_attr_firstname: Firstname attribute
261 261 field_attr_lastname: Lastname attribute
262 262 field_attr_mail: Email attribute
263 263 field_onthefly: On-the-fly user creation
264 264 field_start_date: Start
265 265 field_done_ratio: % Done
266 266 field_auth_source: Authentication mode
267 267 field_hide_mail: Hide my email address
268 268 field_comments: Comment
269 269 field_url: URL
270 270 field_start_page: Start page
271 271 field_subproject: Subproject
272 272 field_hours: Hours
273 273 field_activity: Activity
274 274 field_spent_on: Date
275 275 field_identifier: Identifier
276 276 field_is_filter: Used as a filter
277 277 field_issue_to: Related issue
278 278 field_delay: Delay
279 279 field_assignable: Issues can be assigned to this role
280 280 field_redirect_existing_links: Redirect existing links
281 281 field_estimated_hours: Estimated time
282 282 field_column_names: Columns
283 283 field_time_entries: Log time
284 284 field_time_zone: Time zone
285 285 field_searchable: Searchable
286 286 field_default_value: Default value
287 287 field_comments_sorting: Display comments
288 288 field_parent_title: Parent page
289 289 field_editable: Editable
290 290 field_watcher: Watcher
291 291 field_identity_url: OpenID URL
292 292 field_content: Content
293 293 field_group_by: Group results by
294 294 field_sharing: Sharing
295 295 field_parent_issue: Parent task
296 296 field_member_of_group: Member of Group
297 field_assigned_to_role: Member of Role
297 298
298 299 setting_app_title: Application title
299 300 setting_app_subtitle: Application subtitle
300 301 setting_welcome_text: Welcome text
301 302 setting_default_language: Default language
302 303 setting_login_required: Authentication required
303 304 setting_self_registration: Self-registration
304 305 setting_attachment_max_size: Attachment max. size
305 306 setting_issues_export_limit: Issues export limit
306 307 setting_mail_from: Emission email address
307 308 setting_bcc_recipients: Blind carbon copy recipients (bcc)
308 309 setting_plain_text_mail: Plain text mail (no HTML)
309 310 setting_host_name: Host name and path
310 311 setting_text_formatting: Text formatting
311 312 setting_wiki_compression: Wiki history compression
312 313 setting_feeds_limit: Feed content limit
313 314 setting_default_projects_public: New projects are public by default
314 315 setting_autofetch_changesets: Autofetch commits
315 316 setting_sys_api_enabled: Enable WS for repository management
316 317 setting_commit_ref_keywords: Referencing keywords
317 318 setting_commit_fix_keywords: Fixing keywords
318 319 setting_autologin: Autologin
319 320 setting_date_format: Date format
320 321 setting_time_format: Time format
321 322 setting_cross_project_issue_relations: Allow cross-project issue relations
322 323 setting_issue_list_default_columns: Default columns displayed on the issue list
323 324 setting_repositories_encodings: Repositories encodings
324 325 setting_commit_logs_encoding: Commit messages encoding
325 326 setting_emails_footer: Emails footer
326 327 setting_protocol: Protocol
327 328 setting_per_page_options: Objects per page options
328 329 setting_user_format: Users display format
329 330 setting_activity_days_default: Days displayed on project activity
330 331 setting_display_subprojects_issues: Display subprojects issues on main projects by default
331 332 setting_enabled_scm: Enabled SCM
332 333 setting_mail_handler_body_delimiters: "Truncate emails after one of these lines"
333 334 setting_mail_handler_api_enabled: Enable WS for incoming emails
334 335 setting_mail_handler_api_key: API key
335 336 setting_sequential_project_identifiers: Generate sequential project identifiers
336 337 setting_gravatar_enabled: Use Gravatar user icons
337 338 setting_gravatar_default: Default Gravatar image
338 339 setting_diff_max_lines_displayed: Max number of diff lines displayed
339 340 setting_file_max_size_displayed: Max size of text files displayed inline
340 341 setting_repository_log_display_limit: Maximum number of revisions displayed on file log
341 342 setting_openid: Allow OpenID login and registration
342 343 setting_password_min_length: Minimum password length
343 344 setting_new_project_user_role_id: Role given to a non-admin user who creates a project
344 345 setting_default_projects_modules: Default enabled modules for new projects
345 346 setting_issue_done_ratio: Calculate the issue done ratio with
346 347 setting_issue_done_ratio_issue_field: Use the issue field
347 348 setting_issue_done_ratio_issue_status: Use the issue status
348 349 setting_start_of_week: Start calendars on
349 350 setting_rest_api_enabled: Enable REST web service
350 351 setting_cache_formatted_text: Cache formatted text
351 352
352 353 permission_add_project: Create project
353 354 permission_add_subprojects: Create subprojects
354 355 permission_edit_project: Edit project
355 356 permission_select_project_modules: Select project modules
356 357 permission_manage_members: Manage members
357 358 permission_manage_project_activities: Manage project activities
358 359 permission_manage_versions: Manage versions
359 360 permission_manage_categories: Manage issue categories
360 361 permission_view_issues: View Issues
361 362 permission_add_issues: Add issues
362 363 permission_edit_issues: Edit issues
363 364 permission_manage_issue_relations: Manage issue relations
364 365 permission_add_issue_notes: Add notes
365 366 permission_edit_issue_notes: Edit notes
366 367 permission_edit_own_issue_notes: Edit own notes
367 368 permission_move_issues: Move issues
368 369 permission_delete_issues: Delete issues
369 370 permission_manage_public_queries: Manage public queries
370 371 permission_save_queries: Save queries
371 372 permission_view_gantt: View gantt chart
372 373 permission_view_calendar: View calendar
373 374 permission_view_issue_watchers: View watchers list
374 375 permission_add_issue_watchers: Add watchers
375 376 permission_delete_issue_watchers: Delete watchers
376 377 permission_log_time: Log spent time
377 378 permission_view_time_entries: View spent time
378 379 permission_edit_time_entries: Edit time logs
379 380 permission_edit_own_time_entries: Edit own time logs
380 381 permission_manage_news: Manage news
381 382 permission_comment_news: Comment news
382 383 permission_manage_documents: Manage documents
383 384 permission_view_documents: View documents
384 385 permission_manage_files: Manage files
385 386 permission_view_files: View files
386 387 permission_manage_wiki: Manage wiki
387 388 permission_rename_wiki_pages: Rename wiki pages
388 389 permission_delete_wiki_pages: Delete wiki pages
389 390 permission_view_wiki_pages: View wiki
390 391 permission_view_wiki_edits: View wiki history
391 392 permission_edit_wiki_pages: Edit wiki pages
392 393 permission_delete_wiki_pages_attachments: Delete attachments
393 394 permission_protect_wiki_pages: Protect wiki pages
394 395 permission_manage_repository: Manage repository
395 396 permission_browse_repository: Browse repository
396 397 permission_view_changesets: View changesets
397 398 permission_commit_access: Commit access
398 399 permission_manage_boards: Manage boards
399 400 permission_view_messages: View messages
400 401 permission_add_messages: Post messages
401 402 permission_edit_messages: Edit messages
402 403 permission_edit_own_messages: Edit own messages
403 404 permission_delete_messages: Delete messages
404 405 permission_delete_own_messages: Delete own messages
405 406 permission_export_wiki_pages: Export wiki pages
406 407 permission_manage_subtasks: Manage subtasks
407 408
408 409 project_module_issue_tracking: Issue tracking
409 410 project_module_time_tracking: Time tracking
410 411 project_module_news: News
411 412 project_module_documents: Documents
412 413 project_module_files: Files
413 414 project_module_wiki: Wiki
414 415 project_module_repository: Repository
415 416 project_module_boards: Boards
416 417 project_module_calendar: Calendar
417 418 project_module_gantt: Gantt
418 419
419 420 label_user: User
420 421 label_user_plural: Users
421 422 label_user_new: New user
422 423 label_user_anonymous: Anonymous
423 424 label_project: Project
424 425 label_project_new: New project
425 426 label_project_plural: Projects
426 427 label_x_projects:
427 428 zero: no projects
428 429 one: 1 project
429 430 other: "{{count}} projects"
430 431 label_project_all: All Projects
431 432 label_project_latest: Latest projects
432 433 label_issue: Issue
433 434 label_issue_new: New issue
434 435 label_issue_plural: Issues
435 436 label_issue_view_all: View all issues
436 437 label_issues_by: "Issues by {{value}}"
437 438 label_issue_added: Issue added
438 439 label_issue_updated: Issue updated
439 440 label_document: Document
440 441 label_document_new: New document
441 442 label_document_plural: Documents
442 443 label_document_added: Document added
443 444 label_role: Role
444 445 label_role_plural: Roles
445 446 label_role_new: New role
446 447 label_role_and_permissions: Roles and permissions
447 448 label_member: Member
448 449 label_member_new: New member
449 450 label_member_plural: Members
450 451 label_tracker: Tracker
451 452 label_tracker_plural: Trackers
452 453 label_tracker_new: New tracker
453 454 label_workflow: Workflow
454 455 label_issue_status: Issue status
455 456 label_issue_status_plural: Issue statuses
456 457 label_issue_status_new: New status
457 458 label_issue_category: Issue category
458 459 label_issue_category_plural: Issue categories
459 460 label_issue_category_new: New category
460 461 label_custom_field: Custom field
461 462 label_custom_field_plural: Custom fields
462 463 label_custom_field_new: New custom field
463 464 label_enumerations: Enumerations
464 465 label_enumeration_new: New value
465 466 label_information: Information
466 467 label_information_plural: Information
467 468 label_please_login: Please log in
468 469 label_register: Register
469 470 label_login_with_open_id_option: or login with OpenID
470 471 label_password_lost: Lost password
471 472 label_home: Home
472 473 label_my_page: My page
473 474 label_my_account: My account
474 475 label_my_projects: My projects
475 476 label_my_page_block: My page block
476 477 label_administration: Administration
477 478 label_login: Sign in
478 479 label_logout: Sign out
479 480 label_help: Help
480 481 label_reported_issues: Reported issues
481 482 label_assigned_to_me_issues: Issues assigned to me
482 483 label_last_login: Last connection
483 484 label_registered_on: Registered on
484 485 label_activity: Activity
485 486 label_overall_activity: Overall activity
486 487 label_user_activity: "{{value}}'s activity"
487 488 label_new: New
488 489 label_logged_as: Logged in as
489 490 label_environment: Environment
490 491 label_authentication: Authentication
491 492 label_auth_source: Authentication mode
492 493 label_auth_source_new: New authentication mode
493 494 label_auth_source_plural: Authentication modes
494 495 label_subproject_plural: Subprojects
495 496 label_subproject_new: New subproject
496 497 label_and_its_subprojects: "{{value}} and its subprojects"
497 498 label_min_max_length: Min - Max length
498 499 label_list: List
499 500 label_date: Date
500 501 label_integer: Integer
501 502 label_float: Float
502 503 label_boolean: Boolean
503 504 label_string: Text
504 505 label_text: Long text
505 506 label_attribute: Attribute
506 507 label_attribute_plural: Attributes
507 508 label_download: "{{count}} Download"
508 509 label_download_plural: "{{count}} Downloads"
509 510 label_no_data: No data to display
510 511 label_change_status: Change status
511 512 label_history: History
512 513 label_attachment: File
513 514 label_attachment_new: New file
514 515 label_attachment_delete: Delete file
515 516 label_attachment_plural: Files
516 517 label_file_added: File added
517 518 label_report: Report
518 519 label_report_plural: Reports
519 520 label_news: News
520 521 label_news_new: Add news
521 522 label_news_plural: News
522 523 label_news_latest: Latest news
523 524 label_news_view_all: View all news
524 525 label_news_added: News added
525 526 label_settings: Settings
526 527 label_overview: Overview
527 528 label_version: Version
528 529 label_version_new: New version
529 530 label_version_plural: Versions
530 531 label_close_versions: Close completed versions
531 532 label_confirmation: Confirmation
532 533 label_export_to: 'Also available in:'
533 534 label_read: Read...
534 535 label_public_projects: Public projects
535 536 label_open_issues: open
536 537 label_open_issues_plural: open
537 538 label_closed_issues: closed
538 539 label_closed_issues_plural: closed
539 540 label_x_open_issues_abbr_on_total:
540 541 zero: 0 open / {{total}}
541 542 one: 1 open / {{total}}
542 543 other: "{{count}} open / {{total}}"
543 544 label_x_open_issues_abbr:
544 545 zero: 0 open
545 546 one: 1 open
546 547 other: "{{count}} open"
547 548 label_x_closed_issues_abbr:
548 549 zero: 0 closed
549 550 one: 1 closed
550 551 other: "{{count}} closed"
551 552 label_total: Total
552 553 label_permissions: Permissions
553 554 label_current_status: Current status
554 555 label_new_statuses_allowed: New statuses allowed
555 556 label_all: all
556 557 label_none: none
557 558 label_nobody: nobody
558 559 label_next: Next
559 560 label_previous: Previous
560 561 label_used_by: Used by
561 562 label_details: Details
562 563 label_add_note: Add a note
563 564 label_per_page: Per page
564 565 label_calendar: Calendar
565 566 label_months_from: months from
566 567 label_gantt: Gantt
567 568 label_internal: Internal
568 569 label_last_changes: "last {{count}} changes"
569 570 label_change_view_all: View all changes
570 571 label_personalize_page: Personalize this page
571 572 label_comment: Comment
572 573 label_comment_plural: Comments
573 574 label_x_comments:
574 575 zero: no comments
575 576 one: 1 comment
576 577 other: "{{count}} comments"
577 578 label_comment_add: Add a comment
578 579 label_comment_added: Comment added
579 580 label_comment_delete: Delete comments
580 581 label_query: Custom query
581 582 label_query_plural: Custom queries
582 583 label_query_new: New query
583 584 label_filter_add: Add filter
584 585 label_filter_plural: Filters
585 586 label_equals: is
586 587 label_not_equals: is not
587 588 label_in_less_than: in less than
588 589 label_in_more_than: in more than
589 590 label_greater_or_equal: '>='
590 591 label_less_or_equal: '<='
591 592 label_in: in
592 593 label_today: today
593 594 label_all_time: all time
594 595 label_yesterday: yesterday
595 596 label_this_week: this week
596 597 label_last_week: last week
597 598 label_last_n_days: "last {{count}} days"
598 599 label_this_month: this month
599 600 label_last_month: last month
600 601 label_this_year: this year
601 602 label_date_range: Date range
602 603 label_less_than_ago: less than days ago
603 604 label_more_than_ago: more than days ago
604 605 label_ago: days ago
605 606 label_contains: contains
606 607 label_not_contains: doesn't contain
607 608 label_day_plural: days
608 609 label_repository: Repository
609 610 label_repository_plural: Repositories
610 611 label_browse: Browse
611 612 label_modification: "{{count}} change"
612 613 label_modification_plural: "{{count}} changes"
613 614 label_branch: Branch
614 615 label_tag: Tag
615 616 label_revision: Revision
616 617 label_revision_plural: Revisions
617 618 label_revision_id: "Revision {{value}}"
618 619 label_associated_revisions: Associated revisions
619 620 label_added: added
620 621 label_modified: modified
621 622 label_copied: copied
622 623 label_renamed: renamed
623 624 label_deleted: deleted
624 625 label_latest_revision: Latest revision
625 626 label_latest_revision_plural: Latest revisions
626 627 label_view_revisions: View revisions
627 628 label_view_all_revisions: View all revisions
628 629 label_max_size: Maximum size
629 630 label_sort_highest: Move to top
630 631 label_sort_higher: Move up
631 632 label_sort_lower: Move down
632 633 label_sort_lowest: Move to bottom
633 634 label_roadmap: Roadmap
634 635 label_roadmap_due_in: "Due in {{value}}"
635 636 label_roadmap_overdue: "{{value}} late"
636 637 label_roadmap_no_issues: No issues for this version
637 638 label_search: Search
638 639 label_result_plural: Results
639 640 label_all_words: All words
640 641 label_wiki: Wiki
641 642 label_wiki_edit: Wiki edit
642 643 label_wiki_edit_plural: Wiki edits
643 644 label_wiki_page: Wiki page
644 645 label_wiki_page_plural: Wiki pages
645 646 label_index_by_title: Index by title
646 647 label_index_by_date: Index by date
647 648 label_current_version: Current version
648 649 label_preview: Preview
649 650 label_feed_plural: Feeds
650 651 label_changes_details: Details of all changes
651 652 label_issue_tracking: Issue tracking
652 653 label_spent_time: Spent time
653 654 label_overall_spent_time: Overall spent time
654 655 label_f_hour: "{{value}} hour"
655 656 label_f_hour_plural: "{{value}} hours"
656 657 label_time_tracking: Time tracking
657 658 label_change_plural: Changes
658 659 label_statistics: Statistics
659 660 label_commits_per_month: Commits per month
660 661 label_commits_per_author: Commits per author
661 662 label_view_diff: View differences
662 663 label_diff_inline: inline
663 664 label_diff_side_by_side: side by side
664 665 label_options: Options
665 666 label_copy_workflow_from: Copy workflow from
666 667 label_permissions_report: Permissions report
667 668 label_watched_issues: Watched issues
668 669 label_related_issues: Related issues
669 670 label_applied_status: Applied status
670 671 label_loading: Loading...
671 672 label_relation_new: New relation
672 673 label_relation_delete: Delete relation
673 674 label_relates_to: related to
674 675 label_duplicates: duplicates
675 676 label_duplicated_by: duplicated by
676 677 label_blocks: blocks
677 678 label_blocked_by: blocked by
678 679 label_precedes: precedes
679 680 label_follows: follows
680 681 label_end_to_start: end to start
681 682 label_end_to_end: end to end
682 683 label_start_to_start: start to start
683 684 label_start_to_end: start to end
684 685 label_stay_logged_in: Stay logged in
685 686 label_disabled: disabled
686 687 label_show_completed_versions: Show completed versions
687 688 label_me: me
688 689 label_board: Forum
689 690 label_board_new: New forum
690 691 label_board_plural: Forums
691 692 label_board_locked: Locked
692 693 label_board_sticky: Sticky
693 694 label_topic_plural: Topics
694 695 label_message_plural: Messages
695 696 label_message_last: Last message
696 697 label_message_new: New message
697 698 label_message_posted: Message added
698 699 label_reply_plural: Replies
699 700 label_send_information: Send account information to the user
700 701 label_year: Year
701 702 label_month: Month
702 703 label_week: Week
703 704 label_date_from: From
704 705 label_date_to: To
705 706 label_language_based: Based on user's language
706 707 label_sort_by: "Sort by {{value}}"
707 708 label_send_test_email: Send a test email
708 709 label_feeds_access_key: RSS access key
709 710 label_missing_feeds_access_key: Missing a RSS access key
710 711 label_feeds_access_key_created_on: "RSS access key created {{value}} ago"
711 712 label_module_plural: Modules
712 713 label_added_time_by: "Added by {{author}} {{age}} ago"
713 714 label_updated_time_by: "Updated by {{author}} {{age}} ago"
714 715 label_updated_time: "Updated {{value}} ago"
715 716 label_jump_to_a_project: Jump to a project...
716 717 label_file_plural: Files
717 718 label_changeset_plural: Changesets
718 719 label_default_columns: Default columns
719 720 label_no_change_option: (No change)
720 721 label_bulk_edit_selected_issues: Bulk edit selected issues
721 722 label_theme: Theme
722 723 label_default: Default
723 724 label_search_titles_only: Search titles only
724 725 label_user_mail_option_all: "For any event on all my projects"
725 726 label_user_mail_option_selected: "For any event on the selected projects only..."
726 727 label_user_mail_option_none: "Only for things I watch or I'm involved in"
727 728 label_user_mail_no_self_notified: "I don't want to be notified of changes that I make myself"
728 729 label_registration_activation_by_email: account activation by email
729 730 label_registration_manual_activation: manual account activation
730 731 label_registration_automatic_activation: automatic account activation
731 732 label_display_per_page: "Per page: {{value}}"
732 733 label_age: Age
733 734 label_change_properties: Change properties
734 735 label_general: General
735 736 label_more: More
736 737 label_scm: SCM
737 738 label_plugins: Plugins
738 739 label_ldap_authentication: LDAP authentication
739 740 label_downloads_abbr: D/L
740 741 label_optional_description: Optional description
741 742 label_add_another_file: Add another file
742 743 label_preferences: Preferences
743 744 label_chronological_order: In chronological order
744 745 label_reverse_chronological_order: In reverse chronological order
745 746 label_planning: Planning
746 747 label_incoming_emails: Incoming emails
747 748 label_generate_key: Generate a key
748 749 label_issue_watchers: Watchers
749 750 label_example: Example
750 751 label_display: Display
751 752 label_sort: Sort
752 753 label_ascending: Ascending
753 754 label_descending: Descending
754 755 label_date_from_to: From {{start}} to {{end}}
755 756 label_wiki_content_added: Wiki page added
756 757 label_wiki_content_updated: Wiki page updated
757 758 label_group: Group
758 759 label_group_plural: Groups
759 760 label_group_new: New group
760 761 label_time_entry_plural: Spent time
761 762 label_version_sharing_none: Not shared
762 763 label_version_sharing_descendants: With subprojects
763 764 label_version_sharing_hierarchy: With project hierarchy
764 765 label_version_sharing_tree: With project tree
765 766 label_version_sharing_system: With all projects
766 767 label_update_issue_done_ratios: Update issue done ratios
767 768 label_copy_source: Source
768 769 label_copy_target: Target
769 770 label_copy_same_as_target: Same as target
770 771 label_display_used_statuses_only: Only display statuses that are used by this tracker
771 772 label_api_access_key: API access key
772 773 label_missing_api_access_key: Missing an API access key
773 774 label_api_access_key_created_on: "API access key created {{value}} ago"
774 775 label_profile: Profile
775 776 label_subtask_plural: Subtasks
776 777 label_project_copy_notifications: Send email notifications during the project copy
777 778
778 779 button_login: Login
779 780 button_submit: Submit
780 781 button_save: Save
781 782 button_check_all: Check all
782 783 button_uncheck_all: Uncheck all
783 784 button_delete: Delete
784 785 button_create: Create
785 786 button_create_and_continue: Create and continue
786 787 button_test: Test
787 788 button_edit: Edit
788 789 button_add: Add
789 790 button_change: Change
790 791 button_apply: Apply
791 792 button_clear: Clear
792 793 button_lock: Lock
793 794 button_unlock: Unlock
794 795 button_download: Download
795 796 button_list: List
796 797 button_view: View
797 798 button_move: Move
798 799 button_move_and_follow: Move and follow
799 800 button_back: Back
800 801 button_cancel: Cancel
801 802 button_activate: Activate
802 803 button_sort: Sort
803 804 button_log_time: Log time
804 805 button_rollback: Rollback to this version
805 806 button_watch: Watch
806 807 button_unwatch: Unwatch
807 808 button_reply: Reply
808 809 button_archive: Archive
809 810 button_unarchive: Unarchive
810 811 button_reset: Reset
811 812 button_rename: Rename
812 813 button_change_password: Change password
813 814 button_copy: Copy
814 815 button_copy_and_follow: Copy and follow
815 816 button_annotate: Annotate
816 817 button_update: Update
817 818 button_configure: Configure
818 819 button_quote: Quote
819 820 button_duplicate: Duplicate
820 821 button_show: Show
821 822
822 823 status_active: active
823 824 status_registered: registered
824 825 status_locked: locked
825 826
826 827 version_status_open: open
827 828 version_status_locked: locked
828 829 version_status_closed: closed
829 830
830 831 field_active: Active
831 832
832 833 text_select_mail_notifications: Select actions for which email notifications should be sent.
833 834 text_regexp_info: eg. ^[A-Z0-9]+$
834 835 text_min_max_length_info: 0 means no restriction
835 836 text_project_destroy_confirmation: Are you sure you want to delete this project and related data ?
836 837 text_subprojects_destroy_warning: "Its subproject(s): {{value}} will be also deleted."
837 838 text_workflow_edit: Select a role and a tracker to edit the workflow
838 839 text_are_you_sure: Are you sure ?
839 840 text_journal_changed: "{{label}} changed from {{old}} to {{new}}"
840 841 text_journal_set_to: "{{label}} set to {{value}}"
841 842 text_journal_deleted: "{{label}} deleted ({{old}})"
842 843 text_journal_added: "{{label}} {{value}} added"
843 844 text_tip_task_begin_day: task beginning this day
844 845 text_tip_task_end_day: task ending this day
845 846 text_tip_task_begin_end_day: task beginning and ending this day
846 847 text_project_identifier_info: 'Only lower case letters (a-z), numbers and dashes are allowed.<br />Once saved, the identifier can not be changed.'
847 848 text_caracters_maximum: "{{count}} characters maximum."
848 849 text_caracters_minimum: "Must be at least {{count}} characters long."
849 850 text_length_between: "Length between {{min}} and {{max}} characters."
850 851 text_tracker_no_workflow: No workflow defined for this tracker
851 852 text_unallowed_characters: Unallowed characters
852 853 text_comma_separated: Multiple values allowed (comma separated).
853 854 text_line_separated: Multiple values allowed (one line for each value).
854 855 text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages
855 856 text_issue_added: "Issue {{id}} has been reported by {{author}}."
856 857 text_issue_updated: "Issue {{id}} has been updated by {{author}}."
857 858 text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content ?
858 859 text_issue_category_destroy_question: "Some issues ({{count}}) are assigned to this category. What do you want to do ?"
859 860 text_issue_category_destroy_assignments: Remove category assignments
860 861 text_issue_category_reassign_to: Reassign issues to this category
861 862 text_user_mail_option: "For unselected projects, you will only receive notifications about things you watch or you're involved in (eg. issues you're the author or assignee)."
862 863 text_no_configuration_data: "Roles, trackers, issue statuses and workflow have not been configured yet.\nIt is highly recommended to load the default configuration. You will be able to modify it once loaded."
863 864 text_load_default_configuration: Load the default configuration
864 865 text_status_changed_by_changeset: "Applied in changeset {{value}}."
865 866 text_issues_destroy_confirmation: 'Are you sure you want to delete the selected issue(s) ?'
866 867 text_select_project_modules: 'Select modules to enable for this project:'
867 868 text_default_administrator_account_changed: Default administrator account changed
868 869 text_file_repository_writable: Attachments directory writable
869 870 text_plugin_assets_writable: Plugin assets directory writable
870 871 text_rmagick_available: RMagick available (optional)
871 872 text_destroy_time_entries_question: "{{hours}} hours were reported on the issues you are about to delete. What do you want to do ?"
872 873 text_destroy_time_entries: Delete reported hours
873 874 text_assign_time_entries_to_project: Assign reported hours to the project
874 875 text_reassign_time_entries: 'Reassign reported hours to this issue:'
875 876 text_user_wrote: "{{value}} wrote:"
876 877 text_enumeration_destroy_question: "{{count}} objects are assigned to this value."
877 878 text_enumeration_category_reassign_to: 'Reassign them to this value:'
878 879 text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
879 880 text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
880 881 text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
881 882 text_custom_field_possible_values_info: 'One line for each value'
882 883 text_wiki_page_destroy_question: "This page has {{descendants}} child page(s) and descendant(s). What do you want to do?"
883 884 text_wiki_page_nullify_children: "Keep child pages as root pages"
884 885 text_wiki_page_destroy_children: "Delete child pages and all their descendants"
885 886 text_wiki_page_reassign_children: "Reassign child pages to this parent page"
886 887 text_own_membership_delete_confirmation: "You are about to remove some or all of your permissions and may no longer be able to edit this project after that.\nAre you sure you want to continue?"
887 888 text_zoom_in: Zoom in
888 889 text_zoom_out: Zoom out
889 890
890 891 default_role_manager: Manager
891 892 default_role_developer: Developer
892 893 default_role_reporter: Reporter
893 894 default_tracker_bug: Bug
894 895 default_tracker_feature: Feature
895 896 default_tracker_support: Support
896 897 default_issue_status_new: New
897 898 default_issue_status_in_progress: In Progress
898 899 default_issue_status_resolved: Resolved
899 900 default_issue_status_feedback: Feedback
900 901 default_issue_status_closed: Closed
901 902 default_issue_status_rejected: Rejected
902 903 default_doc_category_user: User documentation
903 904 default_doc_category_tech: Technical documentation
904 905 default_priority_low: Low
905 906 default_priority_normal: Normal
906 907 default_priority_high: High
907 908 default_priority_urgent: Urgent
908 909 default_priority_immediate: Immediate
909 910 default_activity_design: Design
910 911 default_activity_development: Development
911 912
912 913 enumeration_issue_priorities: Issue priorities
913 914 enumeration_doc_categories: Document categories
914 915 enumeration_activities: Activities (time tracking)
915 916 enumeration_system_activity: System Activity
916 917
@@ -1,35 +1,40
1 1 module ObjectDaddyHelpers
2 2 # TODO: Remove these three once everyone has ported their code to use the
3 3 # new object_daddy version with protected attribute support
4 4 def User.generate_with_protected(attributes={})
5 5 User.generate(attributes)
6 6 end
7 7
8 8 def User.generate_with_protected!(attributes={})
9 9 User.generate!(attributes)
10 10 end
11 11
12 12 def User.spawn_with_protected(attributes={})
13 13 User.spawn(attributes)
14 14 end
15 15
16 def User.add_to_project(user, project, roles)
17 roles = [roles] unless roles.is_a?(Array)
18 Member.generate!(:principal => user, :project => project, :roles => roles)
19 end
20
16 21 # Generate the default Query
17 22 def Query.generate_default!(attributes={})
18 23 query = Query.spawn(attributes)
19 24 query.name ||= '_'
20 25 query.save!
21 26 query
22 27 end
23 28
24 29 # Generate an issue for a project, using it's trackers
25 30 def Issue.generate_for_project!(project, attributes={})
26 31 issue = Issue.spawn(attributes) do |issue|
27 32 issue.project = project
28 33 issue.tracker = project.trackers.first unless project.trackers.empty?
29 34 yield issue if block_given?
30 35 end
31 36 issue.save!
32 37 issue
33 38 end
34 39
35 40 end
@@ -1,458 +1,524
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class QueryTest < ActiveSupport::TestCase
21 21 fixtures :projects, :enabled_modules, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :watchers, :custom_fields, :custom_values, :versions, :queries
22 22
23 23 def test_custom_fields_for_all_projects_should_be_available_in_global_queries
24 24 query = Query.new(:project => nil, :name => '_')
25 25 assert query.available_filters.has_key?('cf_1')
26 26 assert !query.available_filters.has_key?('cf_3')
27 27 end
28 28
29 29 def test_system_shared_versions_should_be_available_in_global_queries
30 30 Version.find(2).update_attribute :sharing, 'system'
31 31 query = Query.new(:project => nil, :name => '_')
32 32 assert query.available_filters.has_key?('fixed_version_id')
33 33 assert query.available_filters['fixed_version_id'][:values].detect {|v| v.last == '2'}
34 34 end
35 35
36 36 def test_project_filter_in_global_queries
37 37 query = Query.new(:project => nil, :name => '_')
38 38 project_filter = query.available_filters["project_id"]
39 39 assert_not_nil project_filter
40 40 project_ids = project_filter[:values].map{|p| p[1]}
41 41 assert project_ids.include?("1") #public project
42 42 assert !project_ids.include?("2") #private project user cannot see
43 43 end
44 44
45 45 def find_issues_with_query(query)
46 46 Issue.find :all,
47 47 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
48 48 :conditions => query.statement
49 49 end
50 50
51 51 def assert_find_issues_with_query_is_successful(query)
52 52 assert_nothing_raised do
53 53 find_issues_with_query(query)
54 54 end
55 55 end
56 56
57 57 def assert_query_statement_includes(query, condition)
58 58 assert query.statement.include?(condition), "Query statement condition not found in: #{query.statement}"
59 59 end
60 60
61 61 def test_query_should_allow_shared_versions_for_a_project_query
62 62 subproject_version = Version.find(4)
63 63 query = Query.new(:project => Project.find(1), :name => '_')
64 64 query.add_filter('fixed_version_id', '=', [subproject_version.id.to_s])
65 65
66 66 assert query.statement.include?("#{Issue.table_name}.fixed_version_id IN ('4')")
67 67 end
68 68
69 69 def test_query_with_multiple_custom_fields
70 70 query = Query.find(1)
71 71 assert query.valid?
72 72 assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
73 73 issues = find_issues_with_query(query)
74 74 assert_equal 1, issues.length
75 75 assert_equal Issue.find(3), issues.first
76 76 end
77 77
78 78 def test_operator_none
79 79 query = Query.new(:project => Project.find(1), :name => '_')
80 80 query.add_filter('fixed_version_id', '!*', [''])
81 81 query.add_filter('cf_1', '!*', [''])
82 82 assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL")
83 83 assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''")
84 84 find_issues_with_query(query)
85 85 end
86 86
87 87 def test_operator_none_for_integer
88 88 query = Query.new(:project => Project.find(1), :name => '_')
89 89 query.add_filter('estimated_hours', '!*', [''])
90 90 issues = find_issues_with_query(query)
91 91 assert !issues.empty?
92 92 assert issues.all? {|i| !i.estimated_hours}
93 93 end
94 94
95 95 def test_operator_all
96 96 query = Query.new(:project => Project.find(1), :name => '_')
97 97 query.add_filter('fixed_version_id', '*', [''])
98 98 query.add_filter('cf_1', '*', [''])
99 99 assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL")
100 100 assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''")
101 101 find_issues_with_query(query)
102 102 end
103 103
104 104 def test_operator_greater_than
105 105 query = Query.new(:project => Project.find(1), :name => '_')
106 106 query.add_filter('done_ratio', '>=', ['40'])
107 107 assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40")
108 108 find_issues_with_query(query)
109 109 end
110 110
111 111 def test_operator_in_more_than
112 112 Issue.find(7).update_attribute(:due_date, (Date.today + 15))
113 113 query = Query.new(:project => Project.find(1), :name => '_')
114 114 query.add_filter('due_date', '>t+', ['15'])
115 115 issues = find_issues_with_query(query)
116 116 assert !issues.empty?
117 117 issues.each {|issue| assert(issue.due_date >= (Date.today + 15))}
118 118 end
119 119
120 120 def test_operator_in_less_than
121 121 query = Query.new(:project => Project.find(1), :name => '_')
122 122 query.add_filter('due_date', '<t+', ['15'])
123 123 issues = find_issues_with_query(query)
124 124 assert !issues.empty?
125 125 issues.each {|issue| assert(issue.due_date >= Date.today && issue.due_date <= (Date.today + 15))}
126 126 end
127 127
128 128 def test_operator_less_than_ago
129 129 Issue.find(7).update_attribute(:due_date, (Date.today - 3))
130 130 query = Query.new(:project => Project.find(1), :name => '_')
131 131 query.add_filter('due_date', '>t-', ['3'])
132 132 issues = find_issues_with_query(query)
133 133 assert !issues.empty?
134 134 issues.each {|issue| assert(issue.due_date >= (Date.today - 3) && issue.due_date <= Date.today)}
135 135 end
136 136
137 137 def test_operator_more_than_ago
138 138 Issue.find(7).update_attribute(:due_date, (Date.today - 10))
139 139 query = Query.new(:project => Project.find(1), :name => '_')
140 140 query.add_filter('due_date', '<t-', ['10'])
141 141 assert query.statement.include?("#{Issue.table_name}.due_date <=")
142 142 issues = find_issues_with_query(query)
143 143 assert !issues.empty?
144 144 issues.each {|issue| assert(issue.due_date <= (Date.today - 10))}
145 145 end
146 146
147 147 def test_operator_in
148 148 Issue.find(7).update_attribute(:due_date, (Date.today + 2))
149 149 query = Query.new(:project => Project.find(1), :name => '_')
150 150 query.add_filter('due_date', 't+', ['2'])
151 151 issues = find_issues_with_query(query)
152 152 assert !issues.empty?
153 153 issues.each {|issue| assert_equal((Date.today + 2), issue.due_date)}
154 154 end
155 155
156 156 def test_operator_ago
157 157 Issue.find(7).update_attribute(:due_date, (Date.today - 3))
158 158 query = Query.new(:project => Project.find(1), :name => '_')
159 159 query.add_filter('due_date', 't-', ['3'])
160 160 issues = find_issues_with_query(query)
161 161 assert !issues.empty?
162 162 issues.each {|issue| assert_equal((Date.today - 3), issue.due_date)}
163 163 end
164 164
165 165 def test_operator_today
166 166 query = Query.new(:project => Project.find(1), :name => '_')
167 167 query.add_filter('due_date', 't', [''])
168 168 issues = find_issues_with_query(query)
169 169 assert !issues.empty?
170 170 issues.each {|issue| assert_equal Date.today, issue.due_date}
171 171 end
172 172
173 173 def test_operator_this_week_on_date
174 174 query = Query.new(:project => Project.find(1), :name => '_')
175 175 query.add_filter('due_date', 'w', [''])
176 176 find_issues_with_query(query)
177 177 end
178 178
179 179 def test_operator_this_week_on_datetime
180 180 query = Query.new(:project => Project.find(1), :name => '_')
181 181 query.add_filter('created_on', 'w', [''])
182 182 find_issues_with_query(query)
183 183 end
184 184
185 185 def test_operator_contains
186 186 query = Query.new(:project => Project.find(1), :name => '_')
187 187 query.add_filter('subject', '~', ['uNable'])
188 188 assert query.statement.include?("LOWER(#{Issue.table_name}.subject) LIKE '%unable%'")
189 189 result = find_issues_with_query(query)
190 190 assert result.empty?
191 191 result.each {|issue| assert issue.subject.downcase.include?('unable') }
192 192 end
193 193
194 194 def test_operator_does_not_contains
195 195 query = Query.new(:project => Project.find(1), :name => '_')
196 196 query.add_filter('subject', '!~', ['uNable'])
197 197 assert query.statement.include?("LOWER(#{Issue.table_name}.subject) NOT LIKE '%unable%'")
198 198 find_issues_with_query(query)
199 199 end
200 200
201 201 def test_filter_watched_issues
202 202 User.current = User.find(1)
203 203 query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}})
204 204 result = find_issues_with_query(query)
205 205 assert_not_nil result
206 206 assert !result.empty?
207 207 assert_equal Issue.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id)
208 208 User.current = nil
209 209 end
210 210
211 211 def test_filter_unwatched_issues
212 212 User.current = User.find(1)
213 213 query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '!', :values => ['me']}})
214 214 result = find_issues_with_query(query)
215 215 assert_not_nil result
216 216 assert !result.empty?
217 217 assert_equal((Issue.visible - Issue.watched_by(User.current)).sort_by(&:id).size, result.sort_by(&:id).size)
218 218 User.current = nil
219 219 end
220 220
221 221 def test_default_columns
222 222 q = Query.new
223 223 assert !q.columns.empty?
224 224 end
225 225
226 226 def test_set_column_names
227 227 q = Query.new
228 228 q.column_names = ['tracker', :subject, '', 'unknonw_column']
229 229 assert_equal [:tracker, :subject], q.columns.collect {|c| c.name}
230 230 c = q.columns.first
231 231 assert q.has_column?(c)
232 232 end
233 233
234 234 def test_groupable_columns_should_include_custom_fields
235 235 q = Query.new
236 236 assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
237 237 end
238 238
239 239 def test_default_sort
240 240 q = Query.new
241 241 assert_equal [], q.sort_criteria
242 242 end
243 243
244 244 def test_set_sort_criteria_with_hash
245 245 q = Query.new
246 246 q.sort_criteria = {'0' => ['priority', 'desc'], '2' => ['tracker']}
247 247 assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria
248 248 end
249 249
250 250 def test_set_sort_criteria_with_array
251 251 q = Query.new
252 252 q.sort_criteria = [['priority', 'desc'], 'tracker']
253 253 assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria
254 254 end
255 255
256 256 def test_create_query_with_sort
257 257 q = Query.new(:name => 'Sorted')
258 258 q.sort_criteria = [['priority', 'desc'], 'tracker']
259 259 assert q.save
260 260 q.reload
261 261 assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria
262 262 end
263 263
264 264 def test_sort_by_string_custom_field_asc
265 265 q = Query.new
266 266 c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
267 267 assert c
268 268 assert c.sortable
269 269 issues = Issue.find :all,
270 270 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
271 271 :conditions => q.statement,
272 272 :order => "#{c.sortable} ASC"
273 273 values = issues.collect {|i| i.custom_value_for(c.custom_field).to_s}
274 274 assert !values.empty?
275 275 assert_equal values.sort, values
276 276 end
277 277
278 278 def test_sort_by_string_custom_field_desc
279 279 q = Query.new
280 280 c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
281 281 assert c
282 282 assert c.sortable
283 283 issues = Issue.find :all,
284 284 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
285 285 :conditions => q.statement,
286 286 :order => "#{c.sortable} DESC"
287 287 values = issues.collect {|i| i.custom_value_for(c.custom_field).to_s}
288 288 assert !values.empty?
289 289 assert_equal values.sort.reverse, values
290 290 end
291 291
292 292 def test_sort_by_float_custom_field_asc
293 293 q = Query.new
294 294 c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'float' }
295 295 assert c
296 296 assert c.sortable
297 297 issues = Issue.find :all,
298 298 :include => [ :assigned_to, :status, :tracker, :project, :priority ],
299 299 :conditions => q.statement,
300 300 :order => "#{c.sortable} ASC"
301 301 values = issues.collect {|i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end}.compact
302 302 assert !values.empty?
303 303 assert_equal values.sort, values
304 304 end
305 305
306 306 def test_invalid_query_should_raise_query_statement_invalid_error
307 307 q = Query.new
308 308 assert_raise Query::StatementInvalid do
309 309 q.issues(:conditions => "foo = 1")
310 310 end
311 311 end
312 312
313 313 def test_issue_count_by_association_group
314 314 q = Query.new(:name => '_', :group_by => 'assigned_to')
315 315 count_by_group = q.issue_count_by_group
316 316 assert_kind_of Hash, count_by_group
317 317 assert_equal %w(NilClass User), count_by_group.keys.collect {|k| k.class.name}.uniq.sort
318 318 assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq
319 319 assert count_by_group.has_key?(User.find(3))
320 320 end
321 321
322 322 def test_issue_count_by_list_custom_field_group
323 323 q = Query.new(:name => '_', :group_by => 'cf_1')
324 324 count_by_group = q.issue_count_by_group
325 325 assert_kind_of Hash, count_by_group
326 326 assert_equal %w(NilClass String), count_by_group.keys.collect {|k| k.class.name}.uniq.sort
327 327 assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq
328 328 assert count_by_group.has_key?('MySQL')
329 329 end
330 330
331 331 def test_issue_count_by_date_custom_field_group
332 332 q = Query.new(:name => '_', :group_by => 'cf_8')
333 333 count_by_group = q.issue_count_by_group
334 334 assert_kind_of Hash, count_by_group
335 335 assert_equal %w(Date NilClass), count_by_group.keys.collect {|k| k.class.name}.uniq.sort
336 336 assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq
337 337 end
338 338
339 339 def test_label_for
340 340 q = Query.new
341 341 assert_equal 'assigned_to', q.label_for('assigned_to_id')
342 342 end
343 343
344 344 def test_editable_by
345 345 admin = User.find(1)
346 346 manager = User.find(2)
347 347 developer = User.find(3)
348 348
349 349 # Public query on project 1
350 350 q = Query.find(1)
351 351 assert q.editable_by?(admin)
352 352 assert q.editable_by?(manager)
353 353 assert !q.editable_by?(developer)
354 354
355 355 # Private query on project 1
356 356 q = Query.find(2)
357 357 assert q.editable_by?(admin)
358 358 assert !q.editable_by?(manager)
359 359 assert q.editable_by?(developer)
360 360
361 361 # Private query for all projects
362 362 q = Query.find(3)
363 363 assert q.editable_by?(admin)
364 364 assert !q.editable_by?(manager)
365 365 assert q.editable_by?(developer)
366 366
367 367 # Public query for all projects
368 368 q = Query.find(4)
369 369 assert q.editable_by?(admin)
370 370 assert !q.editable_by?(manager)
371 371 assert !q.editable_by?(developer)
372 372 end
373 373
374 374 context "#available_filters" do
375 375 setup do
376 376 @query = Query.new(:name => "_")
377 377 end
378 378
379 379 should "include users of visible projects in cross-project view" do
380 380 users = @query.available_filters["assigned_to_id"]
381 381 assert_not_nil users
382 382 assert users[:values].map{|u|u[1]}.include?("3")
383 383 end
384 384
385 385 context "'member_of_group' filter" do
386 386 should "be present" do
387 387 assert @query.available_filters.keys.include?("member_of_group")
388 388 end
389 389
390 390 should "be an optional list" do
391 391 assert_equal :list_optional, @query.available_filters["member_of_group"][:type]
392 392 end
393 393
394 394 should "have a list of the groups as values" do
395 395 Group.destroy_all # No fixtures
396 396 group1 = Group.generate!.reload
397 397 group2 = Group.generate!.reload
398 398
399 399 expected_group_list = [
400 400 [group1.name, group1.id],
401 401 [group2.name, group2.id]
402 402 ]
403 403 assert_equal expected_group_list, @query.available_filters["member_of_group"][:values]
404 404 end
405 405
406 406 end
407
407
408 context "'assigned_to_role' filter" do
409 should "be present" do
410 assert @query.available_filters.keys.include?("assigned_to_role")
411 end
412
413 should "be an optional list" do
414 assert_equal :list_optional, @query.available_filters["assigned_to_role"][:type]
415 end
416
417 should "have a list of the Roles as values" do
418 assert @query.available_filters["assigned_to_role"][:values].include?(['Manager',1])
419 assert @query.available_filters["assigned_to_role"][:values].include?(['Developer',2])
420 assert @query.available_filters["assigned_to_role"][:values].include?(['Reporter',3])
421 end
422
423 should "not include the built in Roles as values" do
424 assert ! @query.available_filters["assigned_to_role"][:values].include?(['Non member',4])
425 assert ! @query.available_filters["assigned_to_role"][:values].include?(['Anonymous',5])
426 end
427
428 end
429
408 430 end
409 431
410 432 context "#statement" do
411 433 context "with 'member_of_group' filter" do
412 434 setup do
413 435 Group.destroy_all # No fixtures
414 436 @user_in_group = User.generate!
415 437 @second_user_in_group = User.generate!
416 438 @user_in_group2 = User.generate!
417 439 @user_not_in_group = User.generate!
418 440
419 441 @group = Group.generate!.reload
420 442 @group.users << @user_in_group
421 443 @group.users << @second_user_in_group
422 444
423 445 @group2 = Group.generate!.reload
424 446 @group2.users << @user_in_group2
425 447
426 448 end
427 449
428 450 should "search assigned to for users in the group" do
429 451 @query = Query.new(:name => '_')
430 452 @query.add_filter('member_of_group', '=', [@group.id.to_s])
431 453
432 454 assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}')"
433 455 assert_find_issues_with_query_is_successful @query
434 456 end
435 457
436 458 should "search not assigned to any group member (none)" do
437 459 @query = Query.new(:name => '_')
438 460 @query.add_filter('member_of_group', '!*', [''])
439 461
440 462 # Users not in a group
441 463 assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IS NULL OR #{Issue.table_name}.assigned_to_id NOT IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}')"
442 464 assert_find_issues_with_query_is_successful @query
443 465
444 466 end
445 467
446 468 should "search assigned to any group member (all)" do
447 469 @query = Query.new(:name => '_')
448 470 @query.add_filter('member_of_group', '*', [''])
449 471
450 472 # Only users in a group
451 473 assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}')"
452 474 assert_find_issues_with_query_is_successful @query
453 475
454 476 end
455 477 end
478
479 context "with 'assigned_to_role' filter" do
480 setup do
481 # No fixtures
482 MemberRole.delete_all
483 Member.delete_all
484 Role.delete_all
485
486 @manager_role = Role.generate!(:name => 'Manager')
487 @developer_role = Role.generate!(:name => 'Developer')
488
489 @project = Project.generate!
490 @manager = User.generate!
491 @developer = User.generate!
492 @boss = User.generate!
493 User.add_to_project(@manager, @project, @manager_role)
494 User.add_to_project(@developer, @project, @developer_role)
495 User.add_to_project(@boss, @project, [@manager_role, @developer_role])
496 end
497
498 should "search assigned to for users with the Role" do
499 @query = Query.new(:name => '_')
500 @query.add_filter('assigned_to_role', '=', [@manager_role.id.to_s])
501
502 assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@boss.id}')"
503 assert_find_issues_with_query_is_successful @query
504 end
505
506 should "search assigned to for users not assigned to any Role (none)" do
507 @query = Query.new(:name => '_')
508 @query.add_filter('assigned_to_role', '!*', [''])
509
510 assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IS NULL OR #{Issue.table_name}.assigned_to_id NOT IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')"
511 assert_find_issues_with_query_is_successful @query
512 end
513
514 should "search assigned to for users assigned to any Role (all)" do
515 @query = Query.new(:name => '_')
516 @query.add_filter('assigned_to_role', '*', [''])
517
518 assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')"
519 assert_find_issues_with_query_is_successful @query
520 end
521 end
456 522 end
457 523
458 524 end
General Comments 0
You need to be logged in to leave comments. Login now