Skip to content

Commit e04b052

Browse files
committed
require terms by default, fixes CNVS-7330
they were required prior to our new settings refactors. this way we don't need to go set it in prod test plan: 1. terms should be required when registering at /register 2. terms should be required when activing an account (via course invitation email) 3. in the console, do Setting.set('terms_required', 'false') 4. terms should no longer be required on those pages Change-Id: Idb13727839b847845cd4dacde4797e4e1571b42f Reviewed-on: https://gerrit.instructure.com/22988 Reviewed-by: Mark Ericksen <marke@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
1 parent 22a4ea7 commit e04b052

11 files changed

Lines changed: 54 additions & 20 deletions

File tree

app/models/account.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def privacy_policy_url
238238
end
239239

240240
def terms_required?
241-
Setting.get('terms_required', false)
241+
Setting.get('terms_required', 'true') == 'true'
242242
end
243243

244244
def require_acceptance_of_terms?(user)

app/models/user.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,11 @@ def update_avatar_image(force_reload=false)
10831083
end
10841084

10851085
def record_acceptance_of_terms
1086-
if @require_acceptance_of_terms && @terms_of_use
1087-
preferences[:accepted_terms] = Time.now.utc
1088-
end
1086+
accept_terms if @require_acceptance_of_terms && @terms_of_use
1087+
end
1088+
1089+
def accept_terms
1090+
preferences[:accepted_terms] = Time.now.utc
10891091
end
10901092

10911093
def self.max_messages_per_day

app/views/communication_channels/confirm.html.erb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,18 @@ Which is you?", :count => @merge_opportunities.length %>
133133
</div>
134134
</div>
135135
<% end %>
136-
<% if require_terms? %>
137136
<div class="control-group">
138137
<div class="controls">
139-
<label for="user_terms_of_use">
140-
<%= check_box :user, :terms_of_use %>
141-
<%= agree_to_terms %>
142-
</label>
138+
<% if require_terms? %>
139+
<label for="user_terms_of_use">
140+
<%= check_box :user, :terms_of_use %>
141+
<%= agree_to_terms %>
142+
</label>
143+
<% else %>
144+
<a href="<%= @domain_root_account.privacy_policy_url %>" target="_blank"><%= t "#site.view_privacy_policy", "View Privacy Policy" %></a>
145+
<% end %>
143146
</div>
144147
</div>
145-
<% end %>
146148
<div class="control-group">
147149
<div class="controls">
148150
<% unless @merge_opportunities.empty? %>

spec/controllers/communication_channels_controller_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
describe "open registration" do
115115
it "should show a pre-registered user the confirmation form" do
116116
user_with_pseudonym(:password => :autogenerate)
117+
@user.accept_terms
118+
@user.save
117119
@user.should be_pre_registered
118120

119121
get 'confirm', :nonce => @cc.confirmation_code
@@ -126,6 +128,8 @@
126128

127129
it "should finalize registration for a pre-registered user" do
128130
user_with_pseudonym(:password => :autogenerate)
131+
@user.accept_terms
132+
@user.save
129133
@user.should be_pre_registered
130134

131135
post 'confirm', :nonce => @cc.confirmation_code, :register => 1, :pseudonym => {:password => 'asdfasdf', :password_confirmation => 'asdfasdf'}
@@ -152,6 +156,8 @@
152156
@account = Account.create!
153157
@course = Course.create!(:account => @account) { |c| c.workflow_state = 'available' }
154158
user_with_pseudonym(:account => @account, :password => :autogenerate)
159+
@user.accept_terms
160+
@user.save
155161
@enrollment = @course.enroll_user(@user)
156162
@pseudonym.account.should == @account
157163
@user.should be_pre_registered
@@ -190,6 +196,7 @@
190196
it "should show the confirm form for a creation_pending user" do
191197
course(:active_all => 1)
192198
user
199+
@user.accept_terms
193200
@user.update_attribute(:workflow_state, 'creation_pending')
194201
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
195202
@enrollment = @course.enroll_student(@user)
@@ -205,6 +212,7 @@
205212
it "should register creation_pending user" do
206213
course(:active_all => 1)
207214
user
215+
@user.accept_terms
208216
@user.update_attribute(:workflow_state, 'creation_pending')
209217
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
210218
@enrollment = @course.enroll_student(@user)
@@ -230,6 +238,7 @@
230238

