3 # Système de gestion des adhésions de Nos oignons
4 # Copyright © 2013-2014 Nos oignons <contact@nos-oignons.net>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 require 'nos_oignons/git'
20 require 'nos_oignons/mailman'
21 require 'nos_oignons/member'
22 require 'nos_oignons/reminder'
23 require 'nos_oignons/reminder_db'
26 BOARD_EMAIL = 'ca@nos-oignons.net'
27 ADVISORS_EMAIL = 'deontologie@nos-oignons.net'
28 MEMBER_MAILING_LIST = 'ag@nos-oignons.net'
29 CONTACT_INFO = <<-EOT.gsub(/^ /, '')
30 Identifiant SIREN 842 479 313
31 https://nos-oignons.net/
32 contact@nos-oignons.net
33 Téléphone : +33 9 72 42 96 04
35 POSTAL_ADDRESS = <<-EOT.gsub(/^ /, '')
43 # The following class methods are all meant to be called as command-line scripts
45 def create_membership_fee_receipt!(member_id, amount)
46 member = NosOignons::Member.new(member_id)
47 member.create_receipt!(amount)
51 NosOignons::Member.all.each do |member|
58 def update_ag_subscribers!
59 list = NosOignons::MEMBER_MAILING_LIST
61 current_members = NosOignons::Mailman.list_members(list)
62 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
64 # Who is not subscribed yet?
65 emails_to_add = uptodate_emails - current_members.collect(&:email)
66 emails_to_add.each do |email|
67 NosOignons::Mailman.susbcribe_email(list, email)
70 # Who should not be subscribed anymore?
71 current_members.each do |list_member|
72 unless uptodate_emails.include?(list_member.email)
73 list_member.unsubscribe!
78 def send_membership_reminders!
79 today = Time.now.to_date
80 reminders = NosOignons::Reminder.all.sort_by(&:days)
81 NosOignons::Member.all.select(&:up_to_date?).each do |member|
82 next if member.membership_fee_paid_on.year == (today + reminders.last.days).year
83 anniversary = Time.new(today.next_month.year, member.joined_on.month,
84 member.joined_on.day).to_date
85 next if member.membership_fee_paid_on >= anniversary - reminders.last.days
86 reminders.each do |reminder|
87 next if (anniversary - today).to_i > reminder.days
88 next if member.reminded_on && (anniversary - member.reminded_on).to_i <= reminder.days
90 $stdout.puts "Envoi d'un rappel de cotisation a #{member.to_s}"
91 member.remind(reminder)
97 def send_member_emails_to_advisors!
98 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
99 subject = 'Adresses email des membres à jour de cotisation'
100 body = <<-END_OF_BODY.gsub(/^ /, '')
101 Cher comité de déontologie de Nos oignons,
103 Comme le prévoient les statuts l'article 12 des statuts de
104 l'association, vous devez être en mesure de pouvoir convoquer une
105 assemblée générale extraordinaire. Pour ce faire, voici donc la liste
106 des emails à jour de cotisation à la date d'aujourd'hui :
108 #{uptodate_emails.join("\n")}
110 Et merci encore de votre engagement auprès de Nos oignons !
113 Le robot du conseil d'administration
115 GNU AGPLv3 © Nos oignons <contact@nos-oignons.net>
116 git clone https://nos-oignons.net/gestion-adh.git
118 mail = Mail.new :charset => 'utf-8',
119 :from => NosOignons::BOARD_EMAIL,
120 :to => NosOignons::ADVISORS_EMAIL,
127 if system('git rev-parse --quiet --verify HEAD >/dev/null')
130 # Initial commit: diff against an empty tree object
131 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
134 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
135 NosOignons::Git.handle_modified_files(io) do |file|
136 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
138 # Use empty ref to get the index
139 NosOignons::Member.read_from_git('', file)
140 rescue ArgumentError, Psych::SyntaxError
141 $stderr.puts "Désolé : #{file} n'a pas le bon format !"
148 def pre_receive_hook!(stdin)
149 stdin.readlines.each do |ref_line|
150 old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
151 IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
152 NosOignons::Git.handle_modified_files(io) do |file|
153 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
155 NosOignons::Member.read_from_git(new_value, file)
156 rescue ArgumentError, Psych::SyntaxError
157 $stderr.puts "Désolé : #{file} n'a pas le bon format !"