From 872dbc62a015c1941341e98a30bedafb6ba3bec6 Mon Sep 17 00:00:00 2001 From: Yohan Bataille Date: Mon, 3 Mar 2014 19:49:43 +0100 Subject: [PATCH] =?UTF-8?q?Suppression=20des=20machines=20si=20pas=20de=20?= =?UTF-8?q?cotisations=20depuis=20plus=20de=202=20ans.=20Il=20est=20pr?= =?UTF-8?q?=C3=A9vu=20de=20remplacer=20par=20une=20IP=20d'isolement=20au?= =?UTF-8?q?=20bout=20d'un=20mois=20mais=20il=20y=20a=20un=20bug=20avec=20l?= =?UTF-8?q?e=20calcul=20de=20fin=20de=20connexion=20donc=20c'est=20trop=20?= =?UTF-8?q?risqu=C3=A9=20pour=20le=20moment.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Brie/brie/controllers/scheduler.py | 24 +++++++++++++++++++++++- Brie/brie/lib/aurore_helper.py | 12 +++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Brie/brie/controllers/scheduler.py b/Brie/brie/controllers/scheduler.py index 10c1476..1ebb3ea 100644 --- a/Brie/brie/controllers/scheduler.py +++ b/Brie/brie/controllers/scheduler.py @@ -4,7 +4,7 @@ from brie.config import ldap_config from brie.lib.ldap_helper import * from brie.lib.aurore_helper import * from brie.model.ldap import * - +import sys import datetime import brie.config.credentials as credentials @@ -24,6 +24,7 @@ sched = Scheduler() def disconnect_members_from_residence(admin_user, residence_dn): members = Member.get_all(admin_user, residence_dn) + print (CotisationComputes.current_year()) for member in members: @@ -44,12 +45,33 @@ def disconnect_members_from_residence(admin_user, residence_dn): #end if #end if + if CotisationComputes.is_member_to_delete(member, admin_user, residence_dn): + # supprime les machines mais pas le membre (il pourrait avoir besoin du compte ex : Yohan, le LDAP d'Aurores, etc) + # alors test a ajouter pour ne supprimer que si membre d'aucun groupe + # duplication de code avec class MachineDeleteController + machine_dn = ldap_config.machine_base_dn + member.dn + machines = admin_user.ldap_bind.search(machine_dn, "(objectClass=organizationalRole)", scope = ldap.SCOPE_ONELEVEL) + for machine in machines: + dns = Machine.get_dns_by_id(admin_user, machine.dn) + ip = IpReservation.get_ip(admin_user, residence_dn, dns.dlzData.first()) + print("[LOG] suppression machine " + Machine.get_dhcps(admin_user, machine.dn)[0].get("dhcpHWAddress").values[0] + " pour l'utilisateur "+ member.dn + " par le scheduler") + #sys.stdout.flush() + admin_user.ldap_bind.delete_entry_subtree(machine.dn) + if ip is not None: + taken_attribute = ip.get("x-taken").first() + if taken_attribute is not None: + admin_user.ldap_bind.delete_attr(ip.dn, IpReservation.taken_attr(taken_attribute)) + #end if + #end if + #end for + #end if #end for #end def @sched.interval_schedule(days=1, start_date="2013-09-30 22:14:37") +#@sched.interval_schedule(minutes=1, start_date="2013-09-30 22:14:37") def disconnect_members_job(): user = admin_user() diff --git a/Brie/brie/lib/aurore_helper.py b/Brie/brie/lib/aurore_helper.py index 8c23c7a..8319b81 100644 --- a/Brie/brie/lib/aurore_helper.py +++ b/Brie/brie/lib/aurore_helper.py @@ -113,7 +113,6 @@ class CotisationComputes: anniversary = 0 # tri par ordre d'inscription result = sorted(result) - if result != []: anniversary_day = result[0][0].day SORT_ORDER = {9: 0, 10: 1, 11: 2, 12: 3, 1: 4, 2: 5, 3: 6, 4: 7, 5: 8, 6: 9, 7: 10, 8: 11} @@ -138,6 +137,15 @@ class CotisationComputes: return Room.get_by_member_dn(user_session, residence_dn, member.dn) == None or cotisations == [] #end def + @staticmethod + # no cotisation for 2 years + def is_member_to_delete(member, user_session, residence_dn): + current_year = CotisationComputes.current_year() + cotisations_this_year = Cotisation.cotisations_of_member(user_session, member.dn, current_year) + cotisations_previous_year = Cotisation.cotisations_of_member(user_session, member.dn, current_year - 1) + return cotisations_this_year == [] and cotisations_previous_year == [] + #end def + @staticmethod # 7 days grace period def is_cotisation_paid(member, user_session, residence_dn): @@ -149,6 +157,8 @@ class CotisationComputes: cotisations = Cotisation.cotisations_of_member(user_session, member.dn, current_year) anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations) delta = (now - anniversary) + if member.dn == "uid=emir.kort,ou=2013,ou=membres,dc=ile,dc=u-psud,dc=fr": + print "member :" + member.dn + "delta :" + str(delta) + "now :" + str(now) + "anniversary :" + str(anniversary) return delta.days <= 7 #end def