From 1f386f6f8636cfaf4acb616713a9e180afc16bf6 Mon Sep 17 00:00:00 2001 From: Josep Egea Date: Wed, 30 Oct 2024 19:21:13 +0100 Subject: [PATCH] Move asking for user name to hint partial --- app/controllers/sessions_controller.rb | 12 +++--------- app/helpers/application_helper.rb | 2 +- app/models/user.rb | 4 ++++ app/views/application/_hint.slim | 8 ++++++++ spec/controllers/sessions_controller_spec.rb | 8 -------- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 0045ed1a6..87105b75d 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -16,19 +16,13 @@ def create begin authorization = Authorization.handle_authorization(current_user, request.env['omniauth.auth']) sign_in(authorization.user) - options = { notice: t('flash.logged_in', name: current_user.name) } + user_name = current_user.missing_name? ? '' : current_user.name + options = { notice: t('flash.logged_in', name: user_name) } rescue User::DuplicateNickname => e options = { alert: t('flash.duplicate_nick', name: e.nickname) } end - redirect_path = request.env['omniauth.origin'].presence || root_path - - if current_user&.missing_name? - options = { alert: t('flash.update_profile_details') } - redirect_path = edit_user_path(current_user) - end - - redirect_to redirect_path, options + redirect_to request.env['omniauth.origin'].presence || root_path, options end def destroy diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c6b24a9e0..588bb83f9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -88,7 +88,7 @@ def hint(close = true) end def user_name(user) - user.missing_name? ? '-' : user.name + user.display_name end private diff --git a/app/models/user.rb b/app/models/user.rb index de0e9bb07..f425c6189 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -123,6 +123,10 @@ def missing_name? name == EMPTY_NAME end + def display_name + missing_name? ? '-' : name + end + class DuplicateNickname < StandardError attr_reader :nickname diff --git a/app/views/application/_hint.slim b/app/views/application/_hint.slim index 175a13570..6544c5f62 100644 --- a/app/views/application/_hint.slim +++ b/app/views/application/_hint.slim @@ -25,3 +25,11 @@ li.mb-4 span.job-toggle= link_to fa_icon("chevron-up"), '#', title: t("hint.click_to_refresh") if index == 0 .job.ml-4== job_description(job) + +- if current_user&.missing_name? + = hint(false) do + .highlights + => fa_icon("exclamation-triangle") + strong=> t("flash.update_profile_details") + - unless current_page?(edit_user_path(current_user)) + = link_to t("login.edit_profile"), edit_user_path(current_user) diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index b86d95189..5cb69a294 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -62,13 +62,5 @@ expect(response).to have_http_status(:unprocessable_entity) end end - - context 'GET :create' do - it 'creates the user and redirects to edit', :aggregate_failures do - get :create, params: { provider: :email } - expect(controller.send(:signed_in?)).to be_truthy - expect(response).to redirect_to(edit_user_path(User.last)) - end - end end end