Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email when course application is canceled #1039

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions app/mailers/event/participation_canceled_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas.

class Event::ParticipationCanceledMailer < ApplicationMailer
include EventMailer
include MultilingualMailer

CONFIRMATION = "event_participation_canceled"

def confirmation(participation)
@participation = participation
@course = participation.event
@person = participation.person
headers[:bcc] = @course.groups.first.course_admin_email
locales = @course.language.split("_")

compose_multilingual(@person, CONFIRMATION, locales)
end
end
12 changes: 10 additions & 2 deletions app/models/sac_cas/event/participation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ module SacCas::Event::Participation
attr_accessor :adult_consent, :terms_and_conditions, :newsletter, :check_root_conditions

validates :adult_consent, :terms_and_conditions, acceptance: {if: :check_root_conditions}

validates :actual_days, numericality: {greater_than_or_equal_to: 0, allow_blank: true}

validate :assert_actual_days_size

after_update :send_application_canceled_email, if: :state_changed_to_canceled?
end

def subsidy_amount
Expand Down Expand Up @@ -59,4 +59,12 @@ def update_previous_state
self.previous_state = state_was
end
end

def state_changed_to_canceled?
saved_change_to_attribute(:state)&.second == "canceled"
end

def send_application_canceled_email
Event::ParticipationCanceledMailer.confirmation(self).deliver_later
end
end
13 changes: 13 additions & 0 deletions db/seeds/custom_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
{key: Event::ApplicationConfirmationMailer::ASSIGNED,
placeholders_required: "event-name",
placeholders_optional: "recipient-name, event-details, event-number, event-link, application-url, application-closing-at, person-url, missing-information"},
{key: Event::ParticipationCanceledMailer::CONFIRMATION,
placeholders_required: "event-name",
placeholders_optional: "recipient-name, event-details, event-number, event-link, application-url, person-url"},
{key: Event::LeaderReminderMailer::REMINDER_NEXT_WEEK,
placeholders_required: "event-name",
placeholders_optional: "recipient-name, event-details, event-number, event-link"},
Expand Down Expand Up @@ -136,6 +139,16 @@
"Person: {person-url}<br>" \
"Event-Link: {event-link}<br>" \
"Kursdetails:<br><br>{event-details}<br><br>{missing-information}"},
{custom_content_id: CustomContent.get(Event::ParticipationCanceledMailer::CONFIRMATION).id,
locale: "de",
label: "Kurs: E-Mail Abmeldung",
subject: "Kursabmeldung bestätigt",
body: "Hallo {recipient-name},<br><br>" \
"Deine Abmeldung für den Kurs {event-name} (Nummer: {event-number}) wurde bestätigt. " \
"Anmeldung: {application-url}<br>" \
"Person: {person-url}<br>" \
"Event-Link: {event-link}<br>" \
"Kursdetails:<br><br>{event-details}<br><br>{missing-information}"},
{custom_content_id: leader_reminder_next_week_id,
locale: "de",
label: "Kurs: E-Mail Kursvorbereitungen abschliessen",
Expand Down
25 changes: 25 additions & 0 deletions spec/mailers/event/participation_canceled_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas.

require "spec_helper"

describe Event::ParticipationCanceledMailer do
let(:event) { Fabricate(:sac_open_course) }
let(:participation) { event.participations.create!(person: people(:mitglied)) }
let(:mail) { described_class.confirmation(participation) }

before { event.groups.first.update!(course_admin_email: "admin@example.com") }

it "sends to email addresses of participant" do
expect(mail.to).to match_array(["e.hillary@hitobito.example.com"])
expect(mail.bcc).to match_array(["admin@example.com"])
expect(mail.body.to_s).to include(
"Hallo Edmund,",
"Deine Abmeldung für den Kurs Eventus (Nummer: #{event.number}) wurde bestätigt."
)
end
end
Loading