-
Notifications
You must be signed in to change notification settings - Fork 166
LG-4449 Implement rules of use for existing users #5040
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
71afd96
LG-4449 Implement rules of use for existing users
stevegsa 3011474
Misc
stevegsa bccc5f0
Misc
stevegsa ee4909d
Misc
stevegsa 6b113cb
Misc
stevegsa c80eae2
Misc
stevegsa 8e9b9a0
Controller under users
stevegsa 3a7e590
UpdateUser
stevegsa 0b6de33
Drop render
stevegsa 50f48af
MarketingSite.security_and_privacy_practices_url
stevegsa 5dc3e33
RULES_OF_USE_SUBMITTED
stevegsa d46eda2
Move view
stevegsa f5f6be1
MarketingSite.security_and_privacy_practices_url
stevegsa 43503aa
Users routes
stevegsa 4733a24
Revert
stevegsa 788f95d
Ands
stevegsa 47f8348
Translations
stevegsa ba0ae24
overview_html
stevegsa 54c6214
Spec
stevegsa 7d811bb
more spec
stevegsa 958493b
next_url_after_valid_authentication
stevegsa 487cdfa
Unused p
stevegsa cc1e910
Unused param instructions
stevegsa a1b2336
Remove request_id
stevegsa b057bbc
Simply add [required] to the selector in form-validation.js
stevegsa 23b9289
rules of use url
stevegsa a9575b0
normalize yaml
stevegsa 4e0782f
Quotes
stevegsa 05f1c18
normalize
stevegsa 4a8df62
Update url
stevegsa 3b482f1
FormResponse.new(success: success, errors: errors)
stevegsa 9a71c09
Smoke test updates
stevegsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,51 @@ | ||
| module Users | ||
| class RulesOfUseController < ApplicationController | ||
| before_action :confirm_signed_in | ||
| before_action :confirm_need_to_accept_rules_of_use | ||
|
|
||
| def new | ||
| analytics.track_event(Analytics::RULES_OF_USE_VISIT) | ||
| @rules_of_use_form = new_rules_of_use_form | ||
| render :new, formats: :html | ||
| end | ||
|
|
||
| def create | ||
| @rules_of_use_form = new_rules_of_use_form | ||
|
|
||
| result = @rules_of_use_form.submit(permitted_params) | ||
|
|
||
| analytics.track_event(Analytics::RULES_OF_USE_SUBMITTED, result.to_h) | ||
|
|
||
| if result.success? | ||
| process_successful_agreement_to_rules_of_use | ||
| else | ||
| render :new | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def new_rules_of_use_form | ||
| RulesOfUseForm.new(current_user) | ||
| end | ||
|
|
||
| def process_successful_agreement_to_rules_of_use | ||
| redirect_to user_two_factor_authentication_url | ||
| end | ||
|
|
||
| def confirm_signed_in | ||
| return if signed_in? | ||
| redirect_to root_url | ||
| end | ||
|
|
||
| def confirm_need_to_accept_rules_of_use | ||
| return unless current_user.accepted_terms_at | ||
|
|
||
| redirect_to user_two_factor_authentication_url | ||
| end | ||
|
|
||
| def permitted_params | ||
| params.require(:user).permit(:terms_accepted) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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,42 @@ | ||
| class RulesOfUseForm | ||
| include ActiveModel::Model | ||
| include ActionView::Helpers::TranslationHelper | ||
|
|
||
| validate :validate_terms_accepted | ||
|
|
||
| attr_reader :terms_accepted | ||
|
|
||
| def self.model_name | ||
| ActiveModel::Name.new(self, nil, 'User') | ||
| end | ||
|
|
||
| def initialize(user) | ||
| @user = user | ||
| end | ||
|
|
||
| def validate_terms_accepted | ||
| return if @terms_accepted | ||
|
|
||
| errors.add(:terms_accepted, t('errors.rules_of_use')) | ||
| end | ||
|
|
||
| def submit(params) | ||
| @terms_accepted = params[:terms_accepted] == 'true' | ||
| if valid? | ||
| process_successful_submission | ||
| else | ||
| self.success = false | ||
| end | ||
|
|
||
| FormResponse.new(success: success, errors: errors) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_accessor :success, :user | ||
|
|
||
| def process_successful_submission | ||
| self.success = true | ||
| UpdateUser.new(user: user, attributes: { accepted_terms_at: Time.zone.now }).call | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| <% title t('titles.registrations.new') %> | ||
|
|
||
| <h1><%= t('titles.rules_of_use') %></h1> | ||
|
|
||
| <p> | ||
| <%= t('users.rules_of_use.overview_html', | ||
| link: new_window_link_to(t('titles.rules_of_use'), | ||
| MarketingSite.rules_of_use_url)) %> | ||
| </p> | ||
|
|
||
| <%= t('users.rules_of_use.details_html') %> | ||
| <div class='margin-bottom-6'> | ||
| <%= validated_form_for(@rules_of_use_form, | ||
| html: { autocomplete: 'off', role: 'form' }, | ||
| url: rules_of_use_path) do |f| %> | ||
|
|
||
| <div class="margin-bottom-3"> | ||
| <%= f.check_box :terms_accepted, { class: 'usa-checkbox__input', | ||
| required: true, aria: { invalid: false } }, true, false %> | ||
| <label for="user_terms_accepted" class="usa-checkbox__label"> | ||
| <%= t('users.rules_of_use.check_box_to_accept') %> | ||
| <%= new_window_link_to(t('titles.rules_of_use'), MarketingSite.rules_of_use_url) %> | ||
| </label> | ||
| <div class="usa-error-message usa-error-message--with-icon display-if-invalid" role="alert"> | ||
| <%= t('errors.rules_of_use') %> | ||
| </div> | ||
| </div> | ||
|
|
||
| <%= f.button :button, t('forms.buttons.continue'), type: :submit, | ||
| class: 'usa-button--big grid-col-8 mobile-lg:grid-col-6' %> | ||
| <% end %> | ||
| </div> | ||
|
|
||
| <%= render 'shared/cancel', link: decorated_session.cancel_link_url %> | ||
|
|
||
| <%= javascript_packs_tag_once 'accept-terms-button' %> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,123 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Users::RulesOfUseController do | ||
| describe 'before_actions' do | ||
| it 'includes appropriate before_actions' do | ||
| expect(subject).to have_actions( | ||
| :before, | ||
| :confirm_signed_in, | ||
| :confirm_need_to_accept_rules_of_use, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| describe '#new' do | ||
| subject(:action) { get :new } | ||
|
|
||
| context 'with a user that has not accepted the rules of use' do | ||
| before do | ||
| sign_in_before_2fa_with_user_that_needs_to_accept_rules_of_use | ||
| end | ||
|
|
||
| it 'renders' do | ||
| action | ||
| expect(response).to render_template(:new) | ||
| end | ||
|
|
||
| it 'logs an analytics event for visiting' do | ||
| stub_analytics | ||
| expect(@analytics).to receive(:track_event).with(Analytics::RULES_OF_USE_VISIT) | ||
|
|
||
| action | ||
| end | ||
| end | ||
|
|
||
| context 'with a user that has accepted the rules of use' do | ||
| before do | ||
| sign_in_before_2fa | ||
| end | ||
|
|
||
| it 'redirects to mfa' do | ||
| action | ||
|
|
||
| expect(response).to redirect_to user_two_factor_authentication_url | ||
| end | ||
| end | ||
|
|
||
| context 'with no user signed in' do | ||
| it 'redirects to root' do | ||
| action | ||
|
|
||
| expect(response).to redirect_to root_url | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '#create' do | ||
| context 'when the user needs to accept the rules of use and does accept them' do | ||
| subject(:action) do | ||
| post :create, params: { user: { terms_accepted: 'true' } } | ||
| end | ||
|
|
||
| before do | ||
| sign_in_before_2fa_with_user_that_needs_to_accept_rules_of_use | ||
| end | ||
|
|
||
| it 'updates the user accepted terms at timestamp' do | ||
| action | ||
|
|
||
| expect(controller.current_user.reload.accepted_terms_at).to be_present | ||
| end | ||
|
|
||
| it 'redirects to the two factor authentication page' do | ||
| action | ||
|
|
||
| expect(response).to redirect_to user_two_factor_authentication_url | ||
| end | ||
|
|
||
| it 'logs a successful analytics event' do | ||
| stub_analytics | ||
| expect(@analytics).to receive(:track_event). | ||
| with(Analytics::RULES_OF_USE_SUBMITTED, hash_including(success: true)) | ||
|
|
||
| action | ||
| end | ||
| end | ||
|
|
||
| context 'when the user needs to accept the rules of use and does not accept them' do | ||
| subject(:action) do | ||
| post :create, params: { user: { terms_accepted: 'false' } } | ||
| end | ||
|
|
||
| before do | ||
| sign_in_before_2fa_with_user_that_needs_to_accept_rules_of_use | ||
| end | ||
|
|
||
| it 'does not updates the user accepted terms at timestamp' do | ||
| action | ||
|
|
||
| expect(controller.current_user.reload.accepted_terms_at).to be_nil | ||
| end | ||
|
|
||
| it 'redirects to the two factor authentication page' do | ||
| action | ||
|
|
||
| expect(response).to render_template(:new) | ||
| end | ||
|
|
||
| it 'logs a failure analytics event' do | ||
| stub_analytics | ||
| expect(@analytics).to receive(:track_event). | ||
| with(Analytics::RULES_OF_USE_SUBMITTED, hash_including(success: false)) | ||
|
|
||
| action | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def sign_in_before_2fa_with_user_that_needs_to_accept_rules_of_use | ||
| user = create(:user, :signed_up) | ||
| UpdateUser.new(user: user, attributes: {accepted_terms_at: nil}).call | ||
| sign_in_before_2fa(user) | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.