Commit a9690fdc authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Email sent when performance removed from subscription: refs #57.

parent 565a303a
......@@ -61,7 +61,13 @@ class SubscriptionsController < ApplicationController
end
def update
old_performance_ids = @subscription.performance_ids
new_performance_ids = global_params[:performance_ids].reject { |id| id == "" }.map(&:to_i)
intersection = old_performance_ids & new_performance_ids
removed_performance_ids = old_performance_ids - intersection
members_concerned_for_removal = Member.joins(:performances).where(performances: { id: removed_performance_ids }).uniq
if @subscription.update_attributes(global_params)
notify_clubs_concerned_by_removal(members_concerned_for_removal, removed_performance_ids)
redirect_to @member, notice: "L'adhésion a bien été mise à jour."
else
flash[:error] = t('flash.error')
......@@ -122,4 +128,19 @@ class SubscriptionsController < ApplicationController
collaborating_clubs = Member.of_member_groups(settings.platform_collaborating_clubs)
@available_performances = Performance.where(member_id: collaborating_clubs.ids)
end
def notify_clubs_concerned_by_removal(members, removed_performance_ids)
failed_recipients = []
members.each do |member|
performances = member.performances.where(id: removed_performance_ids)
begin
Mailer.removed_performances(@subscription, performances).deliver_now
rescue Exception => e
failed_recipients << member.name
end
end
unless failed_recipients.empty?
flash[:warning] = "Une erreur a été rencontrée lors de l'envoi du courriel aux clubs suivants : #{failed_recipients.join(', ')}."
end
end
end
......@@ -60,4 +60,15 @@ class Mailer < ActionMailer::Base
subject: "Nouveau participant à une de vos séances"
end
def removed_performances(subscription, performances)
@subscription = subscription
@performances = performances
member = performances.first.member
mail from: Settings.instance.contact_email,
to: member.contacts.map(&:email),
subject: "Un participant quitte une de vos séances"
end
end
<%
# OLIGAA - Stands for "Outil en Ligne d'Information et de Gestion des Activités
# des Associations" which is an online tool for associations to manage news,
# actors and activities.
# Copyright (C) 2010-2017 Comité Départemental du Sport Adapté de la Gironde (CDSA
# 33) <contact@cdsa33.org>
#
# This file is part of OLIGAA.
#
# OLIGAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# OLIGAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
%>
Bonjour,
Par ce mail, nous vous informons que le sportif suivant :
- Prénom Nom : <%= @subscription.adherent.name %>
- Club d'origine : <%= @subscription.member.name %>
- Date de naissance : <%= l @subscription.adherent.born_on %>
- N° licence FFSA : <%= @subscription.adherent.permit_number %>
ne participera plus à votre (vos) séance(s) suivante(s) :
<% @performances.each do |performance| %>
- <%= performance.full_title %>
<% end %>
Nous vous remercions de ne plus noter sa présence à cette (ces) séance(s) sportive(s).
......@@ -45,30 +45,54 @@ feature "Manage subscriptions" do
end
end
scenario "I can edit one" do
asso = create :member, name: "Mon asso"
athle = create :activity, title: "Athlétisme"
adherent = build :adherent, last_name: "Dupont", first_name: "Jean",medico_social_org: nil, other_medicosocial_org: "Une structure"
perf = create :performance, member: asso, activity: athle
subscription = create :subscription, adherent: adherent, performances: [perf], member_id: asso.id
context "regarding edition" do
scenario "I can edit one" do
asso = create :member, name: "Mon asso"
athle = create :activity, title: "Athlétisme"
adherent = build :adherent, last_name: "Dupont", first_name: "Jean",medico_social_org: nil, other_medicosocial_org: "Une structure"
perf = create :performance, member: asso, activity: athle
subscription = create :subscription, adherent: adherent, performances: [perf], member_id: asso.id
visit member_path(asso)
within "aside#subscriptions li", text: "Jean Dupont : Mon asso (Athlétisme)" do
click_edit_link
end
visit member_path(asso)
within "aside#subscriptions li", text: "Jean Dupont : Mon asso (Athlétisme)" do
click_edit_link
end
expect(current_path).to eq edit_member_subscription_path(asso, subscription)
within "form" do
fill_in "Nom", with: "Dupond"
click_update_button
end
expect(current_path).to eq edit_member_subscription_path(asso, subscription)
within "form" do
fill_in "Nom", with: "Dupond"
click_update_button
expect(current_path).to eq member_path(asso)
expect(page).to have_content "L'adhésion a bien été mise à jour."
within "aside#subscriptions ul#internal" do
expect(page).not_to have_content "Jean Dupont"
expect(page).to have_content "Jean Dupond"
end
end
expect(current_path).to eq member_path(asso)
expect(page).to have_content "L'adhésion a bien été mise à jour."
within "aside#subscriptions ul#internal" do
expect(page).not_to have_content "Jean Dupont"
expect(page).to have_content "Jean Dupond"
scenario "email sent when activity removed", type: :mailer do
collaborating_clubs_mg = create :member_group
@settings.platform_collaborating_clubs << collaborating_clubs_mg
usg = create :member, name: "USG", member_groups: [collaborating_clubs_mg]
mouettes = create :member, name: "Les Mouettes", member_groups: [collaborating_clubs_mg]
athle = create :activity, title: "Athlétisme"
adherent = build :adherent, last_name: "Dupont", first_name: "Jean", medico_social_org: nil, other_medicosocial_org: "Une structure"
usg_perf = create :performance, member: usg, activity: athle
mouettes_perf = create :performance, member: mouettes, activity: athle
subscription = create :subscription, adherent: adherent, performances: [usg_perf, mouettes_perf], member_id: usg.id
visit edit_member_subscription_path(usg, subscription)
within "form" do
expect(all("input[type=checkbox]")[1]).to be_checked
uncheck "Les Mouettes - [Athlétisme] Lundi"
click_update_button
end
expect(ActionMailer::Base.deliveries.count).to eq 1
end
scenario "email sent when activity added"
end
scenario "I can list all susbscriptions" do
......
......@@ -83,6 +83,46 @@ viendra pratiquer certaines de vos activités lors des séances suivantes :
Vous devez maintenant lui prendre une licence Multiclub, via l'espace licence de la FFSA (http://espacelicenceffsa.fr/user/login) afin qu'il soit couvert sur les activités sportives de votre club.
Nous vous remercions de bien vouloir vérifier sa présence et qu'il est en possession de son Pass'Multiactivités lors de chaque séance.
EOS
expect(@mail.body.encoded.gsub(/\r/,'')).to match(expected_body)
end
end
describe "removed_performances" do
before(:each) do
c1 = create :contact, email: "c1@ip.fr"
c2 = create :contact, email: "c2@ip.fr"
member = create :member, name: "Mon asso"
member.update_attribute(:contacts, [c1,c2])
athle = create :activity, title: "Athlétisme"
perf1 = create :performance, member: member, activity: athle, day: :monday, start_at: "18:00", end_at: "20:00"
perf2 = create :performance, member: member, activity: athle, day: :wednesday, start_at: "14:00", end_at: "16:00"
adherent = build :adherent, last_name: "Dupont", first_name: "Jean", born_on: "25/08/1986", permit_number: "123456"
subscription = create :subscription, adherent: adherent, performances: [perf1, perf2], member_id: member.id
@mail = Mailer.removed_performances(subscription, [perf2])
end
it "renders the headers" do
expect(@mail.subject).to eq("Un participant quitte une de vos séances")
expect(@mail.from).to eq(["contact@example.com"])
expect(@mail.to).to eq(["c1@ip.fr", "c2@ip.fr"])
end
it "renders the body" do
expected_body = <<EOS
Bonjour,
Par ce mail, nous vous informons que le sportif suivant :
- Prénom Nom : Jean Dupont
- Club d'origine : Mon asso
- Date de naissance : 25/08/1986
- N° licence FFSA : 123456
ne participera plus à votre (vos) séance(s) suivante(s) :
- [Athlétisme] Mercredi de 14h00 à 16h00
Nous vous remercions de ne plus noter sa présence à cette (ces) séance(s) sportive(s).
EOS
expect(@mail.body.encoded.gsub(/\r/,'')).to match(expected_body)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment