diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-06 10:28:20 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-06 10:28:20 +0000 |
commit | 5f8e9d71182040473d4072241ce81fcadada497f (patch) | |
tree | 7701b9fed7aed50afd4dbf7fd34ec5ef08d40e5f /app/models/project.rb | |
parent | e1781235696fe23851154ebbdc913e970d3c0f3a (diff) | |
download | redmine-5f8e9d71182040473d4072241ce81fcadada497f.tar.gz redmine-5f8e9d71182040473d4072241ce81fcadada497f.zip |
Version sharing (#465) + optional inclusion of subprojects in the roadmap view (#2666).
Each version of a project can be shared with:
* subprojects
* projects in the project hierarchy: ancestors + descendants (needs versions management permission on the root project)
* projects in the project tree: root project + all its descendants (same as above)
* all projects (can be set by admin users only)
Notes:
* when sharing a version of a private project with others projects, its name will be visible within the other projects
* a project with versions used by non descendant projects can not be archived
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3123 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 5cc8ab9d0..77de59f44 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -219,13 +219,20 @@ class Project < ActiveRecord::Base self.status == STATUS_ACTIVE end - # Archives the project and its descendants recursively + # Archives the project and its descendants def archive - # Archive subprojects if any - children.each do |subproject| - subproject.archive + # Check that there is no issue of a non descendant project that is assigned + # to one of the project or descendant versions + v_ids = self_and_descendants.collect {|p| p.version_ids}.flatten + if v_ids.any? && Issue.find(:first, :include => :project, + :conditions => ["(#{Project.table_name}.lft < ? OR #{Project.table_name}.rgt > ?)" + + " AND #{Issue.table_name}.fixed_version_id IN (?)", lft, rgt, v_ids]) + return false end - update_attribute :status, STATUS_ARCHIVED + Project.transaction do + archive! + end + true end # Unarchives the project @@ -297,6 +304,7 @@ class Project < ActiveRecord::Base # move_to_child_of adds the project in last (ie.right) position move_to_child_of(p) end + Issue.update_fixed_versions_from_project_hierarchy_change true else # Can not move to the given target @@ -324,6 +332,19 @@ class Project < ActiveRecord::Base end end + # Returns a scope of the Versions used by the project + def shared_versions + @shared_versions ||= + Version.scoped(:include => :project, + :conditions => "#{Project.table_name}.id = #{id}" + + " OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" + + " #{Version.table_name}.sharing = 'system'" + + " OR (#{Project.table_name}.lft >= #{root.lft} AND #{Project.table_name}.rgt <= #{root.rgt} AND #{Version.table_name}.sharing = 'tree')" + + " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" + + " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" + + "))") + end + # Returns a hash of project users grouped by role def users_by_role members.find(:all, :include => [:user, :roles]).inject({}) do |h, m| @@ -605,4 +626,12 @@ class Project < ActiveRecord::Base self.time_entry_activities.active end end + + # Archives subprojects recursively + def archive! + children.each do |subproject| + subproject.send :archive! + end + update_attribute :status, STATUS_ARCHIVED + end end |