@@ -687,12 +687,14 class Project < ActiveRecord::Base | |||||
687 | attrs = attrs.deep_dup |
|
687 | attrs = attrs.deep_dup | |
688 |
|
688 | |||
689 | @unallowed_parent_id = nil |
|
689 | @unallowed_parent_id = nil | |
690 | parent_id_param = attrs['parent_id'].to_s |
|
690 | if new_record? || attrs.key?('parent_id') | |
691 |
|
|
691 | parent_id_param = attrs['parent_id'].to_s | |
692 | p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil |
|
692 | if new_record? || parent_id_param != parent_id.to_s | |
693 | unless allowed_parents(user).include?(p) |
|
693 | p = parent_id_param.present? ? Project.find_by_id(parent_id_param) : nil | |
694 | attrs.delete('parent_id') |
|
694 | unless allowed_parents(user).include?(p) | |
695 | @unallowed_parent_id = true |
|
695 | attrs.delete('parent_id') | |
|
696 | @unallowed_parent_id = true | |||
|
697 | end | |||
696 | end |
|
698 | end | |
697 | end |
|
699 | end | |
698 |
|
700 |
@@ -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