Skip to content

Commit

Permalink
Move asking for user name to hint partial
Browse files Browse the repository at this point in the history
  • Loading branch information
josepegea committed Oct 30, 2024
1 parent c4bc489 commit 1f386f6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
12 changes: 3 additions & 9 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def hint(close = true)
end

def user_name(user)
user.missing_name? ? '-' : user.name
user.display_name
end

private
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def missing_name?
name == EMPTY_NAME
end

def display_name
missing_name? ? '-' : name
end

class DuplicateNickname < StandardError
attr_reader :nickname

Expand Down
8 changes: 8 additions & 0 deletions app/views/application/_hint.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 0 additions & 8 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1f386f6

Please sign in to comment.