Skip to content

Commit

Permalink
Merge pull request #302 from fnf-org/mfl/event-emails
Browse files Browse the repository at this point in the history
Mfl/event emails
  • Loading branch information
beingmattlevy authored Sep 13, 2024
2 parents 3b9c026 + 5c60a29 commit f1eba44
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ Rails/NotNullColumn:
- 'db/migrate/20130226221916_add_user_to_ticket_request.rb'
- 'db/migrate/20130311213508_add_event_id_to_ticket_request.rb'

Rails/OutputSafety:
Exclude:
- 'app/mailers/ticket_request_mailer.rb'

# Offense count: 22
# Configuration parameters: Include.
# Include: db/**/*.rb
Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.18
1.3.19
5 changes: 5 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def guest_list
@ticket_requests = @event.admissible_requests
end

# all active guests (completed, awaiting payment)
def active_ticket_requests
@ticket_requests = @event.ticket_requests.active
end

def download_guest_list
send_file(FnF::Services::GuestListCSV.new(@event).csv,
filename: "#{@event.name} Guest List.csv".gsub(/\s+/, '-'),
Expand Down
53 changes: 36 additions & 17 deletions app/controllers/ticket_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class TicketRequestsController < ApplicationController
before_action :authenticate_user!, except: %i[create new]
before_action :set_event
before_action :set_ticket_request, except: %i[create index download payment_reminder]
before_action :set_ticket_request, except: %i[create index download payment_reminder email_ticket_holders]
before_action :require_event_admin, except: %i[create new show edit update destroy]

def index
Expand Down Expand Up @@ -60,22 +60,6 @@ def download
render_flash(flash)
end

def payment_reminder
counter = 0
@event.ticket_requests.where(status: TicketRequest::STATUS_AWAITING_PAYMENT).find_each do |ticket_request|
if ticket_request.price.positive?
Rails.logger.debug { "payment_reminder: sending reminder for ticket request: #{ticket_request.inspect}" }
TicketRequestMailer.payment_reminder(ticket_request).deliver_later
counter += 1
end
end

Rails.logger.debug { "payment_reminder: counter: #{counter}" }

redirect_to event_ticket_requests_path(@event),
notice: "Reminder emails sent to #{counter} ticket requesters!"
end

def show
return redirect_to root_path unless @ticket_request.can_view?(current_user)

Expand Down Expand Up @@ -264,6 +248,41 @@ def refund
end
end

def payment_reminder
counter = 0
@event.ticket_requests.awaiting_payment.find_each do |ticket_request|
if ticket_request.price.positive?
Rails.logger.debug { "payment_reminder: sending reminder for ticket request: #{ticket_request.inspect}" }
TicketRequestMailer.payment_reminder(ticket_request).deliver_later
counter += 1
end
end

Rails.logger.debug { "payment_reminder: counter: #{counter}" }

redirect_to event_ticket_requests_path(@event),
notice: "Reminder emails sent to #{counter} ticket requesters!"
end

def email_ticket_holders
Rails.logger.debug { "email_ticket_holders: params: #{params.inspect}" }

subject = params[:subject].strip
body = params[:body].strip
counter = 0

@event.ticket_requests.active.find_each do |ticket_request|
Rails.logger.debug { "email_ticket_holders: sending reminder for ticket request: #{ticket_request.inspect}" }
TicketRequestMailer.email_ticket_holder(ticket_request, subject, body).deliver_later
counter += 1
end

Rails.logger.debug { "email_ticket_holders: counter: #{counter}" }

redirect_to event_ticket_requests_path(@event),
notice: "Emails sent to #{counter} ticket holders!"
end

private

def ticket_request_id
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
DEFAULT_SENDER_EMAIL = 'tickets@fnf.org'
DEFAULT_REPLY_TO_EMAIL = 'tickets@fnf.org'
DEFAULT_SENDER_EMAIL = 'ticket-support@fnf.org'
DEFAULT_REPLY_TO_EMAIL = 'ticket-support@fnf.org'

layout 'email'

Expand Down
30 changes: 30 additions & 0 deletions app/mailers/ticket_request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ def payment_reminder(ticket_request)
subject: "#{@event.name} buy your tickets now!" # The subject of the email
end

# The `email_ticket_holder` method is used to send an email to ticket holders
#
# @param ticket_request [TicketRequest] The ticket request that has been confirmed
# @param subject [String] email subject line
# @param body [String] email message body
# @return [Mail::Message] The email that has been prepared to be sent.
def email_ticket_holder(ticket_request, subject, body)
self.ticket_request = ticket_request
@body = body.to_s.html_safe

if @ticket_request.awaiting_payment?
# Return if the authentication token is blank
if (@auth_token = @ticket_request.generate_user_auth_token!).blank?
Rails.logger.warn { "email_ticket_holder: no auth token for user: #{@ticket_request.inspect}" }
return
end

@payment_url = new_event_ticket_request_payment_url(event_id: @event.id, ticket_request_id: @ticket_request.id, user_token: @auth_token)
end

Rails.logger.debug { "email_ticket_holder: ticket_request: #{ticket_request.inspect} user: #{ticket_request.user.id}" }
@ticket_request_url = event_ticket_request_url(event_id: @event.id, id: @ticket_request.id)

mail to: to_email, # The recipient of the email
from: from_email, # The sender of the email
reply_to: reply_to_email, # The email address that will receive replies
content_type: 'text/html',
subject: # The subject of the email
end

private

def ticket_request=(ticket_request)
Expand Down
19 changes: 19 additions & 0 deletions app/views/events/_email_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
= form_with url: email_ticket_holders_event_ticket_requests_path(event_id: @event.id), method: :get, data: { event: @event, turbo: true, controller: 'flatpickr', target: '_blank' } do |f|
.container-fluid
.card-header.bg-primary-subtle
%legend Email All Ticket Holders
Tickets Holders Confirmed and Awaiting Payment:
%b #{count}
%hr

%h6 Subject
= f.text_field :subject, value: "#{@event.name}: ", maxlength: 80, class: 'form-control', required: true
%hr
%h6 Email Message
%p
%i Format: Plain text and simple HTML are allowed.

= f.text_area :body, rows: 5, cols: 80, class: 'form-control', required: true
= f.submit "▶︎ Send Emails", class: 'btn btn-primary btn-large',
id: 'submit-email', data: { disable_with: 'Submitting...' }
%br
17 changes: 17 additions & 0 deletions app/views/events/active_ticket_requests.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
= render partial: 'shared/nav_event', locals: { event: @event, active_tab: { email_ticket_holders: 'active' } }

.card
.card-body
- @tr_count = @ticket_requests.count
= render '/events/email_form', resource: @event, count: @tr_count
%table.table.table-condensed
%thead
%tr
%th Ticket Requesters (#{@tr_count})
%tbody
- @ticket_requests.each do |ticket_request|
%tr
%td
- user = "#{ticket_request.user.name} <#{ticket_request.user.email}>"
= link_to event_ticket_request_path(@event, ticket_request) do
%span= user
3 changes: 2 additions & 1 deletion app/views/events/guest_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
%td
- user = "#{ticket_request.user.name} <#{ticket_request.user.email}>"
- email = ticket_request.user.email
%span= user
= link_to event_ticket_request_path(@event, ticket_request) do
%span= user
%td
- if ticket_request.guests.empty?
%span= "as themselves"
Expand Down
22 changes: 21 additions & 1 deletion app/views/payment_mailer/payment_received.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@
Got ticket questions or think something is wrong with your order? We are still
here for you, drop us a line at
= succeed '.' do
= mail_to '[email protected]'
= mail_to '[email protected]'

%p

We care deeply about the health, safety, and comfort of attendees at our events and members
of our community. To help achieve this, we ask all of our members and guests to read,
understand, and share with each guest our
%b=link_to 'Code of Conduct', 'https://fnf.page.link/coc', target: '_blank', onclick: "popupWindow('https://fnf.page.link/coc', 'Code of Conduct', window, 800, 900); return false;"

%p
We are a community driven by volunteerism in the service of the community. As such, we depend upon the energy
and vision of members and guests to make our events happen!
%br
Please (re)acquaint yourself with
%b=link_to 'The FnF Way', 'https://fnf.events/the-fnf-way/', target: '_blank', onclick: "popupWindow('https://fnf.events/the-fnf-way/', 'The FnF Way', window, 700, 900); return false;"
and get involved with helping make the event happen!
%br
%b=link_to 'Volunteer Signups', 'https://signup.app.fnf.org/'
%p

%p
Friends and Family reminds you to
Expand Down Expand Up @@ -43,3 +61,5 @@
So soon!
%br
Your #{@event.name} Ticketing Team
= succeed '.' do
= mail_to '[email protected]'
2 changes: 1 addition & 1 deletion app/views/payments/other.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@

%p
When in doubt, contact us at
= mail_to 'tickets@fnf.org'
= mail_to 'ticket-support@fnf.org'
2 changes: 1 addition & 1 deletion app/views/payments/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

%p
If you have any other questions, don't hesitate to contact us at
= mail_to 'tickets@fnf.org'
= mail_to 'ticket-support@fnf.org'
6 changes: 4 additions & 2 deletions app/views/shared/_nav_event_tabs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
= event.name
.col-sm-12.col-md-12.col-lg-5.col-xl-3.text-end
%h5.d-inline.block.align-baseline.text-nowrap
= event.starting.to_date.strftime('%A, %B %d, %Y')
= event.starting.to_date.strftime('%A, %B %d, %Y')

.card-body.p-0.pt-3.pb-0.border-bottom-0.border-2
%ul.nav.nav-tabs.p-4.pb-0.mb-3.event-tabs
Expand Down Expand Up @@ -41,8 +41,10 @@
= link_to active_addons_camping_event_path(event), class: "nav-link #{active_tab[:camping_permits]}" do
Camping Permits


%li.nav-item
= link_to guest_list_event_path(event), class: "nav-link #{active_tab[:guest_list]}" do
Guest List

%li.nav-item
= link_to active_ticket_requests_event_path(event), class: "nav-link #{active_tab[:email_ticket_holders]}" do
Email Ticket Holders
27 changes: 27 additions & 0 deletions app/views/ticket_request_mailer/email_ticket_holder.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%p
Hi #{@ticket_request.user.first_name},

%p
- if @payment_url.present?
Your tickets still need to be purchased.
= link_to @payment_url do
Buy your tickets now!
%p
= @body

%p
With love ❤️,
%br
Your FnF Ticket Team

%p
- if @payment_url.present?
= link_to @payment_url do
Buy your tickets now!
%p
You can view the status of your request at any time by visiting
= link_to "#{@ticket_request_url}", @ticket_request_url

%p
%p
%i This email was generated by a very friendly #{Faker::Creature::Animal.name} at: #{Time.now}
7 changes: 4 additions & 3 deletions app/views/ticket_requests/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@
%br
- unless is_update
%p
Every year, every attendee, no matter how long they've been coming, must
acquaint themselves with our values and Code of Conduct. Please acknowledge
you've done so this year.
We care deeply about the health, safety, and comfort of attendees at our events and members
of our community. To help achieve this, we ask all everyone and their guests to read,
understand, and acknowledge that you have read both documents and
that you agree to follow and support these values.
= f.label :agrees_to_terms, class: 'checkbox' do
= f.check_box :agrees_to_terms
I’ve read
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ class Application < Rails::Application
idletime: 30.seconds

config.cache_store = :mem_cache_store, '127.0.0.1:11211', { pool: { size: 10 } }

config.action_mailer.preview_paths << Rails.root.join('lib/mailer_previews').to_s
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
post :add_admin
post :remove_admin
get :guest_list
get :active_ticket_requests
get :download_guest_list
get :active_addons_passes
get :active_addons_camping
Expand All @@ -35,6 +36,7 @@
collection do
get :download
get :payment_reminder
get :email_ticket_holders
end

member do
Expand Down
24 changes: 24 additions & 0 deletions lib/mailer_previews/ticket_request_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class TicketRequestMailerPreview < ActionMailer::Preview
def email_ticket_holder
ticket_request = TicketRequest.last
subject = 'Test Subject'
body = "This is my message test
<p>
We care deeply about the health, safety, and comfort of attendees at our events
and member of our community. <br>
To help achieve this, we ask all of our members and guests to read,
and abide by our <a href='https://fnf.page.link/coc'>Code Of Conduct</a>
<p>
We ask that you share this with each of your guests whom you may bring to the event.
<p>
We are a community driven by volunteerism in the service of the community.
<p>
As such, we depend upon the energy and vision of members and guests to make our events happen!<br>
Please (re)acquaint yourself with The FnF Way, https://cfaea.net/the-fnf-way/,<br>
and get involved with helping make the event happen!
"
TicketRequestMailer.with(ticket_request:).email_ticket_holder(ticket_request, subject, body)
end
end

0 comments on commit f1eba44

Please sign in to comment.