Mercurial > hg > soundsoftware-site
comparison app/models/.svn/text-base/issue.rb.svn-base @ 246:eeebe205a056 cannam
* Merge from default branch, bringing us up to SVN trunk rev 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 12:02:03 +0000 |
parents | 051f544170fe |
children | cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
138:fca2657f4aa5 | 246:eeebe205a056 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
32 has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC" | 32 has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC" |
33 | 33 |
34 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all | 34 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all |
35 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all | 35 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all |
36 | 36 |
37 acts_as_nested_set :scope => 'root_id' | 37 acts_as_nested_set :scope => 'root_id', :dependent => :destroy |
38 acts_as_attachable :after_remove => :attachment_removed | 38 acts_as_attachable :after_remove => :attachment_removed |
39 acts_as_customizable | 39 acts_as_customizable |
40 acts_as_watchable | 40 acts_as_watchable |
41 acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], | 41 acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], |
42 :include => [:project, :journals], | 42 :include => [:project, :journals], |
87 } | 87 } |
88 | 88 |
89 before_create :default_assign | 89 before_create :default_assign |
90 before_save :close_duplicates, :update_done_ratio_from_issue_status | 90 before_save :close_duplicates, :update_done_ratio_from_issue_status |
91 after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal | 91 after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal |
92 after_destroy :destroy_children | |
93 after_destroy :update_parent_attributes | 92 after_destroy :update_parent_attributes |
94 | 93 |
95 # 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 |
96 def visible?(usr=nil) | 95 def visible?(usr=nil) |
97 (usr || User.current).allowed_to?(:view_issues, self.project) | 96 (usr || User.current).allowed_to?(:view_issues, self.project) |
421 !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? | 420 !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? |
422 end | 421 end |
423 | 422 |
424 # Returns an array of status that user is able to apply | 423 # Returns an array of status that user is able to apply |
425 def new_statuses_allowed_to(user, include_default=false) | 424 def new_statuses_allowed_to(user, include_default=false) |
426 statuses = status.find_new_statuses_allowed_to(user.roles_for_project(project), tracker) | 425 statuses = status.find_new_statuses_allowed_to( |
426 user.roles_for_project(project), | |
427 tracker, | |
428 author == user, | |
429 assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id | |
430 ) | |
427 statuses << status unless statuses.empty? | 431 statuses << status unless statuses.empty? |
428 statuses << IssueStatus.default if include_default | 432 statuses << IssueStatus.default if include_default |
429 statuses = statuses.uniq.sort | 433 statuses = statuses.uniq.sort |
430 blocked? ? statuses.reject {|s| s.is_closed?} : statuses | 434 blocked? ? statuses.reject {|s| s.is_closed?} : statuses |
431 end | 435 end |
756 # ancestors will be recursively updated | 760 # ancestors will be recursively updated |
757 p.save(false) | 761 p.save(false) |
758 end | 762 end |
759 end | 763 end |
760 | 764 |
761 def destroy_children | |
762 unless leaf? | |
763 children.each do |child| | |
764 child.destroy | |
765 end | |
766 end | |
767 end | |
768 | |
769 # Update issues so their versions are not pointing to a | 765 # Update issues so their versions are not pointing to a |
770 # fixed_version that is not shared with the issue's project | 766 # fixed_version that is not shared with the issue's project |
771 def self.update_versions(conditions=nil) | 767 def self.update_versions(conditions=nil) |
772 # Only need to update issues with a fixed_version from | 768 # Only need to update issues with a fixed_version from |
773 # a different project and that is not systemwide shared | 769 # a different project and that is not systemwide shared |
831 # Saves the changes in a Journal | 827 # Saves the changes in a Journal |
832 # Called after_save | 828 # Called after_save |
833 def create_journal | 829 def create_journal |
834 if @current_journal | 830 if @current_journal |
835 # attributes changes | 831 # attributes changes |
836 (Issue.column_names - %w(id description root_id lft rgt lock_version created_on updated_on)).each {|c| | 832 (Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on)).each {|c| |
837 @current_journal.details << JournalDetail.new(:property => 'attr', | 833 @current_journal.details << JournalDetail.new(:property => 'attr', |
838 :prop_key => c, | 834 :prop_key => c, |
839 :old_value => @issue_before_change.send(c), | 835 :old_value => @issue_before_change.send(c), |
840 :value => send(c)) unless send(c)==@issue_before_change.send(c) | 836 :value => send(c)) unless send(c)==@issue_before_change.send(c) |
841 } | 837 } |