]> source.dussan.org Git - redmine.git/commitdiff
Fixed: parent project field doesn't include blank value when a member with 'add subpr...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 10 Feb 2010 20:38:23 +0000 (20:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 10 Feb 2010 20:38:23 +0000 (20:38 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3405 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index b8030d7fd9345c1cc4cb74dff7ff6ca7958adef8..58ef811400ab78a021bae244820e183dffbffe37 100644 (file)
@@ -249,7 +249,7 @@ class Project < ActiveRecord::Base
     return @allowed_parents if @allowed_parents
     @allowed_parents = Project.find(:all, :conditions => Project.allowed_to_condition(User.current, :add_subprojects))
     @allowed_parents = @allowed_parents - self_and_descendants
-    if User.current.allowed_to?(:add_project, nil, :global => true)
+    if User.current.allowed_to?(:add_project, nil, :global => true) || (!new_record? && parent.nil?)
       @allowed_parents << nil
     end
     unless parent.nil? || @allowed_parents.empty? || @allowed_parents.include?(parent)
index 8b8ce585f4cb6c6ed5ae4818115df9a10511d31a..447ae1b0470ad138fd28f062eba2677d9af17f70 100644 (file)
@@ -285,6 +285,48 @@ class ProjectTest < ActiveSupport::TestCase
     assert Project.new.allowed_parents.compact.empty?
   end
   
+  def test_allowed_parents_with_add_subprojects_permission
+    Role.find(1).remove_permission!(:add_project)
+    Role.find(1).add_permission!(:add_subprojects)
+    User.current = User.find(2)
+    # new project
+    assert !Project.new.allowed_parents.include?(nil)
+    assert Project.new.allowed_parents.include?(Project.find(1))
+    # existing root project
+    assert Project.find(1).allowed_parents.include?(nil)
+    # existing child
+    assert Project.find(3).allowed_parents.include?(Project.find(1))
+    assert !Project.find(3).allowed_parents.include?(nil)
+  end
+
+  def test_allowed_parents_with_add_project_permission
+    Role.find(1).add_permission!(:add_project)
+    Role.find(1).remove_permission!(:add_subprojects)
+    User.current = User.find(2)
+    # new project
+    assert Project.new.allowed_parents.include?(nil)
+    assert !Project.new.allowed_parents.include?(Project.find(1))
+    # existing root project
+    assert Project.find(1).allowed_parents.include?(nil)
+    # existing child
+    assert Project.find(3).allowed_parents.include?(Project.find(1))
+    assert Project.find(3).allowed_parents.include?(nil)
+  end
+
+  def test_allowed_parents_with_add_project_and_subprojects_permission
+    Role.find(1).add_permission!(:add_project)
+    Role.find(1).add_permission!(:add_subprojects)
+    User.current = User.find(2)
+    # new project
+    assert Project.new.allowed_parents.include?(nil)
+    assert Project.new.allowed_parents.include?(Project.find(1))
+    # existing root project
+    assert Project.find(1).allowed_parents.include?(nil)
+    # existing child
+    assert Project.find(3).allowed_parents.include?(Project.find(1))
+    assert Project.find(3).allowed_parents.include?(nil)
+  end
+  
   def test_users_by_role
     users_by_role = Project.find(1).users_by_role
     assert_kind_of Hash, users_by_role