Remove require_terms_agreed configuration option

This has been set to true for 6 years in production. Refs #2097

As per other user settings, we set the terms as seen by default for tests,
and we can override that when necessary for specific tests.
This commit is contained in:
Andy Allan 2019-02-06 15:50:57 +01:00
parent 3795da4014
commit 35a2d66e19
8 changed files with 50 additions and 67 deletions

View file

@ -255,66 +255,50 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
# create method is simply a stand-in for any method that requires terms agreement.
# But writing oauth tests is hard, and so it's easier to put in a controller test.)
def test_api_write_and_terms_agreed_via_token
with_terms_agreed(true) do
user = create(:user, :terms_agreed => nil)
token = create(:access_token, :user => user, :allow_write_api => true)
changeset = create(:changeset, :closed)
user = create(:user, :terms_agreed => nil)
token = create(:access_token, :user => user, :allow_write_api => true)
changeset = create(:changeset, :closed)
# Hack together an oauth request - an alternative would be to sign the request properly
@request.env["oauth.version"] = 1
@request.env["oauth.strategies"] = [:token]
@request.env["oauth.token"] = token
# Hack together an oauth request - an alternative would be to sign the request properly
@request.env["oauth.version"] = 1
@request.env["oauth.strategies"] = [:token]
@request.env["oauth.token"] = token
assert_difference "ChangesetComment.count", 0 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :forbidden
# Try again, after agreement with the terms
user.terms_agreed = Time.now
user.save!
assert_difference "ChangesetComment.count", 1 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :success
assert_difference "ChangesetComment.count", 0 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :forbidden
# Try again, after agreement with the terms
user.terms_agreed = Time.now
user.save!
assert_difference "ChangesetComment.count", 1 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :success
end
# This test does the same as above, but with basic auth, to similarly test that the
# abilities take into account terms agreement too.
def test_api_write_and_terms_agreed_via_basic_auth
with_terms_agreed(true) do
user = create(:user, :terms_agreed => nil)
changeset = create(:changeset, :closed)
user = create(:user, :terms_agreed => nil)
changeset = create(:changeset, :closed)
basic_authorization user.email, "test"
basic_authorization user.email, "test"
assert_difference "ChangesetComment.count", 0 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :forbidden
# Try again, after agreement with the terms
user.terms_agreed = Time.now
user.save!
assert_difference "ChangesetComment.count", 1 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :success
assert_difference "ChangesetComment.count", 0 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
end
assert_response :forbidden
private
# Try again, after agreement with the terms
user.terms_agreed = Time.now
user.save!
def with_terms_agreed(value)
require_terms_agreed = Object.send("remove_const", "REQUIRE_TERMS_AGREED")
Object.const_set("REQUIRE_TERMS_AGREED", value)
yield
Object.send("remove_const", "REQUIRE_TERMS_AGREED")
Object.const_set("REQUIRE_TERMS_AGREED", require_terms_agreed)
assert_difference "ChangesetComment.count", 1 do
post :create, :params => { :id => changeset.id, :text => "This is a comment" }
end
assert_response :success
end
end

View file

@ -646,7 +646,7 @@ class UsersControllerTest < ActionController::TestCase
end
def test_terms_not_seen_without_referer
user = create(:user, :terms_seen => false)
user = create(:user, :terms_seen => false, :terms_agreed => nil)
session[:user] = user.id
@ -667,7 +667,7 @@ class UsersControllerTest < ActionController::TestCase
end
def test_terms_not_seen_with_referer
user = create(:user, :terms_seen => false)
user = create(:user, :terms_seen => false, :terms_agreed => nil)
session[:user] = user.id
@ -690,7 +690,7 @@ class UsersControllerTest < ActionController::TestCase
# Check that if you haven't seen the terms, and make a request that requires authentication,
# that your request is redirected to view the terms
def test_terms_not_seen_redirection
user = create(:user, :terms_seen => false)
user = create(:user, :terms_seen => false, :terms_agreed => nil)
session[:user] = user.id
get :account, :params => { :display_name => user.display_name }
@ -1098,8 +1098,8 @@ class UsersControllerTest < ActionController::TestCase
# Test whether information about contributor terms is shown for users who haven't agreed
def test_terms_not_agreed
agreed_user = create(:user, :terms_agreed => 3.days.ago)
seen_user = create(:user, :terms_seen => true)
not_seen_user = create(:user, :terms_seen => false)
seen_user = create(:user, :terms_seen => true, :terms_agreed => nil)
not_seen_user = create(:user, :terms_seen => false, :terms_agreed => nil)
get :show, :params => { :display_name => agreed_user.display_name }
assert_response :success