diff --git a/lc_ldap.py b/lc_ldap.py index a940b0a..3ecccf4 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -49,6 +49,7 @@ import datetime import copy import time import random +import string try: from Levenshtein import jaro @@ -231,7 +232,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): _,adherents = self.allMachinesAdherents() return adherents - def newMachine(self, parent, realm, uldif): + def newMachine(self, parent, realm, uldif, login=None): """Crée une nouvelle machine: ``realm`` peut être: fil, fil-v6, wifi, wifi-v6, adm, gratuit, personnel-ens, special --Partiellement implémenté""" @@ -248,6 +249,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): elif realm in ["wifi", "wifi-v6"]: uldif['objectClass'] = [u'machineWifi'] + uldif['ipsec'] = [u''.join( random.choice(filter(lambda x: x != 'l' and x != 'o', string.lowercase) + filter(lambda x: x != '1' and x != '0', string.digits)) for i in range(10))] assert isinstance(owner, adherent) or isinstance(owner, club) elif realm in ["fil-adherents", "fil-v6", "personnel-ens"]: @@ -272,10 +274,13 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): # Tout doit disparaître !! machine = self._create_entity('mid=%s,%s' % (uldif['mid'][0], parent), uldif) + login = login or current_user + machine.history_add(login, u"inscription") if machine.may_be(created, self.droits + self._check_parent(machine.dn)): machine.create() else: raise EnvironmentError("Vous n'avez pas le droit de créer cette machine.") + return machine def newAdherent(self, uldif): """Crée un nouvel adhérent""" @@ -530,7 +535,7 @@ class CransLdapObject(object): new_line = u"%s, %s : %s" % (time.strftime("%d/%m/%Y %H:%M"), login, chain) # Attention, le __setitem__ est surchargé, mais pas .append sur l'historique - self["historique"] = self["historique"] + [new_line] + self["historique"] = self.get("historique", []) + [new_line] def create(self): """Crée l'objet dans la base ldap, cette méthode vise à faire en sorte que