]> source.dussan.org Git - redmine.git/commitdiff
Merged r14619 (#20282).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Oct 2015 06:36:58 +0000 (06:36 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Oct 2015 06:36:58 +0000 (06:36 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.1-stable@14649 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/functional/projects_controller_test.rb
test/object_helpers.rb

index aacb01c15dc5a32ebf67ff08dc4a5e7c27f9fcdf..e30fc9fdae8e5c53d6a3e88dbbf038e634562a28 100644 (file)
@@ -687,12 +687,14 @@ class Project < ActiveRecord::Base
     attrs = attrs.deep_dup
 
     @unallowed_parent_id = nil
-    parent_id_param = attrs['parent_id'].to_s
-    if parent_id_param.blank? || parent_id_param != parent_id.to_s
-      p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil
-      unless allowed_parents(user).include?(p)
-        attrs.delete('parent_id')
-        @unallowed_parent_id = true
+    if new_record? || attrs.key?('parent_id')
+      parent_id_param = attrs['parent_id'].to_s
+      if new_record? || parent_id_param != parent_id.to_s
+        p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil
+        unless allowed_parents(user).include?(p)
+          attrs.delete('parent_id')
+          @unallowed_parent_id = true
+        end
       end
     end
 
index 2efb98ccdedb1a6e53c4ae94a212561a96d1f0bc..e4e74521d276cee70fdc8d54b2b971f907424cca 100644 (file)
@@ -486,6 +486,17 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_equal 'eCookbook', Project.find(1).name
   end
 
+  def test_update_child_project_without_parent_permission_should_not_show_validation_error
+    child = Project.generate_with_parent!
+    user = User.generate!
+    User.add_to_project(user, child, Role.generate!(:permissions => [:edit_project]))
+    @request.session[:user_id] = user.id
+
+    post :update, :id => child.id, :project => {:name => 'Updated'}
+    assert_response 302
+    assert_match /Successful update/, flash[:notice]
+  end
+
   def test_modules
     @request.session[:user_id] = 2
     Project.find(1).enabled_module_names = ['issue_tracking', 'news']
index 74f82b68b4bcaebc89f07b9f83e10a6a21cbece3..0f4a78d50bf5de4db740f5ea97cae84e6c27253e 100644 (file)
@@ -39,7 +39,10 @@ module ObjectHelpers
     project
   end
 
-  def Project.generate_with_parent!(parent, attributes={})
+  def Project.generate_with_parent!(*args)
+    attributes = args.last.is_a?(Hash) ? args.pop : {}
+    parent = args.size > 0 ? args.first : Project.generate!
+
     project = Project.generate!(attributes) do |p|
       p.parent = parent
     end