forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use resourceful routes for terms view/accept/decline
- Loading branch information
1 parent
0ffe3ce
commit 92d15db
Showing
15 changed files
with
204 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Accounts | ||
class TermsController < ApplicationController | ||
include SessionMethods | ||
|
||
layout "site" | ||
|
||
before_action :disable_terms_redirect | ||
before_action :authorize_web | ||
before_action :set_locale | ||
before_action :check_database_readable | ||
|
||
authorize_resource :class => :account_terms | ||
|
||
def show | ||
@legale = params[:legale] || OSM.ip_to_country(request.remote_ip) || Settings.default_legale | ||
@text = OSM.legal_text_for_country(@legale) | ||
|
||
if request.xhr? | ||
render :partial => "terms" | ||
else | ||
@title = t ".title" | ||
|
||
if current_user&.terms_agreed? | ||
# Already agreed to terms, so just show settings | ||
redirect_to edit_account_path | ||
elsif current_user.nil? | ||
redirect_to login_path(:referer => request.fullpath) | ||
end | ||
end | ||
end | ||
|
||
def update | ||
@title = t "users.new.title" | ||
|
||
if params[:decline] || !(params[:read_tou] && params[:read_ct]) | ||
if current_user | ||
current_user.terms_seen = true | ||
|
||
flash[:notice] = { :partial => "accounts/terms/terms_declined_flash" } if current_user.save | ||
|
||
referer = safe_referer(params[:referer]) if params[:referer] | ||
|
||
redirect_to referer || edit_account_path | ||
elsif params[:decline] | ||
redirect_to t("users.terms.declined"), :allow_other_host => true | ||
else | ||
redirect_to account_terms_path | ||
end | ||
elsif current_user | ||
unless current_user.terms_agreed? | ||
current_user.consider_pd = params[:user][:consider_pd] | ||
current_user.tou_agreed = Time.now.utc | ||
current_user.terms_agreed = Time.now.utc | ||
current_user.terms_seen = true | ||
|
||
flash[:notice] = t "users.new.terms accepted" if current_user.save | ||
end | ||
|
||
referer = safe_referer(params[:referer]) if params[:referer] | ||
|
||
redirect_to referer || edit_account_path | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require "test_helper" | ||
|
||
module Accounts | ||
class TermsControllerTest < ActionDispatch::IntegrationTest | ||
## | ||
# test all routes which lead to this controller | ||
def test_routes | ||
assert_routing( | ||
{ :path => "/account/terms", :method => :get }, | ||
{ :controller => "accounts/terms", :action => "show" } | ||
) | ||
assert_routing( | ||
{ :path => "/account/terms", :method => :put }, | ||
{ :controller => "accounts/terms", :action => "update" } | ||
) | ||
|
||
get "/user/terms" | ||
assert_redirected_to "/account/terms" | ||
end | ||
|
||
def test_show_not_logged_in | ||
get account_terms_path | ||
|
||
assert_redirected_to login_path(:referer => account_terms_path) | ||
end | ||
|
||
def test_show_agreed | ||
user = create(:user, :terms_seen => true, :terms_agreed => Date.yesterday) | ||
session_for(user) | ||
|
||
get account_terms_path | ||
assert_redirected_to edit_account_path | ||
end | ||
|
||
def test_show_not_seen_without_referer | ||
user = create(:user, :terms_seen => false, :terms_agreed => nil) | ||
session_for(user) | ||
|
||
get account_terms_path | ||
assert_response :success | ||
end | ||
|
||
def test_show_not_seen_with_referer | ||
user = create(:user, :terms_seen => false, :terms_agreed => nil) | ||
session_for(user) | ||
|
||
get account_terms_path(:referer => "/test") | ||
assert_response :success | ||
end | ||
|
||
def test_update_not_seen_without_referer | ||
user = create(:user, :terms_seen => false, :terms_agreed => nil) | ||
session_for(user) | ||
|
||
put account_terms_path, :params => { :user => { :consider_pd => true }, :read_ct => 1, :read_tou => 1 } | ||
assert_redirected_to edit_account_path | ||
assert_equal "Thanks for accepting the new contributor terms!", flash[:notice] | ||
|
||
user.reload | ||
|
||
assert user.consider_pd | ||
assert_not_nil user.terms_agreed | ||
assert user.terms_seen | ||
end | ||
|
||
def test_update_not_seen_with_referer | ||
user = create(:user, :terms_seen => false, :terms_agreed => nil) | ||
session_for(user) | ||
|
||
put account_terms_path, :params => { :user => { :consider_pd => true }, :referer => "/test", :read_ct => 1, :read_tou => 1 } | ||
assert_redirected_to "/test" | ||
assert_equal "Thanks for accepting the new contributor terms!", flash[:notice] | ||
|
||
user.reload | ||
|
||
assert user.consider_pd | ||
assert_not_nil user.terms_agreed | ||
assert user.terms_seen | ||
end | ||
|
||
# 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, :terms_agreed => nil) | ||
session_for(user) | ||
|
||
get edit_account_path | ||
assert_redirected_to account_terms_path(:referer => "/account/edit") | ||
end | ||
end | ||
end |
Oops, something went wrong.