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_reciept!(member_id, amount)
30 member = NosOignons::Member.new(member_id)
31 member.create_reciept!(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 NosOignons::Reminder.all.sort_by(&:days).reverse.each do |reminder|
62 next if anniversary < today + reminder.days
64 member.remind(reminder)
70 def send_member_emails_to_advisors!
71 uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
72 subject = 'Adresses email des membres à jour de cotisation'
73 body = <<-END_OF_BODY.gsub(/^ /, '')
74 Cher comité de déontologie de Nos oignons,
76 Comme le prévoient les statuts l'article 12 des statuts de
77 l'association, vous devez être en mesure de pouvoir convoquer une
78 assemblée générale extraordinaire. Pour ce faire, voici donc la liste
79 des emails à jour de cotisation à la date d'aujourd'hui :
81 #{uptodate_emails.join("\n")}
83 Et merci encore de votre engagement auprès de Nos oignons !
86 Le robot du conseil d'administration
88 mail = Mail.new :charset => 'utf-8',
89 :from => NosOignons::BOARD_EMAIL,
90 :to => NosOignons::ADVISORS_EMAIL,
97 if system('git rev-parse --quiet --verify HEAD >/dev/null')
100 # Initial commit: diff against an empty tree object
101 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
104 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
105 NosOignons::Git.handle_modified_files(io) do |file|
106 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
108 # Use empty ref to get the index
109 NosOignons::Member.read_from_git('', file)
110 rescue ArgumentError, Psych::SyntaxError
111 $stderr.puts "Désolé : #{file} n'a pas le bon format !"
118 def pre_receive_hook!(stdin)
119 stdin.readlines.each do |ref_line|
120 old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
121 IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
122 NosOignons::Git.handle_modified_files(io) do |file|
123 next unless file.start_with?("#{NosOignons::MEMBERS_DB_DIR}/")
125 NosOignons::Member.read_from_git(new_value, file)
126 rescue ArgumentError, Psych::SyntaxError
127 $stderr.puts "Désolé : #{file} n'a pas le bon format !"