]> source.dussan.org Git - redmine.git/commitdiff
Merged r8865 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 5 Mar 2012 13:04:36 +0000 (13:04 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 5 Mar 2012 13:04:36 +0000 (13:04 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.3-stable@9115 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/project_test.rb

index cdb460ed61150094d2e1e2e836e4bed860559987..d6ae404984dec7aada88770ac1f5a9fa4b7b8b5f 100644 (file)
@@ -390,16 +390,21 @@ class Project < ActiveRecord::Base
 
   # Returns a scope of the Versions used by the project
   def shared_versions
-    @shared_versions ||= begin
-      r = root? ? self : root
+    if new_record?
       Version.scoped(:include => :project,
-                     :conditions => "#{Project.table_name}.id = #{id}" +
-                                    " OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
+                     :conditions => "#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND #{Version.table_name}.sharing = 'system'")
+    else
+      @shared_versions ||= begin
+        r = root? ? self : root
+        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 >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" +
                                           " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
                                           " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
                                           "))")
+      end
     end
   end
 
index 152d096c6de752d6979d4bcbf414c5d27c86c3a5..9ae389885d5ffa22abf1f61425191f4b83c1dc90 100644 (file)
@@ -586,6 +586,13 @@ class ProjectTest < ActiveSupport::TestCase
     assert !versions.collect(&:id).include?(6)
   end
 
+  def test_shared_versions_for_new_project_should_include_system_shared_versions
+    p = Project.find(5)
+    v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
+
+    assert_include v, Project.new.shared_versions
+  end
+
   def test_next_identifier
     ProjectCustomField.delete_all
     Project.create!(:name => 'last', :identifier => 'p2008040')