Skip to content

Commit

Permalink
EVENTS: E-Mail bei Ablehnung (#558)
Browse files Browse the repository at this point in the history
prototype (#558)

attempt to seed the specs (#558)

remove fixtures for customcontent (#558)

send email and fix specs (#558)

new spec for participation rejection job (#558)

fix specs, rollback state (#558)

move job test spec to course_spec (#558)
  • Loading branch information
Largo committed Jun 18, 2024
1 parent f60bdf8 commit b5516a9
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 237 deletions.
31 changes: 31 additions & 0 deletions app/jobs/event/participation_rejection_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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::ParticipationRejectionJob < BaseJob
self.parameters = [:participation_id]

def initialize(participation)
super()
@participation_id = participation.id
end

def perform
return unless participation # may have been deleted again

set_locale
send_rejection
end

private

def send_rejection
Event::ParticipationMailer.reject(participation).deliver_now
end

def participation
@participation ||= Event::Participation.find_by(id: @participation_id)
end
end
29 changes: 29 additions & 0 deletions app/mailers/sac_cas/event/participation_mailer.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.

module SacCas::Event::ParticipationMailer
extend ActiveSupport::Concern

CONTENT_REJECTED_PARTICIPATION = 'event_participation_rejected'

def reject(participation)
@participation = participation
person = @participation.person

compose(person, CONTENT_REJECTED_PARTICIPATION)
end

private

def placeholder_event_name
@participation.event.to_s
end

def placeholder_recipient_name_with_salutation
@participation.person.salutation_value
end
end
30 changes: 22 additions & 8 deletions app/models/concerns/events/courses/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@ module Events::Courses::State
assignment_closed: [:ready, :canceled],
ready: [:closed, :canceled],
canceled: [:application_open],
closed: [:ready]
}.freeze
closed: [:ready] }.freeze

self.possible_states = SAC_COURSE_STATES.keys.collect(&:to_s)

validate :assert_valid_state_change, if: :state_changed?
before_create :set_default_state
end
after_commit :notify_rejected_participants, if: :assignment_closed?

def available_states(state = self.state)
SAC_COURSE_STATES[state.to_sym]
end
def available_states(state = self.state)
SAC_COURSE_STATES[state.to_sym]
end

def assignment_closed?
state.to_sym == :assignment_closed
end

def state_possible?(new_state)
available_states.any?(new_state.to_sym)
def state_possible?(new_state)
available_states.any?(new_state.to_sym)
end

def notify_rejected_participants
rejected_participants.each do |participation|
Event::ParticipationRejectionJob.new(participation).enqueue!
end
end

def rejected_participants
participations.where(state: 'rejected')
end
end

private
Expand Down
37 changes: 37 additions & 0 deletions db/seeds/custom_contents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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.

CustomContent.seed_once(:key,
{ key: Event::ParticipationMailer::CONTENT_REJECTED_PARTICIPATION, # 'event_participation_rejected`
placeholders_required: 'participant-name',
placeholders_optional: 'event-name, application-url, event-details' })

participation_rejected_id =
CustomContent.get(Event::ParticipationMailer::CONTENT_REJECTED_PARTICIPATION).id

CustomContent::Translation.seed_once(:custom_content_id, :locale,
{ custom_content_id: participation_rejected_id,
locale: 'de',
label: 'Anlass: E-Mail Ablehnung',
subject: 'Kursablehnung',
body: "Hallo {participant-name}<br/><br/>" \
"Sie wurden leider für den Kurs {event-name} abgelehnt.<br/><br/>" \
"Siehe {application-url}<br/><br/>" \
"Kursdetails:<br/>{event-details}<br/>" },

{ custom_content_id: participation_rejected_id,
locale: 'fr',
label: "Événement: E-Mail de refus" },

{ custom_content_id: participation_rejected_id,
locale: 'en',
label: 'Event: Rejection email' },

{ custom_content_id: participation_rejected_id,
locale: 'it',
label: "Evento: E-mail della notifica della rifiuto" }
)
1 change: 1 addition & 0 deletions lib/hitobito_sac_cas/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Wagon < Rails::Engine
Event::ParticipationBanner.prepend SacCas::Event::ParticipationBanner
Event::ParticipationContactData.prepend SacCas::Event::ParticipationContactData
Event::Participatable.prepend SacCas::Event::Participatable
Event::ParticipationMailer.prepend SacCas::Event::ParticipationMailer
FutureRole.prepend SacCas::FutureRole
Group.include SacCas::Group
Household.prepend SacCas::Household
Expand Down
4 changes: 2 additions & 2 deletions spec/features/event_participation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def complete_contact_data
visit group_event_path(group_id: group, id: event)
click_button 'Abmelden'
within('.popover-body') { click_on 'Abmelden' }
expect( find_field('Begründung').native.attribute('validationMessage')).to eq 'Please fill out this field.'
expect( find_field('Begründung').native.attribute('validationMessage')).to match(/Please fill (out|in) this field./)
end

it 'can cancel with reason' do
Expand All @@ -94,7 +94,7 @@ def complete_contact_data
visit group_event_participation_path(group_id: group, event_id: event, id: participation.id)
click_button 'Abmelden'
within('.popover-body') { click_on 'Abmelden' }
expect( find_field('Begründung').native.attribute('validationMessage')).to eq 'Please fill out this field.'
expect( find_field('Begründung').native.attribute('validationMessage')).to match(/Please fill (out|in) this field./)
end

it 'can cancel with reason' do
Expand Down
8 changes: 4 additions & 4 deletions spec/features/self_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def complete_main_person_form
expect(page).to have_field 'Mail'
fill_in 'Mail', with: person.email
click_on 'Registrieren'
expect(page).to have_css '.alert-success',
expect(page).to have_css '.alert-success',
text: 'Es existiert bereits ein Login für diese E-Mail.'
expect(page).to have_css 'h1', text: 'Anmelden'
expect(page).to have_field 'Haupt‑E‑Mail / Mitglied‑Nr', with: person.email
Expand Down Expand Up @@ -97,7 +97,7 @@ def complete_main_person_form
click_button 'Anmelden'

expect(person.roles.map(&:type)).to eq([self_registration_role.to_s])
expect(current_path).to eq("#{group_person_path(group_id: group, id: person,
expect(current_path).to eq("#{group_person_path(group_id: group, id: person,
locale: :de)}.html")
end

Expand All @@ -115,7 +115,7 @@ def complete_main_person_form
it 'cannot complete without accepting adult consent' do
complete_main_person_form
expect { click_on 'Registrieren' }.not_to(change { Person.count })
expect(adult_consent_field.native.attribute('validationMessage')).to eq 'Please check this box if you want to proceed.'
expect(adult_consent_field.native.attribute('validationMessage')).to match(/Please (check|tick) this box if you want to proceed./)
end

it 'can complete when accepting adult consent' do
Expand Down Expand Up @@ -153,7 +153,7 @@ def complete_main_person_form
end.not_to(change { Person.count })

field = page.find_field('Ich erkläre mich mit den folgenden Bestimmungen einverstanden:')
expect(field.native.attribute('validationMessage')).to eq 'Please check this box if you want to proceed.'
expect(field.native.attribute('validationMessage')).to match(/Please (check|tick) this box if you want to proceed./)

# flash not rendered because of native html require
expect(page).not_to have_text('Um die Registrierung abzuschliessen, muss der Datenschutzerklärung zugestimmt werden.')
Expand Down
116 changes: 0 additions & 116 deletions spec/fixtures/custom_content/translations.yml

This file was deleted.

Loading

0 comments on commit b5516a9

Please sign in to comment.