From ff8918a1d430864b98df152a7a0e3334fc4840bd Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 6 Jul 2025 18:11:08 +0200 Subject: [PATCH 1/3] Define a new email that will be sent to admins when a guest changes their attendance status --- app/mailers/admin_mailer.rb | 16 +++++++ app/models/wedding.rb | 1 + .../attendance_change_email.html.erb | 15 ++++++ .../attendance_change_email.text.erb | 7 +++ config/locales/en.yml | 46 +++++++------------ 5 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 app/mailers/admin_mailer.rb create mode 100644 app/views/admin_mailer/attendance_change_email.html.erb create mode 100644 app/views/admin_mailer/attendance_change_email.text.erb diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb new file mode 100644 index 0000000..302673a --- /dev/null +++ b/app/mailers/admin_mailer.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +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}") + ) + ) + end +end diff --git a/app/models/wedding.rb b/app/models/wedding.rb index 36e3ca8..f2b34f6 100644 --- a/app/models/wedding.rb +++ b/app/models/wedding.rb @@ -23,5 +23,6 @@ class Wedding < ApplicationRecord has_many :guests, dependent: :delete_all has_many :groups, dependent: :delete_all has_many :invitations, dependent: :delete_all + has_many :users, dependent: :delete_all has_one :website, dependent: :destroy end diff --git a/app/views/admin_mailer/attendance_change_email.html.erb b/app/views/admin_mailer/attendance_change_email.html.erb new file mode 100644 index 0000000..bac5c40 --- /dev/null +++ b/app/views/admin_mailer/attendance_change_email.html.erb @@ -0,0 +1,15 @@ +

<%= I18n.t('admin_mailer.greeting') %>,

+ +

+ <%= I18n.t('admin_mailer.attendance_change_email.paragraph_1', name: @guest.name) %> +

+ + + +

+ <%= I18n.t("admin_mailer.attendance_change_email.notify_on_updates") %> +

\ No newline at end of file diff --git a/app/views/admin_mailer/attendance_change_email.text.erb b/app/views/admin_mailer/attendance_change_email.text.erb new file mode 100644 index 0000000..120e824 --- /dev/null +++ b/app/views/admin_mailer/attendance_change_email.text.erb @@ -0,0 +1,7 @@ +<%= I18n.t('admin_mailer.greeting') %>, + +<%= I18n.t('admin_mailer.attendance_change_email.paragraph_1', name: @guest.name) %> + +- <%= I18n.t("active_record.attributes.guest.status") %>: <%= I18n.t("active_record.attributes.guest/status.#{@guest.status}") %> + +<%= I18n.t("admin_mailer.attendance_change_email.notify_on_updates") %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c349ae..b85268e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,31 +1,19 @@ -# Files in the config/locales directory are used for internationalization and -# are automatically loaded by Rails. If you want to use locales other than -# English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t "hello" -# -# In views, this is aliased to just `t`: -# -# <%= t("hello") %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# To learn more about the API, please read the Rails Internationalization guide -# at https://guides.rubyonrails.org/i18n.html. -# -# Be aware that YAML interprets the following case-insensitive strings as -# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings -# must be quoted to be interpreted as strings. For example: -# -# en: -# "yes": yup -# enabled: "ON" - en: hello: "Hello world" + active_record: + attributes: + guest: + status: Status + guest/status: + considered: Considered + invited: Invited + confirmed: Confirmed + declined: Declined + tentative: Tentative + + admin_mailer: + greeting: "Dear user" + attendance_change_email: + 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." -- 2.47.1 From d236e459cdc4d7736c9e6a4edf83fed7dcef9766 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 6 Jul 2025 18:30:35 +0200 Subject: [PATCH 2/3] Send an email whenever an anonymous session updates the attendance status of a guest --- app/controllers/guests_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 62530ce..0892c12 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -22,7 +22,13 @@ class GuestsController < ApplicationController end def update - guest = Guest.find(params[:id]).update!(guest_params) + guest = Guest.find(params[:id]) + guest.update!(guest_params) + + if !user_signed_in? && guest.saved_change_to_status? + AdminMailer.with(guest_id: guest.id).attendance_change_email.deliver_later + end + render json: guest.as_json(GUEST_PARAMS), status: :ok end -- 2.47.1 From 29b3fca80c9a9da82ab5961edfe38e5e559404e6 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 6 Jul 2025 16:32:02 +0000 Subject: [PATCH 3/3] Add copyright notice --- app/mailers/admin_mailer.rb | 2 ++ app/views/admin_mailer/attendance_change_email.html.erb | 2 ++ app/views/admin_mailer/attendance_change_email.text.erb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb index 302673a..af77c4f 100644 --- a/app/mailers/admin_mailer.rb +++ b/app/mailers/admin_mailer.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2024-2025 LibreWeddingPlanner contributors + # frozen_string_literal: true class AdminMailer < ApplicationMailer diff --git a/app/views/admin_mailer/attendance_change_email.html.erb b/app/views/admin_mailer/attendance_change_email.html.erb index bac5c40..19e742c 100644 --- a/app/views/admin_mailer/attendance_change_email.html.erb +++ b/app/views/admin_mailer/attendance_change_email.html.erb @@ -1,3 +1,5 @@ +<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %> +

<%= I18n.t('admin_mailer.greeting') %>,

diff --git a/app/views/admin_mailer/attendance_change_email.text.erb b/app/views/admin_mailer/attendance_change_email.text.erb index 120e824..faf1af0 100644 --- a/app/views/admin_mailer/attendance_change_email.text.erb +++ b/app/views/admin_mailer/attendance_change_email.text.erb @@ -1,3 +1,5 @@ +<%# Copyright (C) 2024-2025 LibreWeddingPlanner contributors %> + <%= I18n.t('admin_mailer.greeting') %>, <%= I18n.t('admin_mailer.attendance_change_email.paragraph_1', name: @guest.name) %> -- 2.47.1