Onboarding "improvements" (#16210)

* Don't set saw_onboarding automatically

This should be set by the onboarding checkbox update (user accepted
terms of service and code of conduct).

The issue is a PATCH request to track the last seen page is sent on
the first page, _before_ the user consents to the terms via the
checkboxes.

This issue is masked by a 422 unprocessable entity response when we
don't get a username in the patch request (next commit).

* Only validate username on the username page

Every other "last page seen" dialog was returning a 422 because the
username is only submitted in the 3rd dialog "build your profile".

Only validate the username field when it's submitted, process other
onboarding updates normally.

* Remove failing test

Since the onboarding_update action no longer sets saw
onboarding (since we send the patch before they've accepted the code
of conduct), don't test that we do.

There's a parallel test for the onboarding checkbox update later in
this file that covers the checkboxes have been accepted.

* overwrite instead of merging user_params

We now initialize it empty, no need to merge params here.
This commit is contained in:
Daniel Uber 2022-01-21 10:58:05 -06:00 committed by GitHub
parent a0edc9ac7e
commit 085c566a7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View file

@ -169,15 +169,15 @@ class UsersController < ApplicationController
def onboarding_update
authorize User
user_params = { saw_onboarding: true }
user_params = {}
if params[:user]
if params.dig(:user, :username).blank?
if params[:user].key?(:username) && params[:user][:username].blank?
return render_update_response(false, "Username cannot be blank")
end
sanitize_user_params
user_params.merge!(params[:user].permit(ALLOWED_USER_PARAMS))
user_params = params[:user].permit(ALLOWED_USER_PARAMS)
end
update_result = Users::Update.call(current_user, user: user_params, profile: profile_params)

View file

@ -12,11 +12,6 @@ RSpec.describe "UsersOnboarding", type: :request do
context "when signed in" do
before { sign_in user }
it "updates saw_onboarding boolean" do
patch "/onboarding_update.json", params: {}
expect(user.saw_onboarding).to eq(true)
end
it "updates the user's last_onboarding_page attribute" do
params = { user: { last_onboarding_page: "v2: personal info form", username: "test" } }
expect do