|
@@
-1016,89
+1016,72
class UserTest < ActiveSupport::TestCase
|
|
1016
|
end
|
|
1016
|
end
|
|
1017
|
end
|
|
1017
|
end
|
|
1018
|
|
|
1018
|
|
|
1019
|
context "#allowed_to?" do
|
|
1019
|
test "#allowed_to? for archived project should return false" do
|
|
1020
|
context "with a unique project" do
|
|
1020
|
project = Project.find(1)
|
|
1021
|
should "return false if project is archived" do
|
|
1021
|
project.archive
|
|
1022
|
project = Project.find(1)
|
|
1022
|
project.reload
|
|
1023
|
Project.any_instance.stubs(:status).returns(Project::STATUS_ARCHIVED)
|
|
1023
|
assert_equal false, @admin.allowed_to?(:view_issues, project)
|
|
1024
|
assert_equal false, @admin.allowed_to?(:view_issues, Project.find(1))
|
|
1024
|
end
|
|
1025
|
end
|
|
|
|
|
1026
|
|
|
|
|
|
1027
|
should "return false for write action if project is closed" do
|
|
|
|
|
1028
|
project = Project.find(1)
|
|
|
|
|
1029
|
Project.any_instance.stubs(:status).returns(Project::STATUS_CLOSED)
|
|
|
|
|
1030
|
assert_equal false, @admin.allowed_to?(:edit_project, Project.find(1))
|
|
|
|
|
1031
|
end
|
|
|
|
|
1032
|
|
|
|
|
|
1033
|
should "return true for read action if project is closed" do
|
|
|
|
|
1034
|
project = Project.find(1)
|
|
|
|
|
1035
|
Project.any_instance.stubs(:status).returns(Project::STATUS_CLOSED)
|
|
|
|
|
1036
|
assert_equal true, @admin.allowed_to?(:view_project, Project.find(1))
|
|
|
|
|
1037
|
end
|
|
|
|
|
1038
|
|
|
1025
|
|
|
1039
|
should "return false if related module is disabled" do
|
|
1026
|
test "#allowed_to? for closed project should return true for read actions" do
|
|
1040
|
project = Project.find(1)
|
|
1027
|
project = Project.find(1)
|
|
1041
|
project.enabled_module_names = ["issue_tracking"]
|
|
1028
|
project.close
|
|
1042
|
assert_equal true, @admin.allowed_to?(:add_issues, project)
|
|
1029
|
project.reload
|
|
1043
|
assert_equal false, @admin.allowed_to?(:view_wiki_pages, project)
|
|
1030
|
assert_equal false, @admin.allowed_to?(:edit_project, project)
|
|
1044
|
end
|
|
1031
|
assert_equal true, @admin.allowed_to?(:view_project, project)
|
|
|
|
|
1032
|
end
|
|
1045
|
|
|
1033
|
|
|
1046
|
should "authorize nearly everything for admin users" do
|
|
1034
|
test "#allowed_to? for project with module disabled should return false" do
|
|
1047
|
project = Project.find(1)
|
|
1035
|
project = Project.find(1)
|
|
1048
|
assert ! @admin.member_of?(project)
|
|
1036
|
project.enabled_module_names = ["issue_tracking"]
|
|
1049
|
%w(edit_issues delete_issues manage_news add_documents manage_wiki).each do |p|
|
|
1037
|
assert_equal true, @admin.allowed_to?(:add_issues, project)
|
|
1050
|
assert_equal true, @admin.allowed_to?(p.to_sym, project)
|
|
1038
|
assert_equal false, @admin.allowed_to?(:view_wiki_pages, project)
|
|
1051
|
end
|
|
1039
|
end
|
|
1052
|
end
|
|
|
|
|
1053
|
|
|
1040
|
|
|
1054
|
should "authorize normal users depending on their roles" do
|
|
1041
|
test "#allowed_to? for admin users should return true" do
|
|
1055
|
project = Project.find(1)
|
|
1042
|
project = Project.find(1)
|
|
1056
|
assert_equal true, @jsmith.allowed_to?(:delete_messages, project) #Manager
|
|
1043
|
assert ! @admin.member_of?(project)
|
|
1057
|
assert_equal false, @dlopper.allowed_to?(:delete_messages, project) #Developper
|
|
1044
|
%w(edit_issues delete_issues manage_news add_documents manage_wiki).each do |p|
|
|
1058
|
end
|
|
1045
|
assert_equal true, @admin.allowed_to?(p.to_sym, project)
|
|
1059
|
end
|
|
1046
|
end
|
|
|
|
|
1047
|
end
|
|
1060
|
|
|
1048
|
|
|
1061
|
context "with multiple projects" do
|
|
1049
|
test "#allowed_to? for normal users" do
|
|
1062
|
should "return false if array is empty" do
|
|
1050
|
project = Project.find(1)
|
|
1063
|
assert_equal false, @admin.allowed_to?(:view_project, [])
|
|
1051
|
assert_equal true, @jsmith.allowed_to?(:delete_messages, project) #Manager
|
|
1064
|
end
|
|
1052
|
assert_equal false, @dlopper.allowed_to?(:delete_messages, project) #Developper
|
|
|
|
|
1053
|
end
|
|
1065
|
|
|
1054
|
|
|
1066
|
should "return true only if user has permission on all these projects" do
|
|
1055
|
test "#allowed_to? with empty array should return false" do
|
|
1067
|
assert_equal true, @admin.allowed_to?(:view_project, Project.all.to_a)
|
|
1056
|
assert_equal false, @admin.allowed_to?(:view_project, [])
|
|
1068
|
assert_equal false, @dlopper.allowed_to?(:view_project, Project.all.to_a) #cannot see Project(2)
|
|
1057
|
end
|
|
1069
|
assert_equal true, @jsmith.allowed_to?(:edit_issues, @jsmith.projects.to_a) #Manager or Developer everywhere
|
|
|
|
|
1070
|
assert_equal false, @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects.to_a) #Dev cannot delete_issue_watchers
|
|
|
|
|
1071
|
end
|
|
|
|
|
1072
|
|
|
1058
|
|
|
1073
|
should "behave correctly with arrays of 1 project" do
|
|
1059
|
test "#allowed_to? with multiple projects" do
|
|
1074
|
assert_equal false, User.anonymous.allowed_to?(:delete_issues, [Project.first])
|
|
1060
|
assert_equal true, @admin.allowed_to?(:view_project, Project.all.to_a)
|
|
1075
|
end
|
|
1061
|
assert_equal false, @dlopper.allowed_to?(:view_project, Project.all.to_a) #cannot see Project(2)
|
|
1076
|
end
|
|
1062
|
assert_equal true, @jsmith.allowed_to?(:edit_issues, @jsmith.projects.to_a) #Manager or Developer everywhere
|
|
|
|
|
1063
|
assert_equal false, @jsmith.allowed_to?(:delete_issue_watchers, @jsmith.projects.to_a) #Dev cannot delete_issue_watchers
|
|
|
|
|
1064
|
end
|
|
1077
|
|
|
1065
|
|
|
1078
|
context "with options[:global]" do
|
|
1066
|
test "#allowed_to? with with options[:global] should return true if user has one role with the permission" do
|
|
1079
|
should "authorize if user has at least one role that has this permission" do
|
|
1067
|
@dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere
|
|
1080
|
@dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere
|
|
1068
|
@anonymous = User.find(6)
|
|
1081
|
@anonymous = User.find(6)
|
|
1069
|
assert_equal true, @jsmith.allowed_to?(:delete_issue_watchers, nil, :global => true)
|
|
1082
|
assert_equal true, @jsmith.allowed_to?(:delete_issue_watchers, nil, :global => true)
|
|
1070
|
assert_equal false, @dlopper2.allowed_to?(:delete_issue_watchers, nil, :global => true)
|
|
1083
|
assert_equal false, @dlopper2.allowed_to?(:delete_issue_watchers, nil, :global => true)
|
|
1071
|
assert_equal true, @dlopper2.allowed_to?(:add_issues, nil, :global => true)
|
|
1084
|
assert_equal true, @dlopper2.allowed_to?(:add_issues, nil, :global => true)
|
|
1072
|
assert_equal false, @anonymous.allowed_to?(:add_issues, nil, :global => true)
|
|
1085
|
assert_equal false, @anonymous.allowed_to?(:add_issues, nil, :global => true)
|
|
1073
|
assert_equal true, @anonymous.allowed_to?(:view_issues, nil, :global => true)
|
|
1086
|
assert_equal true, @anonymous.allowed_to?(:view_issues, nil, :global => true)
|
|
|
|
|
1087
|
end
|
|
|
|
|
1088
|
end
|
|
|
|
|
1089
|
end
|
|
1074
|
end
|
|
1090
|
|
|
1075
|
|
|
1091
|
# this is just a proxy method, the test only calls it to ensure it doesn't break trivially
|
|
1076
|
# this is just a proxy method, the test only calls it to ensure it doesn't break trivially
|
|
1092
|
context "#allowed_to_globally?" do
|
|
1077
|
test "#allowed_to_globally?" do
|
|
1093
|
should "proxy to #allowed_to? and reflect global permissions" do
|
|
1078
|
@dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere
|
|
1094
|
@dlopper2 = User.find(5) #only Developper on a project, not Manager anywhere
|
|
1079
|
@anonymous = User.find(6)
|
|
1095
|
@anonymous = User.find(6)
|
|
1080
|
assert_equal true, @jsmith.allowed_to_globally?(:delete_issue_watchers)
|
|
1096
|
assert_equal true, @jsmith.allowed_to_globally?(:delete_issue_watchers)
|
|
1081
|
assert_equal false, @dlopper2.allowed_to_globally?(:delete_issue_watchers)
|
|
1097
|
assert_equal false, @dlopper2.allowed_to_globally?(:delete_issue_watchers)
|
|
1082
|
assert_equal true, @dlopper2.allowed_to_globally?(:add_issues)
|
|
1098
|
assert_equal true, @dlopper2.allowed_to_globally?(:add_issues)
|
|
1083
|
assert_equal false, @anonymous.allowed_to_globally?(:add_issues)
|
|
1099
|
assert_equal false, @anonymous.allowed_to_globally?(:add_issues)
|
|
1084
|
assert_equal true, @anonymous.allowed_to_globally?(:view_issues)
|
|
1100
|
assert_equal true, @anonymous.allowed_to_globally?(:view_issues)
|
|
|
|
|
1101
|
end
|
|
|
|
|
1102
|
end
|
|
1085
|
end
|
|
1103
|
|
|
1086
|
|
|
1104
|
context "User#notify_about?" do
|
|
1087
|
context "User#notify_about?" do
|