Define a worker process and endpoint to send invitations PDF via email
All checks were successful
Run unit tests / copyright_notice (pull_request) Successful in 56s
Run unit tests / rubocop (pull_request) Successful in 1m10s
Run unit tests / check-licenses (pull_request) Successful in 1m20s
Run unit tests / unit_tests (pull_request) Successful in 2m3s
Run unit tests / build-static-assets (pull_request) Successful in 9m10s
All checks were successful
Run unit tests / copyright_notice (pull_request) Successful in 56s
Run unit tests / rubocop (pull_request) Successful in 1m10s
Run unit tests / check-licenses (pull_request) Successful in 1m20s
Run unit tests / unit_tests (pull_request) Successful in 2m3s
Run unit tests / build-static-assets (pull_request) Successful in 9m10s
This commit is contained in:
parent
4496deeef5
commit
397a0f34ff
@ -26,6 +26,12 @@ class InvitationsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email
|
||||||
|
AdminMailer.with(wedding_id: ActsAsTenant.current_tenant.id).invitations_pdf_email.deliver_later
|
||||||
|
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
|
|
||||||
def sheet; end
|
def sheet; end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -5,14 +5,41 @@
|
|||||||
class AdminMailer < ApplicationMailer
|
class AdminMailer < ApplicationMailer
|
||||||
def attendance_change_email
|
def attendance_change_email
|
||||||
@guest = Guest.find(params[:guest_id])
|
@guest = Guest.find(params[:guest_id])
|
||||||
|
ActsAsTenant.with_tenant(@guest.wedding) do
|
||||||
mail(
|
mail(
|
||||||
to: @guest.wedding.users.pluck(:email),
|
to: recipients,
|
||||||
subject: I18n.t(
|
subject: I18n.t(
|
||||||
'admin_mailer.attendance_change_email.subject',
|
'admin_mailer.attendance_change_email.subject',
|
||||||
name: @guest.name,
|
name: @guest.name,
|
||||||
status: I18n.t("active_record.attributes.guest/status.#{@guest.status}")
|
status: I18n.t("active_record.attributes.guest/status.#{@guest.status}")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def invitations_pdf_email
|
||||||
|
ActsAsTenant.with_tenant(Wedding.find(params[:wedding_id])) do
|
||||||
|
invitations = Invitation.includes(:guests).all
|
||||||
|
|
||||||
|
pdf_html = ActionController::Base.new.render_to_string(
|
||||||
|
template: 'invitations/sheet',
|
||||||
|
layout: 'pdf',
|
||||||
|
locals: { invitations: }
|
||||||
|
)
|
||||||
|
pdf = WickedPdf.new.pdf_from_string(pdf_html)
|
||||||
|
|
||||||
|
attachments["invitations_#{Time.current.strftime('%Y%m%d_%H%M%S')}.pdf"] = pdf
|
||||||
|
|
||||||
|
mail(
|
||||||
|
to: recipients,
|
||||||
|
subject: I18n.t('admin_mailer.invitations_pdf_email.subject')
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def recipients
|
||||||
|
ActsAsTenant.current_tenant.users.pluck(:email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
7
app/views/admin_mailer/invitations_pdf_email.html.erb
Normal file
7
app/views/admin_mailer/invitations_pdf_email.html.erb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
|
||||||
|
|
||||||
|
<p><%= I18n.t('admin_mailer.greeting') %>,</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= I18n.t('admin_mailer.invitations_pdf_email.paragraph_1') %>
|
||||||
|
</p>
|
5
app/views/admin_mailer/invitations_pdf_email.txt.erb
Normal file
5
app/views/admin_mailer/invitations_pdf_email.txt.erb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %>
|
||||||
|
|
||||||
|
<%= I18n.t('admin_mailer.greeting') %>,
|
||||||
|
|
||||||
|
<%= I18n.t('admin_mailer.invitations_pdf_email.paragraph_1') %>
|
@ -17,3 +17,6 @@ en:
|
|||||||
subject: "%{name} has changed their attendance status: %{status}"
|
subject: "%{name} has changed their attendance status: %{status}"
|
||||||
paragraph_1: "The guest %{name} has changed their attendance for the wedding."
|
paragraph_1: "The guest %{name} has changed their attendance for the wedding."
|
||||||
notify_on_updates: "You will be notified of any further changes to their attendance status."
|
notify_on_updates: "You will be notified of any further changes to their attendance status."
|
||||||
|
invitations_pdf_email:
|
||||||
|
subject: "Your wedding invitations are ready"
|
||||||
|
paragraph_1: "Your wedding invitations are ready. Please, find them attached to this email."
|
||||||
|
@ -42,7 +42,9 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
resources :tables_arrangements, only: %i[index show create]
|
resources :tables_arrangements, only: %i[index show create]
|
||||||
resources :summary, only: :index
|
resources :summary, only: :index
|
||||||
resources :invitations, only: %i[show index create update destroy]
|
resources :invitations, only: %i[show index create update destroy] do
|
||||||
|
post :email, on: :collection
|
||||||
|
end
|
||||||
|
|
||||||
root to: redirect("/%{slug}")
|
root to: redirect("/%{slug}")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user