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

This commit is contained in:
Manuel Bustillo 2025-07-08 19:23:16 +02:00
parent 4496deeef5
commit 397a0f34ff
6 changed files with 59 additions and 9 deletions

View File

@ -26,6 +26,12 @@ class InvitationsController < ApplicationController
end
end
def email
AdminMailer.with(wedding_id: ActsAsTenant.current_tenant.id).invitations_pdf_email.deliver_later
head :ok
end
def sheet; end
def show

View File

@ -5,14 +5,41 @@
class AdminMailer < ApplicationMailer
def attendance_change_email
@guest = Guest.find(params[:guest_id])
mail(
to: @guest.wedding.users.pluck(:email),
subject: I18n.t(
'admin_mailer.attendance_change_email.subject',
name: @guest.name,
status: I18n.t("active_record.attributes.guest/status.#{@guest.status}")
ActsAsTenant.with_tenant(@guest.wedding) do
mail(
to: recipients,
subject: I18n.t(
'admin_mailer.attendance_change_email.subject',
name: @guest.name,
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

View 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>

View 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') %>

View File

@ -17,3 +17,6 @@ en:
subject: "%{name} has changed their attendance status: %{status}"
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."
invitations_pdf_email:
subject: "Your wedding invitations are ready"
paragraph_1: "Your wedding invitations are ready. Please, find them attached to this email."

View File

@ -42,7 +42,9 @@ Rails.application.routes.draw do
resources :tables_arrangements, only: %i[index show create]
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}")
end