@@ -680,14 +680,16 class Project < ActiveRecord::Base | |||||
680 | attrs = attrs.deep_dup |
|
680 | attrs = attrs.deep_dup | |
681 |
|
681 | |||
682 | @unallowed_parent_id = nil |
|
682 | @unallowed_parent_id = nil | |
|
683 | if new_record? || attrs.key?('parent_id') | |||
683 | parent_id_param = attrs['parent_id'].to_s |
|
684 | parent_id_param = attrs['parent_id'].to_s | |
684 |
if |
|
685 | if new_record? || parent_id_param != parent_id.to_s | |
685 | p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil |
|
686 | p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil | |
686 | unless allowed_parents(user).include?(p) |
|
687 | unless allowed_parents(user).include?(p) | |
687 | attrs.delete('parent_id') |
|
688 | attrs.delete('parent_id') | |
688 | @unallowed_parent_id = true |
|
689 | @unallowed_parent_id = true | |
689 | end |
|
690 | end | |
690 | end |
|
691 | end | |
|
692 | end | |||
691 |
|
693 | |||
692 | super(attrs, user) |
|
694 | super(attrs, user) | |
693 | end |
|
695 | end |
@@ -486,6 +486,17 class ProjectsControllerTest < ActionController::TestCase | |||||
486 | assert_equal 'eCookbook', Project.find(1).name |
|
486 | assert_equal 'eCookbook', Project.find(1).name | |
487 | end |
|
487 | end | |
488 |
|
488 | |||
|
489 | def test_update_child_project_without_parent_permission_should_not_show_validation_error | |||
|
490 | child = Project.generate_with_parent! | |||
|
491 | user = User.generate! | |||
|
492 | User.add_to_project(user, child, Role.generate!(:permissions => [:edit_project])) | |||
|
493 | @request.session[:user_id] = user.id | |||
|
494 | ||||
|
495 | post :update, :id => child.id, :project => {:name => 'Updated'} | |||
|
496 | assert_response 302 | |||
|
497 | assert_match /Successful update/, flash[:notice] | |||
|
498 | end | |||
|
499 | ||||
489 | def test_modules |
|
500 | def test_modules | |
490 | @request.session[:user_id] = 2 |
|
501 | @request.session[:user_id] = 2 | |
491 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
|
502 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
@@ -39,7 +39,10 module ObjectHelpers | |||||
39 | project |
|
39 | project | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 |
def Project.generate_with_parent!( |
|
42 | def Project.generate_with_parent!(*args) | |
|
43 | attributes = args.last.is_a?(Hash) ? args.pop : {} | |||
|
44 | parent = args.size > 0 ? args.first : Project.generate! | |||
|
45 | ||||
43 | project = Project.generate!(attributes) do |p| |
|
46 | project = Project.generate!(attributes) do |p| | |
44 | p.parent = parent |
|
47 | p.parent = parent | |
45 | end |
|
48 | end |
General Comments 0
You need to be logged in to leave comments.
Login now