-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from uclibs/162-fix-500-error-on-submission
162 fix 500 error on submission
- Loading branch information
Showing
13 changed files
with
276 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# ApplicationMailer Class | ||
# ======================== | ||
# | ||
# The ApplicationMailer serves as the base class for all other mailers in the application. | ||
# It sets default settings that are common to all mailers. For instance, it sets the default | ||
# sender email address. | ||
# | ||
# Inherited From: | ||
# - ActionMailer::Base: Inherits all the functionalities provided by ActionMailer. | ||
# | ||
# Constants: | ||
# - None | ||
# | ||
# Methods: | ||
# - None (Methods would be specific to individual mailers inheriting from this class) | ||
# | ||
# Environment Variables: | ||
# - MAIL_SENDER: The default "from" email address. | ||
# | ||
# Example Usage: | ||
# ``` | ||
# class MyMailer < ApplicationMailer | ||
# def welcome_email(user) | ||
# @user = user | ||
# mail(to: @user.email, subject: 'Welcome to My Site') | ||
# end | ||
# end | ||
# ``` | ||
# | ||
# Note: Each specific mailer should inherit from this class to utilize the default settings. | ||
|
||
class ApplicationMailer < ActionMailer::Base | ||
default from: 'from@example.com' | ||
default from: ENV.fetch('MAIL_SENDER') | ||
layout 'mailer' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
# PublicationMailer | ||
# ================= | ||
# This mailer class is responsible for sending email notifications related to | ||
# publications. It extends the ApplicationMailer, inheriting its default settings, and | ||
# utilizes the MailerHelper for additional utility functions. | ||
# | ||
# Responsibilities: | ||
# - Send confirmation email notifications when a publication is submitted. | ||
# - Derive the sender's email and name from an environment variable, ensuring it's formatted correctly. | ||
# | ||
# Usage: | ||
# Call the `publication_submit` method, providing it with the submitter and the publication. | ||
# This sends an email to the submitter confirming the submission of their publication. | ||
# The email also gets BCC'd to the default sender email for tracking purposes. | ||
# | ||
# Example: | ||
# ``` | ||
# PublicationMailer.publication_submit(submitter, publication).deliver_now | ||
# ``` | ||
# | ||
# Environment Variables: | ||
# - MAIL_SENDER: Contains the default sender's email address (and optionally the sender's name). | ||
|
||
class PublicationMailer < ApplicationMailer | ||
helper MailerHelper | ||
default from: -> { ENV.fetch('MAIL_SENDER', nil) } | ||
|
||
SUBJECT = 'Publication received for Artists, Authors, Editors & Composers' | ||
|
||
def publication_submit(submitter, publication) | ||
@submitter = submitter | ||
@publication = publication | ||
receivers = "#{submitter.email_address}, #{ENV.fetch('MAIL_SENDER', nil)}" | ||
mail(to: receivers, subject: 'Publication received for Artists, Authors, Editors & Composers') | ||
sender_name, sender_email = parse_default_sender | ||
submitter_name = "#{submitter.first_name} #{submitter.last_name}" | ||
|
||
mail( | ||
to: email_address_with_name(@submitter.email_address, submitter_name), | ||
bcc: sender_email, | ||
from: email_address_with_name(sender_email, sender_name), | ||
subject: SUBJECT | ||
) | ||
end | ||
|
||
private | ||
|
||
def parse_default_sender | ||
default_sender = ENV.fetch('MAIL_SENDER') | ||
raise ArgumentError, 'SMTP From address may not be blank' if default_sender.blank? | ||
|
||
match_data = default_sender.match(/(.+?) <(.+)>/) | ||
if match_data | ||
[match_data[1], match_data[2]] # [sender_name, sender_email] | ||
else | ||
['', default_sender] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<p> | ||
Thank you for your submission of "<%= @publication.work_title %>" by: <%= all_authors_email(@publication) %>.<br><br> | ||
<% work_or_other_title = @publication.work_title || @publication.other_title || "-untitled work-" %> | ||
Thank you for your submission of "<%= work_or_other_title %>" by: <%= all_authors_email(@publication) %>.<br><br> | ||
More information about this year's event is forthcoming. If you have any questions, please contact Melissa Norris at melissa.norris@uc.edu or (513) 556-1558. | ||
</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Thank you for your submission of "<%= @publication.work_title %>" by: <%= all_authors_email(@publication) %>. | ||
<% work_or_other_title = @publication.work_title || @publication.other_title || "-untitled work-" %> | ||
Thank you for your submission of "<%= work_or_other_title %>" by: <%= all_authors_email(@publication) %>. | ||
|
||
More information about this year's event is forthcoming. If you have any questions, please contact Melissa Norris at melissa.norris@uc.edu or (513) 556-1558. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.