3 require 'nos_oignons/git'
4 require 'nos_oignons/mailman'
5 require 'nos_oignons/member'
6 require 'nos_oignons/reminder'
7 require 'nos_oignons/reminder_db'
10 BOARD_EMAIL = 'ca@nos-oignons.net'
11 ADVISORS_EMAIL = 'deontologie@nos-oignons.net'
12 MEMBER_MAILING_LIST = 'ag'
13 CONTACT_INFO = <<-EOT.gsub(/^ /, '')
14 https://nos-oignons.net/
15 contact@nos-oignons.net
16 Téléphone : +33 9 72 42 96 04
17 Fax : +33 9 72 42 96 06
19 POSTAL_ADDRESS = <<-EOT.gsub(/^ /, '')
22 105 route des Pommiers
23 74370 Saint Martin Bellevue
27 # The following class methods are all meant to be called as command-line scripts
29 def create_membership_fee_receipt!(member_id, amount)
30 member = NosOignons::Member.new(member_id)
31 member.create_receipt!(amount)
35 NosOignons::Member.all.each do |member|
42 def update_ag_subscribers!
43 list = NosOignons::MEMBER_MAILING_LIST
45 current_emails = NosOignons::Mailman.list_members(list)
46 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
48 emails_to_add = uptodate_emails - current_emails
49 NosOignons::Mailman.add_members(list, emails_to_add) unless emails_to_add.empty?
50 emails_to_remove = current_emails - uptodate_emails
51 NosOignons::Mailman.remove_members(list, emails_to_remove) unless emails_to_remove.empty?
54 def send_membership_reminders!
55 today = Time.now.to_date
56 NosOignons::Member.all.select(&:up_to_date?).each do |member|
57 anniversary = Time.new(today.year, member.joined_on.month,
58 member.joined_on.day).to_date
59 next if member.membership_fee_paid_on >= anniversary
60 next if member.reminded_on && member.reminded_on >= today
61 reminders = NosOignons::Reminder.all.sort_by(&:days).reverse
62 next if anniversary > today + reminders.first.days
63 reminders.each do |reminder|
64 next if anniversary < today + reminder.days
66 member.remind(reminder)
72 def send_member_emails_to_advisors!
73 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
74 subject = 'Adresses email des membres à jour de cotisation'
75 body = <<-END_OF_BODY.gsub(/^ /, '')
76 Cher comité de déontologie de Nos oignons,
78 Comme le prévoient les statuts l'article 12 des statuts de
79 l'association, vous devez être en mesure de pouvoir convoquer une
80 assemblée générale extraordinaire. Pour ce faire, voici donc la liste
81 des emails à jour de cotisation à la date d'aujourd'hui :
83 #{uptodate_emails.join("\n")}
85 Et merci encore de votre engagement auprès de Nos oignons !
88 Le robot du conseil d'administration
90 mail = Mail.new :charset => 'utf-8',
91 :from => NosOignons::BOARD_EMAIL,
92 :to => NosOignons::ADVISORS_EMAIL,
99 if system('git rev-parse --quiet --verify HEAD >/dev/null')
102 # Initial commit: diff against an empty tree object
103 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
106 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
107 NosOignons::Git.handle_modified_files(io) do |file|
108 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
110 # Use empty ref to get the index
111 NosOignons::Member.read_from_git('', file)
112 rescue ArgumentError, Psych::SyntaxError
113 $stderr.puts "Désolé : #{file} n'a pas le bon format !"
120 def pre_receive_hook!(stdin)
121 stdin.readlines.each do |ref_line|
122 old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
123 IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
124 NosOignons::Git.handle_modified_files(io) do |file|
125 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
127 NosOignons::Member.read_from_git(new_value, file)
128 rescue ArgumentError, Psych::SyntaxError
129 $stderr.puts "Désolé : #{file} n'a pas le bon format !"