231239
it "should show the confirm form for a creation_pending user that's logged in (masquerading)" do
232240
user
241+
@user.accept_terms
233242
@user.update_attribute(:workflow_state, 'creation_pending')
234243
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
235244
# not a full user session; just @current_user is set
@@ -243,6 +252,7 @@
243252

244253
it "should register creation_pending user that's logged in (masquerading)" do
245254
user
255+
@user.accept_terms
246256
@user.update_attribute(:workflow_state, 'creation_pending')
247257
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
248258
# not a full user session; just @current_user is set
@@ -267,6 +277,7 @@
267277
@account = Account.create!
268278
course(:active_all => 1, :account => @account)
269279
user
280+
@user.accept_terms
270281
@user.update_attribute(:workflow_state, 'creation_pending')
271282
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
272283
@enrollment = @course.enroll_student(@user)
@@ -285,6 +296,7 @@
285296
@account = Account.create!
286297
course(:active_all => 1, :account => @account)
287298
user
299+
@user.accept_terms
288300
@user.update_attribute(:workflow_state, 'creation_pending')
289301
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
290302
@enrollment = @course.enroll_student(@user)
@@ -311,6 +323,7 @@
311323
it "should prepare to register a creation_pending user in the correct account (admin)" do
312324
@account = Account.create!
313325
user
326+
@user.accept_terms
314327
@user.update_attribute(:workflow_state, 'creation_pending')
315328
@account.add_user(@user)
316329
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
@@ -327,6 +340,7 @@
327340
it "should register creation_pending user in the correct account (admin)" do
328341
@account = Account.create!
329342
user
343+
@user.accept_terms
330344
@user.update_attribute(:workflow_state, 'creation_pending')
331345
@account.add_user(@user)
332346
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
@@ -350,6 +364,7 @@
350364
it "should show the confirm form for old creation_pending users that have a pseudonym" do
351365
course(:active_all => 1)
352366
user
367+
@user.accept_terms
353368
@user.update_attribute(:workflow_state, 'creation_pending')
354369
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
355370
@enrollment = @course.enroll_student(@user)
@@ -364,6 +379,7 @@
364379
it "should work for old creation_pending users that have a pseudonym" do
365380
course(:active_all => 1)
366381
user
382+
@user.accept_terms
367383
@user.update_attribute(:workflow_state, 'creation_pending')
368384
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
369385
@enrollment = @course.enroll_student(@user)
@@ -391,6 +407,7 @@
391407
user_with_pseudonym(:active_all => 1, :username => 'jt@instructure.com')
392408
course(:active_all => 1)
393409
user
410+
@user.accept_terms
394411
@user.update_attribute(:workflow_state, 'creation_pending')
395412
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
396413
@enrollment = @course.enroll_student(@user)
@@ -407,6 +424,7 @@
407424
user_with_pseudonym(:active_all => 1, :username => 'jt@instructure.com')
408425
course(:active_all => 1)
409426
user
427+
@user.accept_terms
410428
@user.update_attribute(:workflow_state, 'creation_pending')
411429
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
412430
@enrollment = @course.enroll_student(@user)
@@ -562,6 +580,7 @@
562580

563581
it "should accept an invitation when creating a new user" do
564582
course_with_student(:active_course => 1)
583+
@user.accept_terms
565584
@user.update_attribute(:workflow_state, 'creation_pending')
566585
@cc = @user.communication_channels.create!(:path => 'jt@instructure.com')
567586

spec/controllers/tours_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
end
1010

1111
it "should add dismissed tours to user preferences" do
12-
@user.preferences.should be_empty
12+
@user.preferences[:dismissed_tours].should be_nil
1313
delete 'dismiss', :name => 'FakeTour'
1414
@user.reload
1515
@user.preferences[:dismissed_tours].should == {:fake_tour => 1}

spec/controllers/users_controller_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,19 @@
275275
p.user.communication_channels.first.path.should == 'jacob@instructure.com'
276276
end
277277

278-
it "should validate acceptance of the terms if required" do
279-
Setting.set('terms_required', true)
278+
it "should validate acceptance of the terms" do
280279
post 'create', :pseudonym => { :unique_id => 'jacob@instructure.com' }, :user => { :name => 'Jacob Fugal' }
281280
response.status.should =~ /400 Bad Request/
282281
json = JSON.parse(response.body)
283282
json["errors"]["user"]["terms_of_use"].should be_present
284283
end
285284

