Mercurial > hg > soundsoftware-site
diff app/models/project.rb @ 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 db0caa9f0ff4 |
line wrap: on
line diff
--- a/app/models/project.rb Fri Sep 24 14:06:04 2010 +0100 +++ b/app/models/project.rb Fri Nov 19 13:24:41 2010 +0000 @@ -20,6 +20,9 @@ STATUS_ACTIVE = 1 STATUS_ARCHIVED = 9 + # Maximum length for project identifiers + IDENTIFIER_MAX_LENGTH = 100 + # Specific overidden Activities has_many :time_entry_activities has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}" @@ -64,11 +67,11 @@ attr_protected :status, :enabled_module_names validates_presence_of :name, :identifier - validates_uniqueness_of :name, :identifier + validates_uniqueness_of :identifier validates_associated :repository, :wiki - validates_length_of :name, :maximum => 30 + validates_length_of :name, :maximum => 255 validates_length_of :homepage, :maximum => 255 - validates_length_of :identifier, :in => 1..20 + validates_length_of :identifier, :in => 1..IDENTIFIER_MAX_LENGTH # donwcase letters, digits, dashes but not digits only validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :if => Proc.new { |p| p.identifier_changed? } # reserved words @@ -220,6 +223,10 @@ self.status == STATUS_ACTIVE end + def archived? + self.status == STATUS_ARCHIVED + end + # Archives the project and its descendants def archive # Check that there is no issue of a non descendant project that is assigned @@ -382,12 +389,13 @@ # Returns the mail adresses of users that should be always notified on project events def recipients - members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail} + notified_users.collect {|user| user.mail} end # Returns the users that should be notified on project events def notified_users - members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user} + # TODO: User part should be extracted to User#notify_about? + members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user} end # Returns an array of all custom fields enabled for project issues @@ -564,6 +572,18 @@ return nil end end + + # Yields the given block for each project with its level in the tree + def self.project_tree(projects, &block) + ancestors = [] + projects.sort_by(&:lft).each do |project| + while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) + ancestors.pop + end + yield project, ancestors.size + ancestors << project + end + end private