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