diff options
author | Go MAEDA <maeda@farend.jp> | 2023-01-19 11:56:53 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2023-01-19 11:56:53 +0000 |
commit | f9f617caa3dab03d4594b826effe171d65f77338 (patch) | |
tree | 7125980798dafa88646c1bd90af15c08d78334a1 /test/unit | |
parent | 613147aba93134132910e5187314fe125b3efa5f (diff) | |
download | redmine-f9f617caa3dab03d4594b826effe171d65f77338.tar.gz redmine-f9f617caa3dab03d4594b826effe171d65f77338.zip |
Merged r22063 from trunk to 5.0-stable (#38070).
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@22064 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/role_test.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/unit/role_test.rb b/test/unit/role_test.rb index 8ec078648..48fb06000 100644 --- a/test/unit/role_test.rb +++ b/test/unit/role_test.rb @@ -101,6 +101,82 @@ class RoleTest < ActiveSupport::TestCase assert_equal false, role.has_permission?(:delete_issues) end + def test_permissions_all_trackers? + role = Role.create!(:name => 'Test', :permissions => [:view_issues]) + assert_equal true, role.permissions_all_trackers?(:view_issues) + assert_equal false, role.permissions_all_trackers?(:edit_issues) + + role.set_permission_trackers :view_issues, [1] + role.set_permission_trackers :edit_issues, [1] + assert_equal false, role.permissions_all_trackers?(:view_issues) + assert_equal false, role.permissions_all_trackers?(:edit_issues) + + role.set_permission_trackers :view_issues, :all + role.set_permission_trackers :edit_issues, :all + assert_equal true, role.permissions_all_trackers?(:view_issues) + assert_equal false, role.permissions_all_trackers?(:edit_issues) + end + + def test_permissions_all_trackers_considers_base_permission + role = Role.create!(:name => 'Test', :permissions => [:view_issues]) + assert_equal true, role.permissions_all_trackers?(:view_issues) + + role.remove_permission!(:view_issues) + assert_equal false, role.permissions_all_trackers?(:view_issues) + end + + def test_permissions_tracker_ids? + role = Role.create!(:name => 'Test', :permissions => [:view_issues]) + assert_equal false, role.permissions_tracker_ids?(:view_issues, 1) + assert_equal false, role.permissions_tracker_ids?(:edit_issues, 1) + + role.set_permission_trackers :view_issues, [1, 2, 3] + role.set_permission_trackers :edit_issues, [1, 2, 3] + + assert_equal true, role.permissions_tracker_ids?(:view_issues, 1) + assert_equal false, role.permissions_tracker_ids?(:edit_issues, 1) + end + + def test_permissions_tracker_ids_considers_base_permission + role = Role.create!(:name => 'Test', :permissions => [:view_issues]) + role.set_permission_trackers :view_issues, [1, 2, 3] + assert_equal true, role.permissions_tracker_ids?(:view_issues, 1) + + role.remove_permission!(:view_issues) + assert_equal false, role.permissions_tracker_ids?(:view_issues, 1) + end + + def test_permissions_tracker? + tracker = Tracker.find(1) + role = Role.create!(:name => 'Test', :permissions => [:view_issues]) + assert_equal true, role.permissions_tracker?(:view_issues, 1) + assert_equal false, role.permissions_tracker?(:edit_issues, 1) + + role.set_permission_trackers :view_issues, [1] + role.set_permission_trackers :edit_issues, [1] + assert_equal true, role.permissions_tracker?(:view_issues, tracker) + assert_equal false, role.permissions_tracker?(:edit_issues, tracker) + + role.set_permission_trackers :view_issues, [2] + role.set_permission_trackers :edit_issues, [2] + assert_equal false, role.permissions_tracker?(:view_issues, tracker) + assert_equal false, role.permissions_tracker?(:edit_issues, tracker) + + role.set_permission_trackers :view_issues, :all + role.set_permission_trackers :edit_issues, :all + assert_equal true, role.permissions_tracker?(:view_issues, tracker) + assert_equal false, role.permissions_tracker?(:edit_issues, tracker) + end + + def test_permissions_tracker_considers_base_permission + role = Role.create!(:name => 'Test', :permissions => [:edit_isues]) + role.set_permission_trackers :view_issues, [1, 2, 3] + assert_equal false, role.permissions_tracker_ids?(:view_issues, 1) + + role.set_permission_trackers :view_issues, :all + assert_equal false, role.permissions_tracker_ids?(:view_issues, 1) + end + def test_has_permission_without_permissions role = Role.create!(:name => 'Test') assert_equal false, role.has_permission?(:delete_issues) |