summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-05-27 17:42:04 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-05-27 17:42:04 +0000
commit413247ee5b1643dff7923687711c77a5d90d41f5 (patch)
tree3ab2e5d182fee99cbb145f1783732db5bb46e7bc /app/models
parent70374d084e19dba21e83e8a360a62ff0168ff207 (diff)
downloadredmine-413247ee5b1643dff7923687711c77a5d90d41f5.tar.gz
redmine-413247ee5b1643dff7923687711c77a5d90d41f5.zip
Added the ability to archive projects:
* Only administrators can archive/unarchive projects. * Once archived, the project is visible on the admin project listing only. It doesn't show up anywhere else in the app. Subprojects are also archived. * Archive/unarchive preserve everything on the project (issues, members, ...). * A subproject can not be unarchived if its parent project is archived. git-svn-id: http://redmine.rubyforge.org/svn/trunk@549 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/project.rb40
-rw-r--r--app/models/query.rb6
-rw-r--r--app/models/user.rb2
3 files changed, 37 insertions, 11 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 6dd6b2644..bf83c1389 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -16,6 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Project < ActiveRecord::Base
+ # Project statuses
+ STATUS_ACTIVE = 1
+ STATUS_ARCHIVED = 9
+
has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
has_many :users, :through => :members
@@ -32,6 +36,8 @@ class Project < ActiveRecord::Base
has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
acts_as_tree :order => "name", :counter_cache => true
+ attr_protected :status
+
validates_presence_of :name, :description, :identifier
validates_uniqueness_of :name, :identifier
validates_associated :custom_values, :on => :update
@@ -52,12 +58,11 @@ class Project < ActiveRecord::Base
def issues_with_subprojects(include_subprojects=false)
conditions = nil
- if include_subprojects && children.size > 0
- ids = [id] + children.collect {|c| c.id}
+ if include_subprojects && !active_children.empty?
+ ids = [id] + active_children.collect {|c| c.id}
conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
- else
- conditions = ["#{Issue.table_name}.project_id = ?", id]
end
+ conditions ||= ["#{Issue.table_name}.project_id = ?", id]
Issue.with_scope :find => { :conditions => conditions } do
yield
end
@@ -71,12 +76,33 @@ class Project < ActiveRecord::Base
def self.visible_by(user=nil)
if user && user.admin?
- return nil
+ return ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
elsif user && !user.memberships.empty?
- return ["#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true]
+ return ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))", true]
else
- return ["#{Project.table_name}.is_public = ?", true]
+ return ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = ?", true]
+ end
+ end
+
+ def active?
+ self.status == STATUS_ACTIVE
+ end
+
+ def archive
+ # Archive subprojects if any
+ children.each do |subproject|
+ subproject.archive
end
+ update_attribute :status, STATUS_ARCHIVED
+ end
+
+ def unarchive
+ return false if parent && !parent.active?
+ update_attribute :status, STATUS_ACTIVE
+ end
+
+ def active_children
+ children.select {|child| child.active?}
end
# Returns an array of all custom fields enabled for project issues
diff --git a/app/models/query.rb b/app/models/query.rb
index 47468ba12..145ff851a 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -95,8 +95,8 @@ class Query < ActiveRecord::Base
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values }
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
- unless @project.children.empty?
- @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.children.collect{|s| [s.name, s.id.to_s] } }
+ unless @project.active_children.empty?
+ @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
end
@project.all_custom_fields.select(&:is_filter?).each do |field|
case field.field_format
@@ -164,7 +164,7 @@ class Query < ActiveRecord::Base
if operator_for("subproject_id") == "="
subproject_ids = values_for("subproject_id").each(&:to_i)
else
- subproject_ids = project.children.collect{|p| p.id}
+ subproject_ids = project.active_children.collect{|p| p.id}
end
sql << " AND #{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
else
diff --git a/app/models/user.rb b/app/models/user.rb
index d025651c4..917745b22 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,7 +23,7 @@ class User < ActiveRecord::Base
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
- has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :order => "#{Project.table_name}.name", :dependent => :delete_all
+ has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :conditions => "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}", :order => "#{Project.table_name}.name", :dependent => :delete_all
has_many :projects, :through => :memberships
has_many :custom_values, :dependent => :delete_all, :as => :customized
has_one :preference, :dependent => :destroy, :class_name => 'UserPreference'