Skip to content

Commit 0f2fd5a

Browse files
Efrain Chu-JonBryan Madsen
authored andcommitted
Spec: admin permissions, admin users
Change-Id: I344996d1155352ba09eede187a154e0c2f4e1819 tested: 1. locking permissions 1. enable permissions 1. disabling permissions 1. go to account-level roles page 1. role permissions verified 1. add, delete new role 1. verify permissions for new role 1. add a new user 1. add short, and sortable name 1. searching for a user 1. search for bogus user returns none Reviewed-on: https://gerrit.instructure.com/10665 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bryan Madsen <bryan@instructure.com>
1 parent 54abc87 commit 0f2fd5a

3 files changed

Lines changed: 288 additions & 5 deletions

File tree

app/views/role_overrides/index.html.erb

100644100755
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<% if @managing_account_roles %>
7171
<a href="<%= context_url(@context, :context_permissions_url) %>"><%= t 'links.manage_course_roles', "Manage Course-Level Roles" %></a>
7272
<% else %>
73-
<a href="<%= context_url(@context, :context_permissions_url, :account_roles => 1) %>"><%= t 'links.manage_accoiunt_roles', "Manage Account-Level Roles" %></a>
73+
<a id="course_level_roles" href="<%= context_url(@context, :context_permissions_url, :account_roles => 1) %>"><%= t 'links.manage_accoiunt_roles', "Manage Account-Level Roles" %></a>
7474
<% end %>
7575
<% end %>
7676
</div>
@@ -93,11 +93,11 @@
9393
<% end %>
9494
<tr>
9595
<td colspan="2" style="padding: 2px 3px;">
96-
<% form_tag(context_url(@context, :add_role_context_permissions_url)) do %>
96+
<%form_tag(context_url(@context, :add_role_context_permissions_url)) do %>
9797
<input type="hidden" name="account_roles" value="1"/>
9898
<%= before_label :new_role_type, "New Role Type" %>
99-
<input type="text" name="role_type"/>
100-
<button class="button" type="submit"><%= image_tag "add.png" %> <%= t '#buttons.add', "Add" %></button>
99+
<input class= "add_new_role" type="text" name="role_type"/>
100+
<button id="add_new_role_button" class="button" type="submit"><%= image_tag "add.png" %> <%= t '#buttons.add', "Add" %></button>
101101
<% end %>
102102
</td>
103103
</tr>
@@ -143,7 +143,7 @@
143143
</tbody>
144144
</table>
145145
<div class="button-container">
146-
<button type="submit" class="button"><%= t 'buttons.save', "Save Changes" %></button>
146+
<button type="submit" class="save_permissions_changes button"><%= t 'buttons.save', "Save Changes" %></button>
147147
<a class="cancel_button button-secondary" href="<%= url_for(:back) %>"><%= t '#buttons.cancel', "Cancel" %></a>
148148
</div>
149149
<% end -%>
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/common')
2+
3+
describe "admin permissions" do
4+
it_should_behave_like "in-process server selenium tests"
5+
6+
before (:each) do
7+
course_with_admin_logged_in
8+
end
9+
10+
def has_default_permission? (permission, enrollment_type)
11+
default_permissions = Permissions.retrieve
12+
default_permissions[permission][:true_for].include? enrollment_type
13+
end
14+
15+
def get_updated_role (permission, enrollment_type)
16+
RoleOverride.first(:conditions => {:permission => permission.to_s, :enrollment_type => enrollment_type})
17+
end
18+
19+
def get_checkbox (permission, selector, enrollment_type)
20+
row = nil
21+
permissions = ff("#permissions-table tr > th")
22+
permissions.each do |elem|
23+
if (elem.text.include? permission)
24+
row = elem.find_element(:xpath, "..")
25+
break
26+
end
27+
end
28+
#enrollment type is the number corresponding to the role i.e. Student = 0, Ta = 1, Teacher = 2...
29+
element = row.find_elements(:css, selector)[enrollment_type]
30+
end
31+
32+
def checkbox_verifier(permission, enrollment_type, disable_permission = false, locked = false)
33+
selector = locked ? ".lock" : ".six-checkbox"
34+
#get the element we need
35+
check_box = get_checkbox(permission, selector, enrollment_type)
36+
#we iterate according to the permission event
37+
iterate = disable_permission ? 2 : 1
38+
iterate.times { check_box.click }
39+
f(".save_permissions_changes").click
40+
wait_for_ajax_requests
41+
check_box = get_checkbox(permission, selector, enrollment_type)
42+
if (locked)
43+
check_box.find_element(:xpath, "..").find_element(:css, "input").should have_value "true"
44+
else
45+
if (disable_permission)
46+
check_box.find_element(:css, "input").should have_value "unchecked"
47+
else
48+
check_box.find_element(:css, "input").should have_value "checked"
49+
end
50+
end
51+
end
52+
53+
def permissions_verifier(opts, default_permitted = false, disable_permission = false, locked = false)
54+
if (default_permitted)
55+
has_default_permission?(opts.keys[0], opts.values[0]).should be_true
56+
else
57+
has_default_permission?(opts.keys[0], opts.values[0]).should be_false
58+
end
59+
role = get_updated_role(opts.keys[0], opts.values[0])
60+
role.should be_present
61+
if (disable_permission)
62+
role.enabled.should be_false
63+
else
64+
if (!locked)
65+
role.enabled.should be_true
66+
end
67+
end
68+
if (locked)
69+
role.locked.should be_true
70+
else
71+
role.locked.should be_false
72+
end
73+
74+
end
75+
76+
describe "default role permissions" do
77+
before (:each) do
78+
get "/accounts/#{Account.default.id}/permissions"
79+
end
80+
81+
it "should enable and then disable read sis data for students" do
82+
checkbox_verifier("Read SIS data", 0)
83+
opts = {:read_sis => "StudentEnrollment"}
84+
permissions_verifier(opts)
85+
check_box = get_checkbox("Read SIS data", ".six-checkbox", 0)
86+
check_box.click
87+
f(".save_permissions_changes").click
88+
wait_for_ajax_requests
89+
check_box = get_checkbox("Read SIS data", ".six-checkbox", 0)
90+
check_box.find_element(:css, "input").should have_value "unchecked"
91+
permissions_verifier(opts, false, true)
92+
end
93+
94+
it "should enable read sis data for TAs" do
95+
checkbox_verifier("Read SIS data", 1)
96+
opts = {:read_sis => "TaEnrollment"}
97+
permissions_verifier(opts)
98+
end
99+
100+
it "should lock sis data for students" do
101+
checkbox_verifier("Read SIS data", 0, false, true)
102+
opts = {:read_sis => "StudentEnrollment"}
103+
permissions_verifier(opts, false, false, true)
104+
end
105+
106+
it "should check that teachers have default read sis data enabled and then disable it" do
107+
checkbox_verifier("Read SIS data", 2, true)
108+
opts= {:read_sis => "TeacherEnrollment"}
109+
permissions_verifier(opts, true, true)
110+
end
111+
112+
it "should not enable read sis data for course designer " do
113+
has_default_permission?(:read_sis, "DesignerEnrollment").should be_false
114+
designer = get_checkbox("Read SIS data", ".six-checkbox", 3)
115+
designer.attribute('title').should include_text "you do not have permission"
116+
designer.click
117+
f(".save_permissions_changes").click
118+
wait_for_ajax_requests
119+
designer_role = get_updated_role :read_sis, "DesignerEnrollment"
120+
designer_role.should be_nil
121+
designer = get_checkbox("Read SIS data", ".six-checkbox", 3)
122+
designer.find_element(:css, "input").should have_value ""
123+
end
124+
125+
it "should enable manage wiki for observer" do
126+
element_hash = checkbox_verifier("Manage wiki", 4)
127+
opts = {:manage_wiki => "ObserverEnrollment"}
128+
permissions_verifier(opts)
129+
end
130+
131+
it "should enable view all grades for designer" do
132+
element_hash = checkbox_verifier("View all grades", 3)
133+
opts = {:view_all_grades => "DesignerEnrollment"}
134+
permissions_verifier(opts)
135+
end
136+
137+
it "should navigate to manage account-level roles" do
138+
f("#course_level_roles").click
139+
wait_for_ajax_requests
140+
f("#content h2").should include_text "Account Permissions"
141+
end
142+
end
143+
144+
describe "new role permissions" do
145+
before (:each) do
146+
get "/accounts/#{Account.default.id}/permissions?account_roles=1"
147+
end
148+
149+
def add_new_role role
150+
f(".add_new_role").send_keys(role)
151+
f("#add_new_role_button").click
152+
wait_for_ajax_requests
153+
Account.default.account_membership_types.should include role
154+
f("#permissions-table tr").should include_text role
155+
end
156+
157+
it "should add a new account role type" do
158+
role = "New Role"
159+
add_new_role(role)
160+
end
161+
162+
it "should delete an added role" do
163+
role = "New Role"
164+
add_new_role(role)
165+
f(".remove_role_link").click
166+
driver.switch_to.alert.accept
167+
wait_for_ajax_requests
168+
Account.default.account_membership_types.should_not include role
169+
f("#permissions-table tr").should_not include_text role
170+
end
171+
172+
it "should enable manage permissions of new role" do
173+
role = "New Role"
174+
add_new_role(role)
175+
checkbox_verifier("Manage permissions", 1)
176+
opts={:manage_role_overrides => role}
177+
permissions_verifier(opts)
178+
end
179+
180+
it "should disable manage permissions of new role" do
181+
role = "New Role"
182+
add_new_role(role)
183+
checkbox_verifier("Manage permissions", 1, true)
184+
opts={:manage_role_overrides => role}
185+
permissions_verifier(opts, false, true)
186+
end
187+
188+
it "should lock manage permissions of new role" do
189+
role = "New Role"
190+
add_new_role(role)
191+
checkbox_verifier("Manage permissions", 1, false, true)
192+
opts={:manage_role_overrides => role}
193+
permissions_verifier(opts, false, false, true)
194+
end
195+
end
196+
end

