From 01ab34d4012ab80ff8d14e2e35b68c2dc5ccc2a5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 20 Dec 2008 17:45:40 +0000 Subject: [PATCH] All ancestors must be active to unarchive a project. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/work@2155 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- nested_projects/app/models/project.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nested_projects/app/models/project.rb b/nested_projects/app/models/project.rb index ab2a5f982..84c6c38ff 100644 --- a/nested_projects/app/models/project.rb +++ b/nested_projects/app/models/project.rb @@ -165,6 +165,7 @@ class Project < ActiveRecord::Base self.status == STATUS_ACTIVE end + # Archives the project and its descendants recursively def archive # Archive subprojects if any children.each do |subproject| @@ -173,11 +174,14 @@ class Project < ActiveRecord::Base update_attribute :status, STATUS_ARCHIVED end + # Unarchives the project + # All its ancestors must be active def unarchive - return false if parent && !parent.active? + return false if ancestors.detect {|a| !a.active?} update_attribute :status, STATUS_ACTIVE end + # Returns an array of projects the project can be moved to def possible_parents @possible_parents ||= (Project.active.find(:all) - self_and_descendants) end