Skip to content

params[:invite] logic in accounts_controller

Alex edited this page May 7, 2015 · 1 revision

The accounts_controller's new action accepts a params[:invite]:

before :new do
  invite = Invite.find_by_activation_code(params[:invite])
  ...

Searching for new_account_path.+invite gives us 2 locations:

# app/views/sessions/new.html.haml:9
  = link_to 'Register today', new_account_path(:invite => params[:invite]) ...
# app/views/about/_join_now_home.html.haml:19
  = link_to 'Join Now', new_account_path(:invite => params[:invite] ...

Searching for new_session_(path|url) gives us no link which might be passing over a params[:invite]. The about#home action is the root and there seems to be no usage of root_(path|url).

The line containing params[:invite] in accounts_controller#new was introduced in 64fdc86e.

# app/models/invite.rb
  def claim_url
    "http://#{ URL_HOST }/accounts/new?invite=#{activation_code}"
  end

# app/views/invites/_mail_body.rhtml
  = link_to "Click here to claim this contribution and create an Ohloh page for yourself.", invite.claim_url

# app/views/invite_notifier/invite.rhtml
...
  = render :partial => '../invites/mail_body', :locals => { :invite => @invite }

InviteNotifier's is a mailer and this link was being sent in an email. We have a Send an Invite button on contributions show page which allows us to send this email. The claim_url method was changed in 3ff9d67a:

# app/models/invite_notifier.rb
  def claim_url(invite)
    invite.invitee.nil? ? "http://#{ URL_HOST }/accounts/new?invite=#{invite.activation_code}" : "http://#{ URL_HOST }/projects/#{ invite.project_id }/contributors/#{ invite.contributor_id }?invite=#{invite.activation_code}"
  end

This was probably to handle cases where invitee was already on OpenHub. The new_account_path was removed in dc5fd0e. This was to fix a bug reported in OTWO-824 that lead a user to new account register page when they clicked on the link in invite email's web preview. There was an argument against the change since we lose the ability to invite new users to signup directly, but it was overruled during an offline discussion. No arguments were documented on why we removed the ability to create new users in this fashion, but there seemed to be a consensus on this change. Hence concluding that we do not need the params[:invite] logic in accounts_controller#new & create anymore.