spec/selenium/admin_users_spec.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/common')
2+
3+
describe "admin courses tab" do
4+
it_should_behave_like "in-process server selenium tests"
5+
6+
before (:each) do
7+
course_with_admin_logged_in
8+
get "/accounts/#{Account.default.id}/users"
9+
end
10+
11+
def add_user (opts={})
12+
f(".add_user_link").click
13+
name = opts[:name] ? opts[:name] : "user1"
14+
email = opts[:email] ? opts[:email] : "user1@test.com"
15+
sortable_name = opts[:sortable_name] ? opts[:sortable_name] : name
16+
confirmation = opts[:confirmation] ? opts[:confirmation] : 1
17+
short_name = opts[:short_name] ? opts[:short_name] : name
18+
if (!short_name.eql? name)
19+
replace_content f("#user_short_name"), short_name
20+
end
21+
22+
if(!sortable_name.eql? name)
23+
replace_content f("#user_sortable_name"), sortable_name
24+
end
25+
is_checked("#pseudonym_send_confirmation").should be_true
26+
if (confirmation == 0)
27+
f("#pseudonym_send_confirmation").click
28+
is_checked("#pseudonym_send_confirmation").should be_false
29+
end
30+
f("#add_user_form #user_name").send_keys name
31+
f("#pseudonym_unique_id").send_keys email
32+
f("#add_user_form [type='submit']").click
33+
wait_for_ajax_requests
34+
user = User.first(:conditions =>{:name => name})
35+
user.should be_present
36+
user.sortable_name.should eql sortable_name
37+
user.short_name.should eql short_name
38+
user.email.should eql email
39+
user
40+
end
41+
42+
it "should add an new user" do
43+
opts = {:name => "user_name"}
44+
user = add_user opts
45+
#we need to refresh the page to see the user
46+
refresh_page
47+
f("#user_#{user.id}").should be_displayed
48+
f("#user_#{user.id}").should include_text "user_name"
49+
end
50+
51+
it "should add an new user with a sortable name" do
52+
opts = {:sortable_name => "sortable name"}
53+
add_user(opts)
54+
end
55+
56+
it "should add an new user with a short name" do
57+
opts = {:short_name => "short name"}
58+
add_user(opts)
59+
end
60+
61+
it "should add a new user with confirmation disabled" do
62+
opts = {:confirmation => 0}
63+
add_user(opts)
64+
end
65+
66+
it "should search for a user and should go to it" do
67+
name = "user_1"
68+
opts = {:name => name}
69+
add_user(opts)
70+
f("#right-side #user_name").send_keys(name)
71+
ff(".ui-menu-item .ui-corner-all").count > 0
72+
wait_for_ajax_requests
73+
fj(".ui-menu-item .ui-corner-all:visible").should include_text(name)
74+
fj(".ui-menu-item .ui-corner-all:visible").click
75+
wait_for_ajax_requests
76+
f("#content h2").should include_text name
77+
end
78+
79+
it "should search for a bogus user" do
80+
name = "user_1"
81+
opts = {:name => name}
82+
add_user(opts)
83+
bogus_name = "ser 1"
84+
f("#right-side #user_name").send_keys(bogus_name)
85+
ff(".ui-menu-item .ui-corner-all").count == 0
86+
end
87+
end

0 commit comments

Comments
 (0)