Mercurial > hg > soundsoftware-site
comparison app/models/.svn/text-base/issue.rb.svn-base @ 37:94944d00e43c
* Update to SVN trunk rev 4411
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 19 Nov 2010 13:24:41 +0000 |
parents | 40f7cfd4df19 |
children | af80e5618e9b |
comparison
equal
deleted
inserted
replaced
22:40f7cfd4df19 | 37:94944d00e43c |
---|---|
84 :conditions => Query.merge_conditions(query.statement) | 84 :conditions => Query.merge_conditions(query.statement) |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 before_create :default_assign | 88 before_create :default_assign |
89 before_save :reschedule_following_issues, :close_duplicates, :update_done_ratio_from_issue_status | 89 before_save :close_duplicates, :update_done_ratio_from_issue_status |
90 after_save :update_nested_set_attributes, :update_parent_attributes, :create_journal | 90 after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal |
91 after_destroy :destroy_children | 91 after_destroy :destroy_children |
92 after_destroy :update_parent_attributes | 92 after_destroy :update_parent_attributes |
93 | 93 |
94 # Returns true if usr or current user is allowed to view the issue | 94 # Returns true if usr or current user is allowed to view the issue |
95 def visible?(usr=nil) | 95 def visible?(usr=nil) |
231 estimated_hours | 231 estimated_hours |
232 custom_field_values | 232 custom_field_values |
233 lock_version | 233 lock_version |
234 ) unless const_defined?(:SAFE_ATTRIBUTES) | 234 ) unless const_defined?(:SAFE_ATTRIBUTES) |
235 | 235 |
236 SAFE_ATTRIBUTES_ON_TRANSITION = %w( | |
237 status_id | |
238 assigned_to_id | |
239 fixed_version_id | |
240 done_ratio | |
241 ) unless const_defined?(:SAFE_ATTRIBUTES_ON_TRANSITION) | |
242 | |
236 # Safely sets attributes | 243 # Safely sets attributes |
237 # Should be called from controllers instead of #attributes= | 244 # Should be called from controllers instead of #attributes= |
238 # attr_accessible is too rough because we still want things like | 245 # attr_accessible is too rough because we still want things like |
239 # Issue.new(:project => foo) to work | 246 # Issue.new(:project => foo) to work |
240 # TODO: move workflow/permission checks from controllers to here | 247 # TODO: move workflow/permission checks from controllers to here |
241 def safe_attributes=(attrs, user=User.current) | 248 def safe_attributes=(attrs, user=User.current) |
242 return if attrs.nil? | 249 return unless attrs.is_a?(Hash) |
243 attrs = attrs.reject {|k,v| !SAFE_ATTRIBUTES.include?(k)} | 250 |
251 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed | |
252 if new_record? || user.allowed_to?(:edit_issues, project) | |
253 attrs = attrs.reject {|k,v| !SAFE_ATTRIBUTES.include?(k)} | |
254 elsif new_statuses_allowed_to(user).any? | |
255 attrs = attrs.reject {|k,v| !SAFE_ATTRIBUTES_ON_TRANSITION.include?(k)} | |
256 else | |
257 return | |
258 end | |
259 | |
260 # Tracker must be set before since new_statuses_allowed_to depends on it. | |
261 if t = attrs.delete('tracker_id') | |
262 self.tracker_id = t | |
263 end | |
264 | |
244 if attrs['status_id'] | 265 if attrs['status_id'] |
245 unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i) | 266 unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i) |
246 attrs.delete('status_id') | 267 attrs.delete('status_id') |
247 end | 268 end |
248 end | 269 end |
261 | 282 |
262 self.attributes = attrs | 283 self.attributes = attrs |
263 end | 284 end |
264 | 285 |
265 def done_ratio | 286 def done_ratio |
266 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio? | 287 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio |
267 status.default_done_ratio | 288 status.default_done_ratio |
268 else | 289 else |
269 read_attribute(:done_ratio) | 290 read_attribute(:done_ratio) |
270 end | 291 end |
271 end | 292 end |
324 end | 345 end |
325 | 346 |
326 # Set the done_ratio using the status if that setting is set. This will keep the done_ratios | 347 # Set the done_ratio using the status if that setting is set. This will keep the done_ratios |
327 # even if the user turns off the setting later | 348 # even if the user turns off the setting later |
328 def update_done_ratio_from_issue_status | 349 def update_done_ratio_from_issue_status |
329 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio? | 350 if Issue.use_status_for_done_ratio? && status && status.default_done_ratio |
330 self.done_ratio = status.default_done_ratio | 351 self.done_ratio = status.default_done_ratio |
331 end | 352 end |
332 end | 353 end |
333 | 354 |
334 def init_journal(user, notes = "") | 355 def init_journal(user, notes = "") |
388 !leaf? | 409 !leaf? |
389 end | 410 end |
390 | 411 |
391 # Users the issue can be assigned to | 412 # Users the issue can be assigned to |
392 def assignable_users | 413 def assignable_users |
393 project.assignable_users | 414 users = project.assignable_users |
415 users << author if author | |
416 users.uniq.sort | |
394 end | 417 end |
395 | 418 |
396 # Versions that the issue can be assigned to | 419 # Versions that the issue can be assigned to |
397 def assignable_versions | 420 def assignable_versions |
398 @assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort | 421 @assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort |
413 end | 436 end |
414 | 437 |
415 # Returns the mail adresses of users that should be notified | 438 # Returns the mail adresses of users that should be notified |
416 def recipients | 439 def recipients |
417 notified = project.notified_users | 440 notified = project.notified_users |
418 # Author and assignee are always notified unless they have been locked | 441 # Author and assignee are always notified unless they have been |
419 notified << author if author && author.active? | 442 # locked or don't want to be notified |
420 notified << assigned_to if assigned_to && assigned_to.active? | 443 notified << author if author && author.active? && author.notify_about?(self) |
444 notified << assigned_to if assigned_to && assigned_to.active? && assigned_to.notify_about?(self) | |
421 notified.uniq! | 445 notified.uniq! |
422 # Remove users that can not view the issue | 446 # Remove users that can not view the issue |
423 notified.reject! {|user| !visible?(user)} | 447 notified.reject! {|user| !visible?(user)} |
424 notified.collect(&:mail) | 448 notified.collect(&:mail) |
425 end | 449 end |
712 if p.start_date && p.due_date && p.due_date < p.start_date | 736 if p.start_date && p.due_date && p.due_date < p.start_date |
713 p.start_date, p.due_date = p.due_date, p.start_date | 737 p.start_date, p.due_date = p.due_date, p.start_date |
714 end | 738 end |
715 | 739 |
716 # done ratio = weighted average ratio of leaves | 740 # done ratio = weighted average ratio of leaves |
717 unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio? | 741 unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio |
718 leaves_count = p.leaves.count | 742 leaves_count = p.leaves.count |
719 if leaves_count > 0 | 743 if leaves_count > 0 |
720 average = p.leaves.average(:estimated_hours).to_f | 744 average = p.leaves.average(:estimated_hours).to_f |
721 if average == 0 | 745 if average == 0 |
722 average = 1 | 746 average = 1 |