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

4311 - Missing display name fix #4363

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 18 additions & 12 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ def destroy
end

def create
unless params[:owner_slug].blank?
@owner = User.where(slug: params[:owner_slug]).first
end
@owner = User.find_by(slug: params[:owner_slug]) if params[:owner_slug].present?

#merge the new user information into the guest user id to change into normal user
if current_user && current_user.guest?
# Merge the new user information into the guest user id to change into normal user
if current_user&.guest?
@user = current_user
@user.update(sign_up_params)
@user.guest = false

else
@user = build_resource(sign_up_params)
end

#this is the default Devise code
# This is the default Devise code
yield resource if block_given?

if check_recaptcha(model: @user) && @user.save
# Record the `joined` deed based on Ahoy Visit
join_collection = joined_from_collection(current_visit.id)
Expand All @@ -61,7 +58,7 @@ def create
if session[:guest_user_id]
session[:guest_user_id] = nil
end

if @user.owner
@user.account_type="Trial"
@user.save
Expand All @@ -73,7 +70,8 @@ def create
if @validatable
@minimum_password_length = resource_class.password_length.min
end
respond_with resource

after_failed_sign_up_action_for(params[:registration_type]&.to_sym)
end
end

Expand All @@ -95,7 +93,6 @@ def update
end
end


def set_saml
institution = saml_provider_param
redirect_to user_omniauth_authorize_path(institution) #go to users/auth/saml/instution_name
Expand All @@ -114,7 +111,7 @@ def alert_bento()
def after_sign_up_path_for(resource)
if @user.owner
# Always send new owners to their dashboard for analytics purposes
"#{dashboard_owner_path}#freetrial"
"#{dashboard_owner_path}#freetrial"
else
# New users should be returned to where they were or to their dashboard/watchlist
if session[:user_return_to] && !landing_pages.include?(session[:user_return_to])
Expand All @@ -131,6 +128,15 @@ def after_update_path_for(resource)
edit_registration_path(resource)
end

def after_failed_sign_up_action_for(registration_type)
case registration_type
when :free_trial
render :new_trial
else
render :new
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If in case we add more registration_type, we can easily add it here

end
end

def check_recaptcha(options)
return verify_recaptcha(options) if RECAPTCHA_ENABLED
true
Expand Down
7 changes: 4 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ def email_does_not_match_denylist
end
end


def update_display_name
self.real_name = nil if self.real_name.blank?

if self.owner
self.display_name = self.real_name
else
Expand Down Expand Up @@ -287,9 +288,9 @@ def like_owner?(obj)

def display_name
if self.guest
"Guest"
'Guest'
else
self[:display_name] || self[:login]
self[:display_name].presence || self[:login]
end
end

Expand Down
5 changes: 2 additions & 3 deletions app/views/devise/registrations/new_trial.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ section.signon
<br><br>
==t('.just_want_to_transcribe', sign_up_here: (link_to t('.sign_up_here'), new_user_registration_path))


=form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
=form_for(resource, as: resource_name, url: registration_path(resource_name, registration_type: :free_trial)) do |f|
=devise_error_messages!
.signon_field
=f.label :login, t('.login')
Expand All @@ -37,4 +36,4 @@ section.signon
=f.check_box :activity_email, checked: true
=f.label :receive_activity_emails, t('devise.receive_activity_emails')
<br>
=f.button t('devise.create_account'), class: 'big'
=f.button t('devise.create_account'), class: 'big'
Loading