Commit 5cced1f6 authored by Alexandre Friquet's avatar Alexandre Friquet
Browse files

Send email to other collaborating clubs when subscription created: refs #45.

parent f1f74be9
......@@ -38,6 +38,17 @@ class SubscriptionsController < ApplicationController
end
if @subscription.save
@subscription.external_clubs.each do |external_club|
failed_recipients = []
begin
Mailer.notify_collaborating_club(@subscription, external_club).deliver_now
rescue Exception => e
failed_recipients << external_club.name
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
redirect_to @member, notice: "L'adhésion de #{@subscription.adherent.name} a bien été créée. Pour modifier cette adhésion merci de vous mettre en relation avec un administrateur du site afin que ce dernier procède aux changements."
else
flash.now[:error] = t('flash.error')
......
......@@ -51,4 +51,13 @@ class Mailer < ActionMailer::Base
:subject => "#{ENV['APP_NAME']} - réinitialisation du mot de passe"
end
end
\ No newline at end of file
def notify_collaborating_club(subscription, member)
@subscription = subscription
@performances = subscription.performances.for_member(member)
mail from: Settings.instance.contact_email,
to: member.contacts.map(&:email),
subject: "Nouveau participant à une de vos séances"
end
end
......@@ -10,4 +10,10 @@ class Subscription < ApplicationRecord
def performances_list
"#{performances.to_a.map(&:title_for_subscriptions_list).join(', ')}"
end
def external_clubs
members = self.performances.to_a.map(&:member).uniq
members.delete(self.member)
members
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-2016 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 <%= @subscription.adherent.name %> (<%= @subscription.member.name %>) viendra pratiquer certaines de vos activités lors des séances suivantes :
<% @performances.each do |performance| %>
- <%= performance.full_title %>
<% end %>
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.
......@@ -58,7 +58,7 @@ feature "Manage subscriptions" do
msi = create :member, member_groups: [medico_social_orgs_group]
@settings.platform_medicosocial_orgs << medico_social_orgs_group
collaborating_club = create :member, name: "Mon asso", member_groups: @member.member_groups
perf = create :performance, member: collaborating_club, activity: athle, day: :monday, start_at: "10:00", end_at: "15:00"
perf = create :performance, member: collaborating_club, activity: athle
visit member_path(@member)
within "aside#subscriptions" do
......@@ -112,6 +112,34 @@ feature "Manage subscriptions" do
expect(page).to have_selector("li", text: "Jean-Charles Dupont : Mon asso (Athlétisme)")
end
end
scenario "regarding mail notifications", type: :mailer do
main_club = @member
other_club1 = create :member, name: "Autre asso 1", member_groups: @member.member_groups
other_club2 = create :member, name: "Autre asso 2", member_groups: @member.member_groups
perf1 = create :performance, member: main_club, activity: athle
perf2 = create :performance, member: other_club1, activity: athle
perf3 = create :performance, member: other_club2, activity: athle
visit new_member_subscription_path(@member)
within "form" do
fill_in "Nom", with: "Dupont"
fill_in "Prénom", with: "Jean-Charles"
fill_in "Date de naissance", with: "14/07/1989"
fill_in "N° licence", with: "123456"
select "Autre", from: "Structure médico-sociale"
fill_in "Autre structure médico-sociale", with: "Une structure quelconque"
check "Collaborating club - [Athlétisme] Lundi"
check "Autre asso 1 - [Athlétisme] Lundi"
check "Autre asso 2 - [Athlétisme] Lundi"
expect(page).to have_selector("div#subscription-option", text: "Formule retenue")
click_create_button
end
expect(current_path).to eq member_path(@member)
expect(page).to have_content "L'adhésion de Jean-Charles Dupont a bien été créée."
expect(ActionMailer::Base.deliveries.count).to eq 2
end
end
scenario "I can see internal and external subscriptions" do
......
......@@ -45,4 +45,38 @@ describe Mailer do
expect(@mail.body.encoded).to match("Voici les...")
end
end
end
\ No newline at end of file
describe "notify_collaborating_club" 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"
subscription = create :subscription, adherent: adherent, performances: [perf1, perf2], member_id: member.id
@mail = Mailer.notify_collaborating_club(subscription, member)
end
it "renders the headers" do
expect(@mail.subject).to eq("Nouveau participant à 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 Jean Dupont (Mon asso) viendra pratiquer certaines de vos activités lors des séances suivantes :
- [Athlétisme] Lundi de 18h00 à 20h00
- [Athlétisme] Mercredi de 14h00 à 16h00
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
end
......@@ -27,4 +27,19 @@ RSpec.describe Subscription, type: :model do
expect(Subscription.for_performances([perf1,perf3].map(&:id))).to eq [subscription1]
end
end
describe "behaviors" do
it "#external_clubs returns other members where adherent practices" do
main_club = create :member
other_club1 = create :member
other_club2 = create :member
activity = create :activity
perf1 = create :performance, member: main_club, activity: activity
perf2 = create :performance, member: other_club1, activity: activity
perf3 = create :performance, member: other_club2, activity: activity
adherent = build :adherent
subscription = create :subscription, adherent: adherent, performances: [perf1, perf2, perf3], member_id: main_club.id
expect(subscription.external_clubs).to eq [other_club1, other_club2]
end
end
end
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