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

Invalid User causes 500 on application submission #338

Open
werebus opened this issue Mar 15, 2019 · 0 comments
Open

Invalid User causes 500 on application submission #338

werebus opened this issue Mar 15, 2019 · 0 comments
Labels

Comments

@werebus
Copy link
Member

werebus commented Mar 15, 2019

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 🐮

@werebus werebus added the bug label Mar 15, 2019
@werebus werebus changed the title Invalid User cuases 500 on application submission Invalid User causes 500 on application submission Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant