Suppression des machines si pas de cotisations depuis plus de 2 ans. Il est prévu de remplacer par une IP d'isolement au bout d'un mois mais il y a un bug avec le calcul de fin de connexion donc c'est trop risqué pour le moment.
This commit is contained in:
parent
067cb4bcbc
commit
872dbc62a0
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user