Skip to content

Commit

Permalink
Send confirmation email when leaving zusatzsektion
Browse files Browse the repository at this point in the history
  • Loading branch information
rnestler committed Jul 16, 2024
1 parent c3e702b commit dd0d9b4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
22 changes: 22 additions & 0 deletions app/mailers/memberships/leave_zusatzsektion_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.

module Memberships
class LeaveZusatzsektionMailer < ApplicationMailer
CONFIRMATION = "memberships_leave_zusatzsektion_confirmation"

def confirmation(person, sektion_name, terminate_on)
values = [
%W[person-name #{person}],
%W[sektion-name #{sektion_name}],
%W[terminate-on #{terminate_on}]
].to_h
custom_headers = {cc: Group::Geschaeftsstelle.first.email}
custom_content_mail([person], CONFIRMATION, values, custom_headers)
end
end
end
10 changes: 9 additions & 1 deletion app/models/wizards/memberships/leave_zusatzsektion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def valid?

def save!
super
leave_operation.save!
leave_operation.save!.tap { send_confirmation_mail }
end

def leave_operation
Expand Down Expand Up @@ -67,6 +67,14 @@ def family_membership?

private

def send_confirmation_mail
Memberships::LeaveZusatzsektionMailer.confirmation(
person,
sektion_name,
I18n.l(terminate_on)
).deliver_later
end

def family_main_person?
person.sac_family_main_person
end
Expand Down
12 changes: 10 additions & 2 deletions db/seeds/custom_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
placeholders_optional: 'event-name, application-url, event-details' },
{ key: Qualifications::ExpirationMailer::REMINDER_TODAY },
{ key: Qualifications::ExpirationMailer::REMINDER_NEXT_YEAR },
{ key: Qualifications::ExpirationMailer::REMINDER_YEAR_AFTER_NEXT_YEAR }
{ key: Qualifications::ExpirationMailer::REMINDER_YEAR_AFTER_NEXT_YEAR },
{ key: Memberships::LeaveZusatzsektionMailer::CONFIRMATION, placeholders_required: 'person-name, sektion-name, terminate-on' }
)

participation_rejected_id =
Expand Down Expand Up @@ -54,5 +55,12 @@
label: 'Qualifikation: Erinnerungsmail in 2 Jahren',
subject: 'Erinnerung TL-Anerkennung',
body: 'Liebe(r) Tourenleiter(in), in 2 Jahren läuft deine TL-Anerkennung ab. ' \
'Plane rechtzeitig deine Fortbildungskurse in Absprache mit deinem(r) Tourenchef(in).' }
'Plane rechtzeitig deine Fortbildungskurse in Absprache mit deinem(r) Tourenchef(in).' } ,
{ custom_content_id: CustomContent.get(Memberships::LeaveZusatzsektionMailer::CONFIRMATION).id,
locale: 'de',
label: 'Mitgliedschaften: Bestätigung Austritt Zusatzsektion',
subject: 'Bestätigung Austritt Zusatzsektion',
body: 'Hallo {person-name},<br/><br/>' \
'Der Austritt aus {sektion-name} wurde per {terminate-on} vorgenommen.'
}
)
5 changes: 4 additions & 1 deletion spec/features/memberships/leave_zusatzsektion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

require "spec_helper"

describe "leave zusatzsektion", js: true do
describe "leave zusatzsektion", :tests_active_jobs, js: true do
let(:person) { people(:mitglied) }
let(:role) { person.roles.second }
let(:operator) { person }
Expand Down Expand Up @@ -38,6 +38,7 @@
.to change { person.roles.count }.by(-1)
.and change { role.deleted_at }.from(nil)
.and change { role.termination_reason }.from(nil).to(termination_reason)
.and have_enqueued_mail(Memberships::LeaveZusatzsektionMailer, :confirmation)
end
end

Expand All @@ -57,6 +58,7 @@
.to not_change { person.roles.count }
.and change { role.terminated }.to(true)
.and change { role.termination_reason }.from(nil).to(termination_reason)
.and have_enqueued_mail(Memberships::LeaveZusatzsektionMailer, :confirmation)
expect(role.delete_on).not_to be_nil
end

Expand Down Expand Up @@ -91,6 +93,7 @@
.to not_change { person.roles.count }
.and change { role.terminated }.to(true)
.and change { role.termination_reason }.from(nil).to(termination_reason)
.and have_enqueued_mail(Memberships::LeaveZusatzsektionMailer, :confirmation)
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/mailers/memberships/leave_zusatzsektion_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 Memberships::LeaveZusatzsektionMailer do
let(:person) { people(:mitglied) }
let(:group) { groups(:bluemlisalp) }
let(:switch_on) { "sofort" }
let(:mail) { described_class.confirmation(person, group, switch_on) }

subject { mail.parts.first.body }

it "sends confirmation email to person" do
expect(mail.to).to match_array(["e.hillary@hitobito.example.com"])
expect(mail.subject).to eq "Bestätigung Austritt Zusatzsektion"
expect(mail.body).to match("Hallo Edmund Hillary,")
expect(mail.body).to match("Der Austritt aus SAC Blüemlisalp wurde per sofort vorgenommen.")
end

it "sends confirmation email to geschaefsstelle if configured" do
groups(:geschaeftsstelle).update!(email: "geschaeftsstelle@example.com")
expect(mail.cc).to eq ["geschaeftsstelle@example.com"]
end
end

0 comments on commit dd0d9b4

Please sign in to comment.