diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-05-31 07:16:23 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-05-31 07:16:23 +0000 |
commit | ed9f00178c65cc4b37ad2ab56cc89b1c79c4fb8b (patch) | |
tree | 3420c99029f21a21c236c4ff8c0c532dd548401e /test | |
parent | 48d40a8c8884aefc2287f2030c439578057c9516 (diff) | |
download | redmine-ed9f00178c65cc4b37ad2ab56cc89b1c79c4fb8b.tar.gz redmine-ed9f00178c65cc4b37ad2ab56cc89b1c79c4fb8b.zip |
Ability to limit member management to certain roles (#19707).
git-svn-id: http://svn.redmine.org/redmine/trunk@14293 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/members_controller_test.rb | 83 | ||||
-rw-r--r-- | test/unit/member_test.rb | 31 |
2 files changed, 112 insertions, 2 deletions
diff --git a/test/functional/members_controller_test.rb b/test/functional/members_controller_test.rb index c1f435086..5bad28745 100644 --- a/test/functional/members_controller_test.rb +++ b/test/functional/members_controller_test.rb @@ -30,6 +30,20 @@ class MembersControllerTest < ActionController::TestCase assert_response :success end + def test_new_should_propose_managed_roles_only + role = Role.find(1) + role.update! :all_roles_managed => false + role.managed_roles = Role.where(:id => [2, 3]).to_a + + get :new, :project_id => 1 + assert_response :success + assert_select 'div.roles-selection' do + assert_select 'label', :text => 'Manager', :count => 0 + assert_select 'label', :text => 'Developer' + assert_select 'label', :text => 'Reporter' + end + end + def test_xhr_new xhr :get, :new, :project_id => 1 assert_response :success @@ -52,6 +66,29 @@ class MembersControllerTest < ActionController::TestCase assert User.find(7).member_of?(Project.find(1)) end + def test_create_should_ignore_unmanaged_roles + role = Role.find(1) + role.update! :all_roles_managed => false + role.managed_roles = Role.where(:id => [2, 3]).to_a + + assert_difference 'Member.count' do + post :create, :project_id => 1, :membership => {:role_ids => [1, 2], :user_id => 7} + end + member = Member.order(:id => :desc).first + assert_equal [2], member.role_ids + end + + def test_create_should_be_allowed_for_admin_without_role + User.find(1).members.delete_all + @request.session[:user_id] = 1 + + assert_difference 'Member.count' do + post :create, :project_id => 1, :membership => {:role_ids => [1, 2], :user_id => 7} + end + member = Member.order(:id => :desc).first + assert_equal [1, 2], member.role_ids + end + def test_xhr_create assert_difference 'Member.count', 3 do xhr :post, :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]} @@ -75,14 +112,34 @@ class MembersControllerTest < ActionController::TestCase assert_match /alert/, response.body, "Alert message not sent" end - def test_edit + def test_update assert_no_difference 'Member.count' do put :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3} end assert_redirected_to '/projects/ecookbook/settings/members' end - def test_xhr_edit + def test_update_should_not_add_unmanaged_roles + role = Role.find(1) + role.update! :all_roles_managed => false + role.managed_roles = Role.where(:id => [2, 3]).to_a + member = Member.create!(:user => User.find(9), :role_ids => [3], :project_id => 1) + + put :update, :id => member.id, :membership => {:role_ids => [1, 2, 3]} + assert_equal [2, 3], member.reload.role_ids.sort + end + + def test_update_should_not_remove_unmanaged_roles + role = Role.find(1) + role.update! :all_roles_managed => false + role.managed_roles = Role.where(:id => [2, 3]).to_a + member = Member.create!(:user => User.find(9), :role_ids => [1, 3], :project_id => 1) + + put :update, :id => member.id, :membership => {:role_ids => [2]} + assert_equal [1, 2], member.reload.role_ids.sort + end + + def test_xhr_update assert_no_difference 'Member.count' do xhr :put, :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3} assert_response :success @@ -103,6 +160,28 @@ class MembersControllerTest < ActionController::TestCase assert !User.find(3).member_of?(Project.find(1)) end + def test_destroy_should_fail_with_unmanaged_roles + role = Role.find(1) + role.update! :all_roles_managed => false + role.managed_roles = Role.where(:id => [2, 3]).to_a + member = Member.create!(:user => User.find(9), :role_ids => [1, 3], :project_id => 1) + + assert_no_difference 'Member.count' do + delete :destroy, :id => member.id + end + end + + def test_destroy_should_succeed_with_managed_roles_only + role = Role.find(1) + role.update! :all_roles_managed => false + role.managed_roles = Role.where(:id => [2, 3]).to_a + member = Member.create!(:user => User.find(9), :role_ids => [3], :project_id => 1) + + assert_difference 'Member.count', -1 do + delete :destroy, :id => member.id + end + end + def test_xhr_destroy assert_difference 'Member.count', -1 do xhr :delete, :destroy, :id => 2 diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb index 2ed65543b..221cae4f8 100644 --- a/test/unit/member_test.rb +++ b/test/unit/member_test.rb @@ -159,4 +159,35 @@ class MemberTest < ActiveSupport::TestCase assert_equal -1, a <=> b assert_equal 1, b <=> a end + + def test_managed_roles_should_return_all_roles_for_role_with_all_roles_managed + member = Member.new + member.roles << Role.generate!(:permissions => [:manage_members], :all_roles_managed => true) + assert_equal Role.givable.all, member.managed_roles + end + + def test_managed_roles_should_return_all_roles_for_admins + member = Member.new(:user => User.find(1)) + member.roles << Role.generate! + assert_equal Role.givable.all, member.managed_roles + end + + def test_managed_roles_should_return_limited_roles_for_role_without_all_roles_managed + member = Member.new + member.roles << Role.generate!(:permissions => [:manage_members], :all_roles_managed => false, :managed_role_ids => [2, 3]) + assert_equal [2, 3], member.managed_roles.map(&:id).sort + end + + def test_managed_roles_should_cumulated_managed_roles + member = Member.new + member.roles << Role.generate!(:permissions => [:manage_members], :all_roles_managed => false, :managed_role_ids => [3]) + member.roles << Role.generate!(:permissions => [:manage_members], :all_roles_managed => false, :managed_role_ids => [2]) + assert_equal [2, 3], member.managed_roles.map(&:id).sort + end + + def test_managed_roles_should_return_no_roles_for_role_without_permission + member = Member.new + member.roles << Role.generate!(:all_roles_managed => true) + assert_equal [], member.managed_roles + end end |