Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ER-876 gov one terms and conditions page #980

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def authenticate_registered_user!
authenticate_user! unless user_signed_in?
return true if current_user.registration_complete?

redirect_to edit_registration_name_path, notice: 'Please complete registration'
redirect_to edit_registration_terms_and_conditions_path, notice: 'Please complete registration'
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
end

def configure_permitted_parameters
Expand Down
35 changes: 35 additions & 0 deletions app/controllers/registration/terms_and_conditions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Registration
class TermsAndConditionsController < BaseController
def edit; end

def update
form.terms_and_conditions_agreed_at = user_params[:terms_and_conditions_agreed_at]

if form.save
if current_user.registration_complete?
redirect_to user_path, notice: t(:details_updated)
else
redirect_to edit_registration_name_path
end
else
render :edit, status: :unprocessable_entity
end
end

private

# @return [Hash]
def user_params
params.require(:user).permit(:terms_and_conditions_agreed_at)
end

# @return [Registration::NameForm]
def form
@form ||=
TermsAndConditionsForm.new(
user: current_user,
terms_and_conditions_agreed_at: current_user.terms_and_conditions_agreed_at,
)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def after_sign_in_path_for(resource)
elsif resource.private_beta_registration_complete?
static_path('new-registration')
else
edit_registration_name_path
edit_registration_terms_and_conditions_path
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def after_sign_in_path_for(resource)
elsif resource.private_beta_registration_complete?
static_path('new-registration')
else
edit_registration_name_path
edit_registration_terms_and_conditions_path
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
14 changes: 14 additions & 0 deletions app/forms/registration/terms_and_conditions_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Registration
class TermsAndConditionsForm < BaseForm
attr_accessor :terms_and_conditions_agreed_at

validates :terms_and_conditions_agreed_at, presence: true

# @return [Boolean]
def save
return false unless valid?

user.update!(terms_and_conditions_agreed_at: terms_and_conditions_agreed_at)
end
end
end
22 changes: 22 additions & 0 deletions app/views/registration/terms_and_conditions/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
= render 'user/debug'

- content_for :page_title do
= html_title 'Terms and Conditions'

.govuk-grid-row
.govuk-grid-column-two-thirds-from-desktop
= form_for form, url: registration_terms_and_conditions_path, method: :patch do |f|
= f.govuk_error_summary

h1.govuk-heading-l = t('register_terms_and_conditions.heading')

h3 = t('register_terms_and_conditions.subheading')

= f.govuk_check_boxes_fieldset :terms_and_conditions_agreed_at,
legend: { class: 'govuk-visually-hidden', text: 'Terms and conditions'}, classes: 'light-grey-box' do
= m('register_terms_and_conditions.legend')
= f.terms_and_conditions_check_box


.govuk-button-group
= f.govuk_submit t('links.continue')
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ en:
complete_registration: Thank you for creating an Early years child development training account. You can now start your first module.
update_registration: Thank you for updating your Early years child development training account. You can now continue.

# /registration/terms-and-conditions/edit
register_terms_and_conditions:
heading: Set up your training account
subheading: Agree to our terms and conditions
legend: |
To use this service, you must accept the [terms and conditions](/terms-and-conditions) and [privacy policy](/privacy-policy).

# /registration/name/edit
register_name:
heading: About you
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
end

namespace :registration do
resource :terms_and_conditions, only: %i[edit update], path: 'terms-and-conditions'
resource :name, only: %i[edit update]
resource :setting_type, only: %i[edit update], path: 'setting-type'
resource :setting_type_other, only: %i[edit update], path: 'setting-type-other'
Expand Down
1 change: 1 addition & 0 deletions config/sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
# edit registration/account
add edit_email_user_path
add edit_password_user_path
add edit_registration_terms_and_conditions_path
add edit_registration_name_path
add edit_registration_setting_type_path
add edit_registration_setting_type_other_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

it 'redirects to complete registration' do
expect(session[:id_token]).to eq decoded_id_token
expect(response).to redirect_to edit_registration_name_path
expect(response).to redirect_to edit_registration_terms_and_conditions_path
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/seed_snippets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
subject(:locales) { described_class.new.call }

it 'converts all translations' do
expect(locales.count).to be 191
expect(locales.count).to be 194
end

it 'dot separated key -> Page::Resource#name' do
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
RSpec.describe 'Authentication', type: :request do
describe 'viewing authenticate_user! controller action' do
let(:action_path) { edit_registration_name_path }
let(:action_path) { edit_registration_terms_and_conditions_path }

context 'with User not signed in' do
it 'redirects to sign in page' do
Expand Down Expand Up @@ -89,7 +89,7 @@

it 'redirects to finish registration' do
get action_path
expect(response).to redirect_to(edit_registration_name_path)
expect(response).to redirect_to(edit_registration_terms_and_conditions_path)
end

it 'displays message to complete registration' do
Expand Down
12 changes: 12 additions & 0 deletions spec/system/confirmed_user/completing_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
let(:user) { create :user, :confirmed }

it 'requires name and a setting type and email preferences and a complete' do
expect(page).to have_text('Terms and conditions')

click_button 'Continue'

expect(page).to have_text('There is a problem')
.and have_text('You must accept the terms and conditions and privacy policy to create an account.')

expect(page).to have_text('Agree to our terms and conditions')

check 'I confirm that I accept the terms and conditions and privacy policy.'
click_button 'Continue'

expect(page).to have_text('About you')
click_button 'Continue'

Expand Down
2 changes: 1 addition & 1 deletion spec/system/sign_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

context 'and enters valid credentials' do
it 'signs in successfully' do
expect(page).to have_text('About you') # extra registration
expect(page).to have_text('Agree to our terms and conditions') # extra registration
end
end

Expand Down