285+
it "should not validate acceptance of the terms if not required" do
286+
Setting.set('terms_required', 'false')
287+
post 'create', :pseudonym => { :unique_id => 'jacob@instructure.com' }, :user => { :name => 'Jacob Fugal' }
288+
response.should be_success
289+
end
290+
286291
it "should require email pseudonyms by default" do
287292
post 'create', :pseudonym => { :unique_id => 'jacob' }, :user => { :name => 'Jacob Fugal', :terms_of_use => '1' }
288293
response.status.should =~ /400 Bad Request/

spec/selenium/communication_channels_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
context "confirm" do
77
it "should register the user" do
8+
Setting.set('terms_required', 'false')
89
u1 = user_with_communication_channel(:user_state => 'creation_pending')
910
get "/register/#{u1.communication_channel.confirmation_code}"
1011
set_value f('#pseudonym_password'), "asdfasdf"
@@ -15,7 +16,6 @@
1516
end
1617

1718
it "should require the terms if configured to do so" do
18-
Setting.set('terms_required', true)
1919
u1 = user_with_communication_channel(:user_state => 'creation_pending')
2020
get "/register/#{u1.communication_channel.confirmation_code}"
2121
f('input[name="user[terms_of_use]"]').should be_present
@@ -25,7 +25,6 @@
2525
end
2626

2727
it "should not require the terms if the user has already accepted them" do
28-
Setting.set('terms_required', true)
2928
u1 = user_with_communication_channel(:user_state => 'creation_pending')
3029
u1.preferences[:accepted_terms] = Time.now.utc
3130
u1.save
@@ -35,6 +34,8 @@
3534

3635
it "should allow the user to edit the pseudonym if its already taken" do
3736
u1 = user_with_communication_channel(:username => 'asdf@qwerty.com', :user_state => 'creation_pending')
37+
u1.accept_terms
38+
u1.save
3839
# d'oh, now it's taken
3940
u2 = user_with_pseudonym(:username => 'asdf@qwerty.com', :active_user => true)
4041

spec/selenium/terms_of_use_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
it_should_behave_like "in-process server selenium tests"
55

66
before do
7-
Setting.set 'terms_required', true
87
user_with_pseudonym(active_user: true)
98
end
109

spec/selenium/users_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def validate_login_info(user_id)
197197
end
198198

199199
it "should not require terms if not configured to do so" do
200+
Setting.set('terms_required', 'false')
201+
200202
get '/register'
201203

202204
%w{teacher student parent}.each do |type|
@@ -208,8 +210,6 @@ def validate_login_info(user_id)
208210
end
209211

210212
it "should require terms if configured to do so" do
211-
Setting.set('terms_required', true)
212-
213213
get "/register"
214214

215215
%w{teacher student parent}.each do |type|
@@ -237,6 +237,7 @@ def validate_login_info(user_id)
237237
f('#student_username').send_keys('student')
238238
f('#student_password').send_keys('asdfasdf')
239239
f('#student_password_confirmation').send_keys('asdfasdf')
240+
f('input[name="user[terms_of_use]"]', form).click
240241

241242
expect_new_page_load { form.submit }
242243
# confirm the user is authenticated into the dashboard
@@ -251,6 +252,7 @@ def validate_login_info(user_id)
251252
form = fj('.ui-dialog:visible form')
252253
f('#teacher_name').send_keys('teacher!')
253254
f('#teacher_email').send_keys('teacher@example.com')
255+
f('input[name="user[terms_of_use]"]', form).click
254256

255257
expect_new_page_load { form.submit }
256258
# confirm the user is authenticated into the dashboard
@@ -269,6 +271,7 @@ def validate_login_info(user_id)
269271
f('#parent_email').send_keys('parent@example.com')
270272
f('#parent_child_username').send_keys(@pseudonym.unique_id)
271273
f('#parent_child_password').send_keys('lolwut')
274+
f('input[name="user[terms_of_use]"]', form).click
272275

273276
expect_new_page_load { form.submit }
274277
# confirm the user is authenticated into the dashboard

spec/spec_helper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ def site_admin_user(opts={})
270270

271271
def user(opts={})
272272
@user = User.create!(opts.slice(:name, :short_name))
273-
@user.register! if opts[:active_user] || opts[:active_all]
273+
if opts[:active_user] || opts[:active_all]
274+
@user.accept_terms
275+
@user.register!
276+
end
274277
@user.update_attribute :workflow_state, opts[:user_state] if opts[:user_state]
275278
@user
276279
end

0 commit comments

Comments
 (0)