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

Attempt to address volunteer#create invalid email error in bot-bugsag #6224

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

7riumph
Copy link
Collaborator

@7riumph 7riumph commented Feb 13, 2025

What github issue is this PR for, if any?

Resolves #NaN

Noticed an error with volunteers#create through the discord.

Likely due to an invalid or non standard email.

I refactored it to ensure in the volunteers_controller create function....

  • Emails are not blank
  • Emails are properly formatted (regex)

Before an invite can be sent to the user.

@github-actions github-actions bot added the ruby Pull requests that update Ruby code label Feb 13, 2025
@@ -31,14 +31,17 @@ def create
@volunteer = current_organization.volunteers.new(create_volunteer_params)
authorize @volunteer

if @volunteer.save
if @volunteer.save && @volunteer.email.match?(URI::MailTo::EMAIL_REGEXP)
Copy link
Collaborator

Choose a reason for hiding this comment

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

good

Copy link
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

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

Needs specs but a good start!

@FireLemons
Copy link
Collaborator

FireLemons commented Feb 19, 2025

The regex addition didn't solve the real life error case of an email address with a close parentheses at the end [email protected]) and I think it's because it's technically a correct email format according to the RFC URI::MailTo::EMAIL_PATTERN is based off of so instead I think it's better to error handle email send attempts.

for volunteers_controller.rb:35

    if @volunteer.save
      @volunteer.invite!(current_user)
      # call short io api here
      invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: @volunteer.raw_invitation_token, host: request.base_url)

I suggest wrapping @volunteer.invite!(current_user) in a try catch so not only does it catch emails with invalid formats i.e. [email protected])(from bugsnag) but it will also catch domains and email addresses that don't exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants