##// END OF EJS Templates
Changed issues css class from status-{position} to status-{id} (#11304)....
Jean-Philippe Lang -
r9895:88efd302a7ff
parent child
Show More
@@ -1,1223 +1,1223
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 Issue < ActiveRecord::Base
19 19 include Redmine::SafeAttributes
20 20
21 21 belongs_to :project
22 22 belongs_to :tracker
23 23 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
24 24 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
25 25 belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id'
26 26 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
27 27 belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
28 28 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
29 29
30 30 has_many :journals, :as => :journalized, :dependent => :destroy
31 31 has_many :time_entries, :dependent => :delete_all
32 32 has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
33 33
34 34 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
35 35 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
36 36
37 37 acts_as_nested_set :scope => 'root_id', :dependent => :destroy
38 38 acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
39 39 acts_as_customizable
40 40 acts_as_watchable
41 41 acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
42 42 :include => [:project, :journals],
43 43 # sort by id so that limited eager loading doesn't break with postgresql
44 44 :order_column => "#{table_name}.id"
45 45 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
46 46 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
47 47 :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
48 48
49 49 acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
50 50 :author_key => :author_id
51 51
52 52 DONE_RATIO_OPTIONS = %w(issue_field issue_status)
53 53
54 54 attr_reader :current_journal
55 55
56 56 validates_presence_of :subject, :priority, :project, :tracker, :author, :status
57 57
58 58 validates_length_of :subject, :maximum => 255
59 59 validates_inclusion_of :done_ratio, :in => 0..100
60 60 validates_numericality_of :estimated_hours, :allow_nil => true
61 61 validate :validate_issue, :validate_required_fields
62 62
63 63 scope :visible,
64 64 lambda {|*args| { :include => :project,
65 65 :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
66 66
67 67 scope :open, lambda {|*args|
68 68 is_closed = args.size > 0 ? !args.first : false
69 69 {:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status}
70 70 }
71 71
72 72 scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
73 73 scope :with_limit, lambda { |limit| { :limit => limit} }
74 74 scope :on_active_project, :include => [:status, :project, :tracker],
75 75 :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
76 76
77 77 before_create :default_assign
78 78 before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change
79 79 after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?}
80 80 after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal
81 81 after_destroy :update_parent_attributes
82 82
83 83 # Returns a SQL conditions string used to find all issues visible by the specified user
84 84 def self.visible_condition(user, options={})
85 85 Project.allowed_to_condition(user, :view_issues, options) do |role, user|
86 86 case role.issues_visibility
87 87 when 'all'
88 88 nil
89 89 when 'default'
90 90 user_ids = [user.id] + user.groups.map(&:id)
91 91 "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
92 92 when 'own'
93 93 user_ids = [user.id] + user.groups.map(&:id)
94 94 "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
95 95 else
96 96 '1=0'
97 97 end
98 98 end
99 99 end
100 100
101 101 # Returns true if usr or current user is allowed to view the issue
102 102 def visible?(usr=nil)
103 103 (usr || User.current).allowed_to?(:view_issues, self.project) do |role, user|
104 104 case role.issues_visibility
105 105 when 'all'
106 106 true
107 107 when 'default'
108 108 !self.is_private? || self.author == user || user.is_or_belongs_to?(assigned_to)
109 109 when 'own'
110 110 self.author == user || user.is_or_belongs_to?(assigned_to)
111 111 else
112 112 false
113 113 end
114 114 end
115 115 end
116 116
117 117 def initialize(attributes=nil, *args)
118 118 super
119 119 if new_record?
120 120 # set default values for new records only
121 121 self.status ||= IssueStatus.default
122 122 self.priority ||= IssuePriority.default
123 123 self.watcher_user_ids = []
124 124 end
125 125 end
126 126
127 127 # AR#Persistence#destroy would raise and RecordNotFound exception
128 128 # if the issue was already deleted or updated (non matching lock_version).
129 129 # This is a problem when bulk deleting issues or deleting a project
130 130 # (because an issue may already be deleted if its parent was deleted
131 131 # first).
132 132 # The issue is reloaded by the nested_set before being deleted so
133 133 # the lock_version condition should not be an issue but we handle it.
134 134 def destroy
135 135 super
136 136 rescue ActiveRecord::RecordNotFound
137 137 # Stale or already deleted
138 138 begin
139 139 reload
140 140 rescue ActiveRecord::RecordNotFound
141 141 # The issue was actually already deleted
142 142 @destroyed = true
143 143 return freeze
144 144 end
145 145 # The issue was stale, retry to destroy
146 146 super
147 147 end
148 148
149 149 def reload(*args)
150 150 @workflow_rule_by_attribute = nil
151 151 super
152 152 end
153 153
154 154 # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
155 155 def available_custom_fields
156 156 (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : []
157 157 end
158 158
159 159 # Copies attributes from another issue, arg can be an id or an Issue
160 160 def copy_from(arg, options={})
161 161 issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
162 162 self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
163 163 self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
164 164 self.status = issue.status
165 165 self.author = User.current
166 166 unless options[:attachments] == false
167 167 self.attachments = issue.attachments.map do |attachement|
168 168 attachement.copy(:container => self)
169 169 end
170 170 end
171 171 @copied_from = issue
172 172 self
173 173 end
174 174
175 175 # Returns an unsaved copy of the issue
176 176 def copy(attributes=nil, copy_options={})
177 177 copy = self.class.new.copy_from(self, copy_options)
178 178 copy.attributes = attributes if attributes
179 179 copy
180 180 end
181 181
182 182 # Returns true if the issue is a copy
183 183 def copy?
184 184 @copied_from.present?
185 185 end
186 186
187 187 # Moves/copies an issue to a new project and tracker
188 188 # Returns the moved/copied issue on success, false on failure
189 189 def move_to_project(new_project, new_tracker=nil, options={})
190 190 ActiveSupport::Deprecation.warn "Issue#move_to_project is deprecated, use #project= instead."
191 191
192 192 if options[:copy]
193 193 issue = self.copy
194 194 else
195 195 issue = self
196 196 end
197 197
198 198 issue.init_journal(User.current, options[:notes])
199 199
200 200 # Preserve previous behaviour
201 201 # #move_to_project doesn't change tracker automatically
202 202 issue.send :project=, new_project, true
203 203 if new_tracker
204 204 issue.tracker = new_tracker
205 205 end
206 206 # Allow bulk setting of attributes on the issue
207 207 if options[:attributes]
208 208 issue.attributes = options[:attributes]
209 209 end
210 210
211 211 issue.save ? issue : false
212 212 end
213 213
214 214 def status_id=(sid)
215 215 self.status = nil
216 216 result = write_attribute(:status_id, sid)
217 217 @workflow_rule_by_attribute = nil
218 218 result
219 219 end
220 220
221 221 def priority_id=(pid)
222 222 self.priority = nil
223 223 write_attribute(:priority_id, pid)
224 224 end
225 225
226 226 def category_id=(cid)
227 227 self.category = nil
228 228 write_attribute(:category_id, cid)
229 229 end
230 230
231 231 def fixed_version_id=(vid)
232 232 self.fixed_version = nil
233 233 write_attribute(:fixed_version_id, vid)
234 234 end
235 235
236 236 def tracker_id=(tid)
237 237 self.tracker = nil
238 238 result = write_attribute(:tracker_id, tid)
239 239 @custom_field_values = nil
240 240 @workflow_rule_by_attribute = nil
241 241 result
242 242 end
243 243
244 244 def project_id=(project_id)
245 245 if project_id.to_s != self.project_id.to_s
246 246 self.project = (project_id.present? ? Project.find_by_id(project_id) : nil)
247 247 end
248 248 end
249 249
250 250 def project=(project, keep_tracker=false)
251 251 project_was = self.project
252 252 write_attribute(:project_id, project ? project.id : nil)
253 253 association_instance_set('project', project)
254 254 if project_was && project && project_was != project
255 255 unless keep_tracker || project.trackers.include?(tracker)
256 256 self.tracker = project.trackers.first
257 257 end
258 258 # Reassign to the category with same name if any
259 259 if category
260 260 self.category = project.issue_categories.find_by_name(category.name)
261 261 end
262 262 # Keep the fixed_version if it's still valid in the new_project
263 263 if fixed_version && fixed_version.project != project && !project.shared_versions.include?(fixed_version)
264 264 self.fixed_version = nil
265 265 end
266 266 if parent && parent.project_id != project_id
267 267 self.parent_issue_id = nil
268 268 end
269 269 @custom_field_values = nil
270 270 end
271 271 end
272 272
273 273 def description=(arg)
274 274 if arg.is_a?(String)
275 275 arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n")
276 276 end
277 277 write_attribute(:description, arg)
278 278 end
279 279
280 280 # Overrides assign_attributes so that project and tracker get assigned first
281 281 def assign_attributes_with_project_and_tracker_first(new_attributes, *args)
282 282 return if new_attributes.nil?
283 283 attrs = new_attributes.dup
284 284 attrs.stringify_keys!
285 285
286 286 %w(project project_id tracker tracker_id).each do |attr|
287 287 if attrs.has_key?(attr)
288 288 send "#{attr}=", attrs.delete(attr)
289 289 end
290 290 end
291 291 send :assign_attributes_without_project_and_tracker_first, attrs, *args
292 292 end
293 293 # Do not redefine alias chain on reload (see #4838)
294 294 alias_method_chain(:assign_attributes, :project_and_tracker_first) unless method_defined?(:assign_attributes_without_project_and_tracker_first)
295 295
296 296 def estimated_hours=(h)
297 297 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
298 298 end
299 299
300 300 safe_attributes 'project_id',
301 301 :if => lambda {|issue, user|
302 302 if issue.new_record?
303 303 issue.copy?
304 304 elsif user.allowed_to?(:move_issues, issue.project)
305 305 projects = Issue.allowed_target_projects_on_move(user)
306 306 projects.include?(issue.project) && projects.size > 1
307 307 end
308 308 }
309 309
310 310 safe_attributes 'tracker_id',
311 311 'status_id',
312 312 'category_id',
313 313 'assigned_to_id',
314 314 'priority_id',
315 315 'fixed_version_id',
316 316 'subject',
317 317 'description',
318 318 'start_date',
319 319 'due_date',
320 320 'done_ratio',
321 321 'estimated_hours',
322 322 'custom_field_values',
323 323 'custom_fields',
324 324 'lock_version',
325 325 :if => lambda {|issue, user| issue.new_record? || user.allowed_to?(:edit_issues, issue.project) }
326 326
327 327 safe_attributes 'status_id',
328 328 'assigned_to_id',
329 329 'fixed_version_id',
330 330 'done_ratio',
331 331 'lock_version',
332 332 :if => lambda {|issue, user| issue.new_statuses_allowed_to(user).any? }
333 333
334 334 safe_attributes 'watcher_user_ids',
335 335 :if => lambda {|issue, user| issue.new_record? && user.allowed_to?(:add_issue_watchers, issue.project)}
336 336
337 337 safe_attributes 'is_private',
338 338 :if => lambda {|issue, user|
339 339 user.allowed_to?(:set_issues_private, issue.project) ||
340 340 (issue.author == user && user.allowed_to?(:set_own_issues_private, issue.project))
341 341 }
342 342
343 343 safe_attributes 'parent_issue_id',
344 344 :if => lambda {|issue, user| (issue.new_record? || user.allowed_to?(:edit_issues, issue.project)) &&
345 345 user.allowed_to?(:manage_subtasks, issue.project)}
346 346
347 347 def safe_attribute_names(user=nil)
348 348 names = super
349 349 names -= disabled_core_fields
350 350 names -= read_only_attribute_names(user)
351 351 names
352 352 end
353 353
354 354 # Safely sets attributes
355 355 # Should be called from controllers instead of #attributes=
356 356 # attr_accessible is too rough because we still want things like
357 357 # Issue.new(:project => foo) to work
358 358 def safe_attributes=(attrs, user=User.current)
359 359 return unless attrs.is_a?(Hash)
360 360
361 361 attrs = attrs.dup
362 362
363 363 # Project and Tracker must be set before since new_statuses_allowed_to depends on it.
364 364 if (p = attrs.delete('project_id')) && safe_attribute?('project_id')
365 365 if allowed_target_projects(user).collect(&:id).include?(p.to_i)
366 366 self.project_id = p
367 367 end
368 368 end
369 369
370 370 if (t = attrs.delete('tracker_id')) && safe_attribute?('tracker_id')
371 371 self.tracker_id = t
372 372 end
373 373
374 374 if (s = attrs.delete('status_id')) && safe_attribute?('status_id')
375 375 if new_statuses_allowed_to(user).collect(&:id).include?(s.to_i)
376 376 self.status_id = s
377 377 end
378 378 end
379 379
380 380 attrs = delete_unsafe_attributes(attrs, user)
381 381 return if attrs.empty?
382 382
383 383 unless leaf?
384 384 attrs.reject! {|k,v| %w(priority_id done_ratio start_date due_date estimated_hours).include?(k)}
385 385 end
386 386
387 387 if attrs['parent_issue_id'].present?
388 388 attrs.delete('parent_issue_id') unless Issue.visible(user).exists?(attrs['parent_issue_id'].to_i)
389 389 end
390 390
391 391 if attrs['custom_field_values'].present?
392 392 attrs['custom_field_values'] = attrs['custom_field_values'].reject {|k, v| read_only_attribute_names(user).include? k.to_s}
393 393 end
394 394
395 395 if attrs['custom_fields'].present?
396 396 attrs['custom_fields'] = attrs['custom_fields'].reject {|c| read_only_attribute_names(user).include? c['id'].to_s}
397 397 end
398 398
399 399 # mass-assignment security bypass
400 400 assign_attributes attrs, :without_protection => true
401 401 end
402 402
403 403 def disabled_core_fields
404 404 tracker ? tracker.disabled_core_fields : []
405 405 end
406 406
407 407 # Returns the custom_field_values that can be edited by the given user
408 408 def editable_custom_field_values(user=nil)
409 409 custom_field_values.reject do |value|
410 410 read_only_attribute_names(user).include?(value.custom_field_id.to_s)
411 411 end
412 412 end
413 413
414 414 # Returns the names of attributes that are read-only for user or the current user
415 415 # For users with multiple roles, the read-only fields are the intersection of
416 416 # read-only fields of each role
417 417 # The result is an array of strings where sustom fields are represented with their ids
418 418 #
419 419 # Examples:
420 420 # issue.read_only_attribute_names # => ['due_date', '2']
421 421 # issue.read_only_attribute_names(user) # => []
422 422 def read_only_attribute_names(user=nil)
423 423 workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'readonly'}.keys
424 424 end
425 425
426 426 # Returns the names of required attributes for user or the current user
427 427 # For users with multiple roles, the required fields are the intersection of
428 428 # required fields of each role
429 429 # The result is an array of strings where sustom fields are represented with their ids
430 430 #
431 431 # Examples:
432 432 # issue.required_attribute_names # => ['due_date', '2']
433 433 # issue.required_attribute_names(user) # => []
434 434 def required_attribute_names(user=nil)
435 435 workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'required'}.keys
436 436 end
437 437
438 438 # Returns true if the attribute is required for user
439 439 def required_attribute?(name, user=nil)
440 440 required_attribute_names(user).include?(name.to_s)
441 441 end
442 442
443 443 # Returns a hash of the workflow rule by attribute for the given user
444 444 #
445 445 # Examples:
446 446 # issue.workflow_rule_by_attribute # => {'due_date' => 'required', 'start_date' => 'readonly'}
447 447 def workflow_rule_by_attribute(user=nil)
448 448 return @workflow_rule_by_attribute if @workflow_rule_by_attribute && user.nil?
449 449
450 450 user_real = user || User.current
451 451 roles = user_real.admin ? Role.all : user_real.roles_for_project(project)
452 452 return {} if roles.empty?
453 453
454 454 result = {}
455 455 workflow_permissions = WorkflowPermission.where(:tracker_id => tracker_id, :old_status_id => status_id, :role_id => roles.map(&:id)).all
456 456 if workflow_permissions.any?
457 457 workflow_rules = workflow_permissions.inject({}) do |h, wp|
458 458 h[wp.field_name] ||= []
459 459 h[wp.field_name] << wp.rule
460 460 h
461 461 end
462 462 workflow_rules.each do |attr, rules|
463 463 next if rules.size < roles.size
464 464 uniq_rules = rules.uniq
465 465 if uniq_rules.size == 1
466 466 result[attr] = uniq_rules.first
467 467 else
468 468 result[attr] = 'required'
469 469 end
470 470 end
471 471 end
472 472 @workflow_rule_by_attribute = result if user.nil?
473 473 result
474 474 end
475 475 private :workflow_rule_by_attribute
476 476
477 477 def done_ratio
478 478 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
479 479 status.default_done_ratio
480 480 else
481 481 read_attribute(:done_ratio)
482 482 end
483 483 end
484 484
485 485 def self.use_status_for_done_ratio?
486 486 Setting.issue_done_ratio == 'issue_status'
487 487 end
488 488
489 489 def self.use_field_for_done_ratio?
490 490 Setting.issue_done_ratio == 'issue_field'
491 491 end
492 492
493 493 def validate_issue
494 494 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
495 495 errors.add :due_date, :not_a_date
496 496 end
497 497
498 498 if self.due_date and self.start_date and self.due_date < self.start_date
499 499 errors.add :due_date, :greater_than_start_date
500 500 end
501 501
502 502 if start_date && soonest_start && start_date < soonest_start
503 503 errors.add :start_date, :invalid
504 504 end
505 505
506 506 if fixed_version
507 507 if !assignable_versions.include?(fixed_version)
508 508 errors.add :fixed_version_id, :inclusion
509 509 elsif reopened? && fixed_version.closed?
510 510 errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version)
511 511 end
512 512 end
513 513
514 514 # Checks that the issue can not be added/moved to a disabled tracker
515 515 if project && (tracker_id_changed? || project_id_changed?)
516 516 unless project.trackers.include?(tracker)
517 517 errors.add :tracker_id, :inclusion
518 518 end
519 519 end
520 520
521 521 # Checks parent issue assignment
522 522 if @parent_issue
523 523 if @parent_issue.project_id != project_id
524 524 errors.add :parent_issue_id, :not_same_project
525 525 elsif !new_record?
526 526 # moving an existing issue
527 527 if @parent_issue.root_id != root_id
528 528 # we can always move to another tree
529 529 elsif move_possible?(@parent_issue)
530 530 # move accepted inside tree
531 531 else
532 532 errors.add :parent_issue_id, :not_a_valid_parent
533 533 end
534 534 end
535 535 end
536 536 end
537 537
538 538 # Validates the issue against additional workflow requirements
539 539 def validate_required_fields
540 540 user = new_record? ? author : current_journal.try(:user)
541 541
542 542 required_attribute_names(user).each do |attribute|
543 543 if attribute =~ /^\d+$/
544 544 attribute = attribute.to_i
545 545 v = custom_field_values.detect {|v| v.custom_field_id == attribute }
546 546 if v && v.value.blank?
547 547 errors.add :base, v.custom_field.name + ' ' + l('activerecord.errors.messages.blank')
548 548 end
549 549 else
550 550 if respond_to?(attribute) && send(attribute).blank?
551 551 errors.add attribute, :blank
552 552 end
553 553 end
554 554 end
555 555 end
556 556
557 557 # Set the done_ratio using the status if that setting is set. This will keep the done_ratios
558 558 # even if the user turns off the setting later
559 559 def update_done_ratio_from_issue_status
560 560 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
561 561 self.done_ratio = status.default_done_ratio
562 562 end
563 563 end
564 564
565 565 def init_journal(user, notes = "")
566 566 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
567 567 if new_record?
568 568 @current_journal.notify = false
569 569 else
570 570 @attributes_before_change = attributes.dup
571 571 @custom_values_before_change = {}
572 572 self.custom_field_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
573 573 end
574 574 @current_journal
575 575 end
576 576
577 577 # Returns the id of the last journal or nil
578 578 def last_journal_id
579 579 if new_record?
580 580 nil
581 581 else
582 582 journals.first(:order => "#{Journal.table_name}.id DESC").try(:id)
583 583 end
584 584 end
585 585
586 586 # Return true if the issue is closed, otherwise false
587 587 def closed?
588 588 self.status.is_closed?
589 589 end
590 590
591 591 # Return true if the issue is being reopened
592 592 def reopened?
593 593 if !new_record? && status_id_changed?
594 594 status_was = IssueStatus.find_by_id(status_id_was)
595 595 status_new = IssueStatus.find_by_id(status_id)
596 596 if status_was && status_new && status_was.is_closed? && !status_new.is_closed?
597 597 return true
598 598 end
599 599 end
600 600 false
601 601 end
602 602
603 603 # Return true if the issue is being closed
604 604 def closing?
605 605 if !new_record? && status_id_changed?
606 606 status_was = IssueStatus.find_by_id(status_id_was)
607 607 status_new = IssueStatus.find_by_id(status_id)
608 608 if status_was && status_new && !status_was.is_closed? && status_new.is_closed?
609 609 return true
610 610 end
611 611 end
612 612 false
613 613 end
614 614
615 615 # Returns true if the issue is overdue
616 616 def overdue?
617 617 !due_date.nil? && (due_date < Date.today) && !status.is_closed?
618 618 end
619 619
620 620 # Is the amount of work done less than it should for the due date
621 621 def behind_schedule?
622 622 return false if start_date.nil? || due_date.nil?
623 623 done_date = start_date + ((due_date - start_date+1)* done_ratio/100).floor
624 624 return done_date <= Date.today
625 625 end
626 626
627 627 # Does this issue have children?
628 628 def children?
629 629 !leaf?
630 630 end
631 631
632 632 # Users the issue can be assigned to
633 633 def assignable_users
634 634 users = project.assignable_users
635 635 users << author if author
636 636 users << assigned_to if assigned_to
637 637 users.uniq.sort
638 638 end
639 639
640 640 # Versions that the issue can be assigned to
641 641 def assignable_versions
642 642 @assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort
643 643 end
644 644
645 645 # Returns true if this issue is blocked by another issue that is still open
646 646 def blocked?
647 647 !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
648 648 end
649 649
650 650 # Returns an array of statuses that user is able to apply
651 651 def new_statuses_allowed_to(user=User.current, include_default=false)
652 652 if new_record? && @copied_from
653 653 [IssueStatus.default, @copied_from.status].compact.uniq.sort
654 654 else
655 655 initial_status = nil
656 656 if new_record?
657 657 initial_status = IssueStatus.default
658 658 elsif status_id_was
659 659 initial_status = IssueStatus.find_by_id(status_id_was)
660 660 end
661 661 initial_status ||= status
662 662
663 663 statuses = initial_status.find_new_statuses_allowed_to(
664 664 user.admin ? Role.all : user.roles_for_project(project),
665 665 tracker,
666 666 author == user,
667 667 assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id
668 668 )
669 669 statuses << initial_status unless statuses.empty?
670 670 statuses << IssueStatus.default if include_default
671 671 statuses = statuses.compact.uniq.sort
672 672 blocked? ? statuses.reject {|s| s.is_closed?} : statuses
673 673 end
674 674 end
675 675
676 676 def assigned_to_was
677 677 if assigned_to_id_changed? && assigned_to_id_was.present?
678 678 @assigned_to_was ||= User.find_by_id(assigned_to_id_was)
679 679 end
680 680 end
681 681
682 682 # Returns the mail adresses of users that should be notified
683 683 def recipients
684 684 notified = []
685 685 # Author and assignee are always notified unless they have been
686 686 # locked or don't want to be notified
687 687 notified << author if author
688 688 if assigned_to
689 689 notified += (assigned_to.is_a?(Group) ? assigned_to.users : [assigned_to])
690 690 end
691 691 if assigned_to_was
692 692 notified += (assigned_to_was.is_a?(Group) ? assigned_to_was.users : [assigned_to_was])
693 693 end
694 694 notified = notified.select {|u| u.active? && u.notify_about?(self)}
695 695
696 696 notified += project.notified_users
697 697 notified.uniq!
698 698 # Remove users that can not view the issue
699 699 notified.reject! {|user| !visible?(user)}
700 700 notified.collect(&:mail)
701 701 end
702 702
703 703 # Returns the number of hours spent on this issue
704 704 def spent_hours
705 705 @spent_hours ||= time_entries.sum(:hours) || 0
706 706 end
707 707
708 708 # Returns the total number of hours spent on this issue and its descendants
709 709 #
710 710 # Example:
711 711 # spent_hours => 0.0
712 712 # spent_hours => 50.2
713 713 def total_spent_hours
714 714 @total_spent_hours ||= self_and_descendants.sum("#{TimeEntry.table_name}.hours",
715 715 :joins => "LEFT JOIN #{TimeEntry.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id").to_f || 0.0
716 716 end
717 717
718 718 def relations
719 719 @relations ||= (relations_from + relations_to).sort
720 720 end
721 721
722 722 # Preloads relations for a collection of issues
723 723 def self.load_relations(issues)
724 724 if issues.any?
725 725 relations = IssueRelation.all(:conditions => ["issue_from_id IN (:ids) OR issue_to_id IN (:ids)", {:ids => issues.map(&:id)}])
726 726 issues.each do |issue|
727 727 issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
728 728 end
729 729 end
730 730 end
731 731
732 732 # Preloads visible spent time for a collection of issues
733 733 def self.load_visible_spent_hours(issues, user=User.current)
734 734 if issues.any?
735 735 hours_by_issue_id = TimeEntry.visible(user).sum(:hours, :group => :issue_id)
736 736 issues.each do |issue|
737 737 issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0)
738 738 end
739 739 end
740 740 end
741 741
742 742 # Finds an issue relation given its id.
743 743 def find_relation(relation_id)
744 744 IssueRelation.find(relation_id, :conditions => ["issue_to_id = ? OR issue_from_id = ?", id, id])
745 745 end
746 746
747 747 def all_dependent_issues(except=[])
748 748 except << self
749 749 dependencies = []
750 750 relations_from.each do |relation|
751 751 if relation.issue_to && !except.include?(relation.issue_to)
752 752 dependencies << relation.issue_to
753 753 dependencies += relation.issue_to.all_dependent_issues(except)
754 754 end
755 755 end
756 756 dependencies
757 757 end
758 758
759 759 # Returns an array of issues that duplicate this one
760 760 def duplicates
761 761 relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
762 762 end
763 763
764 764 # Returns the due date or the target due date if any
765 765 # Used on gantt chart
766 766 def due_before
767 767 due_date || (fixed_version ? fixed_version.effective_date : nil)
768 768 end
769 769
770 770 # Returns the time scheduled for this issue.
771 771 #
772 772 # Example:
773 773 # Start Date: 2/26/09, End Date: 3/04/09
774 774 # duration => 6
775 775 def duration
776 776 (start_date && due_date) ? due_date - start_date : 0
777 777 end
778 778
779 779 def soonest_start
780 780 @soonest_start ||= (
781 781 relations_to.collect{|relation| relation.successor_soonest_start} +
782 782 ancestors.collect(&:soonest_start)
783 783 ).compact.max
784 784 end
785 785
786 786 def reschedule_after(date)
787 787 return if date.nil?
788 788 if leaf?
789 789 if start_date.nil? || start_date < date
790 790 self.start_date, self.due_date = date, date + duration
791 791 begin
792 792 save
793 793 rescue ActiveRecord::StaleObjectError
794 794 reload
795 795 self.start_date, self.due_date = date, date + duration
796 796 save
797 797 end
798 798 end
799 799 else
800 800 leaves.each do |leaf|
801 801 leaf.reschedule_after(date)
802 802 end
803 803 end
804 804 end
805 805
806 806 def <=>(issue)
807 807 if issue.nil?
808 808 -1
809 809 elsif root_id != issue.root_id
810 810 (root_id || 0) <=> (issue.root_id || 0)
811 811 else
812 812 (lft || 0) <=> (issue.lft || 0)
813 813 end
814 814 end
815 815
816 816 def to_s
817 817 "#{tracker} ##{id}: #{subject}"
818 818 end
819 819
820 820 # Returns a string of css classes that apply to the issue
821 821 def css_classes
822 s = "issue status-#{status.position} priority-#{priority.position}"
822 s = "issue status-#{status_id} priority-#{priority.position}"
823 823 s << ' closed' if closed?
824 824 s << ' overdue' if overdue?
825 825 s << ' child' if child?
826 826 s << ' parent' unless leaf?
827 827 s << ' private' if is_private?
828 828 s << ' created-by-me' if User.current.logged? && author_id == User.current.id
829 829 s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
830 830 s
831 831 end
832 832
833 833 # Saves an issue and a time_entry from the parameters
834 834 def save_issue_with_child_records(params, existing_time_entry=nil)
835 835 Issue.transaction do
836 836 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
837 837 @time_entry = existing_time_entry || TimeEntry.new
838 838 @time_entry.project = project
839 839 @time_entry.issue = self
840 840 @time_entry.user = User.current
841 841 @time_entry.spent_on = User.current.today
842 842 @time_entry.attributes = params[:time_entry]
843 843 self.time_entries << @time_entry
844 844 end
845 845
846 846 # TODO: Rename hook
847 847 Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
848 848 if save
849 849 # TODO: Rename hook
850 850 Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
851 851 else
852 852 raise ActiveRecord::Rollback
853 853 end
854 854 end
855 855 end
856 856
857 857 # Unassigns issues from +version+ if it's no longer shared with issue's project
858 858 def self.update_versions_from_sharing_change(version)
859 859 # Update issues assigned to the version
860 860 update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
861 861 end
862 862
863 863 # Unassigns issues from versions that are no longer shared
864 864 # after +project+ was moved
865 865 def self.update_versions_from_hierarchy_change(project)
866 866 moved_project_ids = project.self_and_descendants.reload.collect(&:id)
867 867 # Update issues of the moved projects and issues assigned to a version of a moved project
868 868 Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids])
869 869 end
870 870
871 871 def parent_issue_id=(arg)
872 872 parent_issue_id = arg.blank? ? nil : arg.to_i
873 873 if parent_issue_id && @parent_issue = Issue.find_by_id(parent_issue_id)
874 874 @parent_issue.id
875 875 else
876 876 @parent_issue = nil
877 877 nil
878 878 end
879 879 end
880 880
881 881 def parent_issue_id
882 882 if instance_variable_defined? :@parent_issue
883 883 @parent_issue.nil? ? nil : @parent_issue.id
884 884 else
885 885 parent_id
886 886 end
887 887 end
888 888
889 889 # Extracted from the ReportsController.
890 890 def self.by_tracker(project)
891 891 count_and_group_by(:project => project,
892 892 :field => 'tracker_id',
893 893 :joins => Tracker.table_name)
894 894 end
895 895
896 896 def self.by_version(project)
897 897 count_and_group_by(:project => project,
898 898 :field => 'fixed_version_id',
899 899 :joins => Version.table_name)
900 900 end
901 901
902 902 def self.by_priority(project)
903 903 count_and_group_by(:project => project,
904 904 :field => 'priority_id',
905 905 :joins => IssuePriority.table_name)
906 906 end
907 907
908 908 def self.by_category(project)
909 909 count_and_group_by(:project => project,
910 910 :field => 'category_id',
911 911 :joins => IssueCategory.table_name)
912 912 end
913 913
914 914 def self.by_assigned_to(project)
915 915 count_and_group_by(:project => project,
916 916 :field => 'assigned_to_id',
917 917 :joins => User.table_name)
918 918 end
919 919
920 920 def self.by_author(project)
921 921 count_and_group_by(:project => project,
922 922 :field => 'author_id',
923 923 :joins => User.table_name)
924 924 end
925 925
926 926 def self.by_subproject(project)
927 927 ActiveRecord::Base.connection.select_all("select s.id as status_id,
928 928 s.is_closed as closed,
929 929 #{Issue.table_name}.project_id as project_id,
930 930 count(#{Issue.table_name}.id) as total
931 931 from
932 932 #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s
933 933 where
934 934 #{Issue.table_name}.status_id=s.id
935 935 and #{Issue.table_name}.project_id = #{Project.table_name}.id
936 936 and #{visible_condition(User.current, :project => project, :with_subprojects => true)}
937 937 and #{Issue.table_name}.project_id <> #{project.id}
938 938 group by s.id, s.is_closed, #{Issue.table_name}.project_id") if project.descendants.active.any?
939 939 end
940 940 # End ReportsController extraction
941 941
942 942 # Returns an array of projects that user can assign the issue to
943 943 def allowed_target_projects(user=User.current)
944 944 if new_record?
945 945 Project.all(:conditions => Project.allowed_to_condition(user, :add_issues))
946 946 else
947 947 self.class.allowed_target_projects_on_move(user)
948 948 end
949 949 end
950 950
951 951 # Returns an array of projects that user can move issues to
952 952 def self.allowed_target_projects_on_move(user=User.current)
953 953 Project.all(:conditions => Project.allowed_to_condition(user, :move_issues))
954 954 end
955 955
956 956 private
957 957
958 958 def after_project_change
959 959 # Update project_id on related time entries
960 960 TimeEntry.update_all(["project_id = ?", project_id], {:issue_id => id})
961 961
962 962 # Delete issue relations
963 963 unless Setting.cross_project_issue_relations?
964 964 relations_from.clear
965 965 relations_to.clear
966 966 end
967 967
968 968 # Move subtasks
969 969 children.each do |child|
970 970 # Change project and keep project
971 971 child.send :project=, project, true
972 972 unless child.save
973 973 raise ActiveRecord::Rollback
974 974 end
975 975 end
976 976 end
977 977
978 978 def update_nested_set_attributes
979 979 if root_id.nil?
980 980 # issue was just created
981 981 self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
982 982 set_default_left_and_right
983 983 Issue.update_all("root_id = #{root_id}, lft = #{lft}, rgt = #{rgt}", ["id = ?", id])
984 984 if @parent_issue
985 985 move_to_child_of(@parent_issue)
986 986 end
987 987 reload
988 988 elsif parent_issue_id != parent_id
989 989 former_parent_id = parent_id
990 990 # moving an existing issue
991 991 if @parent_issue && @parent_issue.root_id == root_id
992 992 # inside the same tree
993 993 move_to_child_of(@parent_issue)
994 994 else
995 995 # to another tree
996 996 unless root?
997 997 move_to_right_of(root)
998 998 reload
999 999 end
1000 1000 old_root_id = root_id
1001 1001 self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id )
1002 1002 target_maxright = nested_set_scope.maximum(right_column_name) || 0
1003 1003 offset = target_maxright + 1 - lft
1004 1004 Issue.update_all("root_id = #{root_id}, lft = lft + #{offset}, rgt = rgt + #{offset}",
1005 1005 ["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt])
1006 1006 self[left_column_name] = lft + offset
1007 1007 self[right_column_name] = rgt + offset
1008 1008 if @parent_issue
1009 1009 move_to_child_of(@parent_issue)
1010 1010 end
1011 1011 end
1012 1012 reload
1013 1013 # delete invalid relations of all descendants
1014 1014 self_and_descendants.each do |issue|
1015 1015 issue.relations.each do |relation|
1016 1016 relation.destroy unless relation.valid?
1017 1017 end
1018 1018 end
1019 1019 # update former parent
1020 1020 recalculate_attributes_for(former_parent_id) if former_parent_id
1021 1021 end
1022 1022 remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue)
1023 1023 end
1024 1024
1025 1025 def update_parent_attributes
1026 1026 recalculate_attributes_for(parent_id) if parent_id
1027 1027 end
1028 1028
1029 1029 def recalculate_attributes_for(issue_id)
1030 1030 if issue_id && p = Issue.find_by_id(issue_id)
1031 1031 # priority = highest priority of children
1032 1032 if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :joins => :priority)
1033 1033 p.priority = IssuePriority.find_by_position(priority_position)
1034 1034 end
1035 1035
1036 1036 # start/due dates = lowest/highest dates of children
1037 1037 p.start_date = p.children.minimum(:start_date)
1038 1038 p.due_date = p.children.maximum(:due_date)
1039 1039 if p.start_date && p.due_date && p.due_date < p.start_date
1040 1040 p.start_date, p.due_date = p.due_date, p.start_date
1041 1041 end
1042 1042
1043 1043 # done ratio = weighted average ratio of leaves
1044 1044 unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
1045 1045 leaves_count = p.leaves.count
1046 1046 if leaves_count > 0
1047 1047 average = p.leaves.average(:estimated_hours).to_f
1048 1048 if average == 0
1049 1049 average = 1
1050 1050 end
1051 1051 done = p.leaves.sum("COALESCE(estimated_hours, #{average}) * (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f
1052 1052 progress = done / (average * leaves_count)
1053 1053 p.done_ratio = progress.round
1054 1054 end
1055 1055 end
1056 1056
1057 1057 # estimate = sum of leaves estimates
1058 1058 p.estimated_hours = p.leaves.sum(:estimated_hours).to_f
1059 1059 p.estimated_hours = nil if p.estimated_hours == 0.0
1060 1060
1061 1061 # ancestors will be recursively updated
1062 1062 p.save(:validate => false)
1063 1063 end
1064 1064 end
1065 1065
1066 1066 # Update issues so their versions are not pointing to a
1067 1067 # fixed_version that is not shared with the issue's project
1068 1068 def self.update_versions(conditions=nil)
1069 1069 # Only need to update issues with a fixed_version from
1070 1070 # a different project and that is not systemwide shared
1071 1071 Issue.scoped(:conditions => conditions).all(
1072 1072 :conditions => "#{Issue.table_name}.fixed_version_id IS NOT NULL" +
1073 1073 " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
1074 1074 " AND #{Version.table_name}.sharing <> 'system'",
1075 1075 :include => [:project, :fixed_version]
1076 1076 ).each do |issue|
1077 1077 next if issue.project.nil? || issue.fixed_version.nil?
1078 1078 unless issue.project.shared_versions.include?(issue.fixed_version)
1079 1079 issue.init_journal(User.current)
1080 1080 issue.fixed_version = nil
1081 1081 issue.save
1082 1082 end
1083 1083 end
1084 1084 end
1085 1085
1086 1086 # Callback on attachment deletion
1087 1087 def attachment_added(obj)
1088 1088 if @current_journal && !obj.new_record?
1089 1089 @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :value => obj.filename)
1090 1090 end
1091 1091 end
1092 1092
1093 1093 # Callback on attachment deletion
1094 1094 def attachment_removed(obj)
1095 1095 if @current_journal && !obj.new_record?
1096 1096 @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :old_value => obj.filename)
1097 1097 @current_journal.save
1098 1098 end
1099 1099 end
1100 1100
1101 1101 # Default assignment based on category
1102 1102 def default_assign
1103 1103 if assigned_to.nil? && category && category.assigned_to
1104 1104 self.assigned_to = category.assigned_to
1105 1105 end
1106 1106 end
1107 1107
1108 1108 # Updates start/due dates of following issues
1109 1109 def reschedule_following_issues
1110 1110 if start_date_changed? || due_date_changed?
1111 1111 relations_from.each do |relation|
1112 1112 relation.set_issue_to_dates
1113 1113 end
1114 1114 end
1115 1115 end
1116 1116
1117 1117 # Closes duplicates if the issue is being closed
1118 1118 def close_duplicates
1119 1119 if closing?
1120 1120 duplicates.each do |duplicate|
1121 1121 # Reload is need in case the duplicate was updated by a previous duplicate
1122 1122 duplicate.reload
1123 1123 # Don't re-close it if it's already closed
1124 1124 next if duplicate.closed?
1125 1125 # Same user and notes
1126 1126 if @current_journal
1127 1127 duplicate.init_journal(@current_journal.user, @current_journal.notes)
1128 1128 end
1129 1129 duplicate.update_attribute :status, self.status
1130 1130 end
1131 1131 end
1132 1132 end
1133 1133
1134 1134 # Make sure updated_on is updated when adding a note
1135 1135 def force_updated_on_change
1136 1136 if @current_journal
1137 1137 self.updated_on = current_time_from_proper_timezone
1138 1138 end
1139 1139 end
1140 1140
1141 1141 # Saves the changes in a Journal
1142 1142 # Called after_save
1143 1143 def create_journal
1144 1144 if @current_journal
1145 1145 # attributes changes
1146 1146 if @attributes_before_change
1147 1147 (Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on)).each {|c|
1148 1148 before = @attributes_before_change[c]
1149 1149 after = send(c)
1150 1150 next if before == after || (before.blank? && after.blank?)
1151 1151 @current_journal.details << JournalDetail.new(:property => 'attr',
1152 1152 :prop_key => c,
1153 1153 :old_value => before,
1154 1154 :value => after)
1155 1155 }
1156 1156 end
1157 1157 if @custom_values_before_change
1158 1158 # custom fields changes
1159 1159 custom_field_values.each {|c|
1160 1160 before = @custom_values_before_change[c.custom_field_id]
1161 1161 after = c.value
1162 1162 next if before == after || (before.blank? && after.blank?)
1163 1163
1164 1164 if before.is_a?(Array) || after.is_a?(Array)
1165 1165 before = [before] unless before.is_a?(Array)
1166 1166 after = [after] unless after.is_a?(Array)
1167 1167
1168 1168 # values removed
1169 1169 (before - after).reject(&:blank?).each do |value|
1170 1170 @current_journal.details << JournalDetail.new(:property => 'cf',
1171 1171 :prop_key => c.custom_field_id,
1172 1172 :old_value => value,
1173 1173 :value => nil)
1174 1174 end
1175 1175 # values added
1176 1176 (after - before).reject(&:blank?).each do |value|
1177 1177 @current_journal.details << JournalDetail.new(:property => 'cf',
1178 1178 :prop_key => c.custom_field_id,
1179 1179 :old_value => nil,
1180 1180 :value => value)
1181 1181 end
1182 1182 else
1183 1183 @current_journal.details << JournalDetail.new(:property => 'cf',
1184 1184 :prop_key => c.custom_field_id,
1185 1185 :old_value => before,
1186 1186 :value => after)
1187 1187 end
1188 1188 }
1189 1189 end
1190 1190 @current_journal.save
1191 1191 # reset current journal
1192 1192 init_journal @current_journal.user, @current_journal.notes
1193 1193 end
1194 1194 end
1195 1195
1196 1196 # Query generator for selecting groups of issue counts for a project
1197 1197 # based on specific criteria
1198 1198 #
1199 1199 # Options
1200 1200 # * project - Project to search in.
1201 1201 # * field - String. Issue field to key off of in the grouping.
1202 1202 # * joins - String. The table name to join against.
1203 1203 def self.count_and_group_by(options)
1204 1204 project = options.delete(:project)
1205 1205 select_field = options.delete(:field)
1206 1206 joins = options.delete(:joins)
1207 1207
1208 1208 where = "#{Issue.table_name}.#{select_field}=j.id"
1209 1209
1210 1210 ActiveRecord::Base.connection.select_all("select s.id as status_id,
1211 1211 s.is_closed as closed,
1212 1212 j.id as #{select_field},
1213 1213 count(#{Issue.table_name}.id) as total
1214 1214 from
1215 1215 #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s, #{joins} j
1216 1216 where
1217 1217 #{Issue.table_name}.status_id=s.id
1218 1218 and #{where}
1219 1219 and #{Issue.table_name}.project_id=#{Project.table_name}.id
1220 1220 and #{visible_condition(User.current, :project => project)}
1221 1221 group by s.id, s.is_closed, j.id")
1222 1222 end
1223 1223 end
General Comments 0
You need to be logged in to leave comments. Login now