Skip to content

Invalid User causes 500 on application submission #338

@werebus

Description

@werebus

Because of a long chain of nil buck-passing, A person submitting an application whose user information is invalid

Exception
An ActionView::Template::Error occurred in application_submissions#create:

  undefined method `full_name' for nil:NilClass
  app/views/jobapps_mailer/application_notification.text.erb:5:in `_app_views_jobapps_mailer_application_notification_text_erb___180014565477582410_70141218279260'


-------------------------------
Request:
-------------------------------

  * URL        : https://transit-jobapps.admin.umass.edu/application_submissions
  * HTTP Method: POST
  * IP address : 76.10.2.24
  * Parameters REDACTED
  * Timestamp  : 2019-03-14 17:27:09 -0400
  * Server : af-transit-app3.admin.umass.edu
  * Rails root : /srv/jobapps/releases/20190313144528
  * Process: 21137

-------------------------------
Backtrace:
-------------------------------

  app/views/jobapps_mailer/application_notification.text.erb:5:in `_app_views_jobapps_mailer_application_notification_text_erb___180014565477582410_70141218279260'
  app/mailers/jobapps_mailer.rb:21:in `application_notification'
  app/models/application_submission.rb:62:in `block in email_subscribers'
  app/models/application_submission.rb:60:in `email_subscribers'
  app/controllers/application_submissions_controller.rb:19:in `create'

If the attempt to create a user here:

session[:user_id] = User.create(user_attributes).id
set_current_user

fails (because of e.g. #337), session[:user_id] ends up being nil#create returns the un-persisted object on failure. And so, in the call to set_current_user leaves @current_user nil:

def set_current_user
@current_user =
if session.key? :user_id
User.find_by id: session[:user_id]
elsif session.key? :spire
User.find_by spire: session[:spire]
end
end

So, nil gets passed to the mailer when we try to email subscribers:

record.email_subscribers applicant: @current_user

def application_notification(subscription, position, applicant)
@position = position
@applicant = applicant
mail to: subscription.email,
subject: "New application for #{position.name}"
end

Applicant: <%= @applicant.full_name %>.

Needless to say, validation problems should send the user back to correct them, not cause a 500 (even if this particular validation failure is 🐮

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions