Separate the add and remove operations on lists

This commit is contained in:
Timothée Floure 2018-10-07 22:15:19 +02:00
parent 165e01269d
commit 1c8eb14154
2 changed files with 24 additions and 18 deletions

View file

@ -1,5 +1,6 @@
domain = "unipoly.ch" domain = "unipoly.ch"
lists = [ "membres"] lists_add = ["membres"]
lists_remove = ["membres"]
[ldap] [ldap]
host = "ldap.gnugen.ch" host = "ldap.gnugen.ch"

View file

@ -40,7 +40,8 @@ def main
domain = conf["domain"] domain = conf["domain"]
basetree = conf["ldap"]["lists"]["basetree"] basetree = conf["ldap"]["lists"]["basetree"]
conf["lists"].each do |cn| lists = (conf["lists_add"] + conf["lists_remove"]).uniq
lists.each do |cn|
puts ">> Processing list #{cn}@#{domain}" puts ">> Processing list #{cn}@#{domain}"
filter = Net::LDAP::Filter.eq("cn", cn) filter = Net::LDAP::Filter.eq("cn", cn)
@ -75,6 +76,7 @@ def main
if (subscribers.include?(m)) if (subscribers.include?(m))
subscribers.delete(m) subscribers.delete(m)
else else
if (conf["lists_add"].include?(cn))
print "Adding #{m}... " print "Adding #{m}... "
mlmmj_sub_binary = conf["mlmmj"]["sub_binary"] mlmmj_sub_binary = conf["mlmmj"]["sub_binary"]
%x(#{mlmmj_sub_binary} -L #{list} -a #{m} -q -f -s) %x(#{mlmmj_sub_binary} -L #{list} -a #{m} -q -f -s)
@ -85,8 +87,10 @@ def main
end end
end end
end end
end
# Remove remaining "subcribers" (= they did not match with members) # Remove remaining "subcribers" (= they did not match with members)
if (conf["lists_remove"].include?(cn))
subscribers.each do |s| subscribers.each do |s|
print "Removing #{s}... " print "Removing #{s}... "
mlmmj_unsub_binary = conf["mlmmj"]["unsub_binary"] mlmmj_unsub_binary = conf["mlmmj"]["unsub_binary"]
@ -97,6 +101,7 @@ def main
puts "Failed" puts "Failed"
end end
end end
end
print "\n" print "\n"
else else
puts "FAIL" puts "FAIL"