[lc_ldap] On vire le from attributs import *, on corrige une faute de phrapp, et on vire les [xomu]fields, qu'on remplace par une variable attribs.
This commit is contained in:
parent
0d0d9d9676
commit
ecdfbd8962
1 changed files with 54 additions and 75 deletions
129
lc_ldap.py
129
lc_ldap.py
|
@ -58,7 +58,7 @@ sys.path.append('/usr/scripts/gestion')
|
|||
|
||||
import config
|
||||
import crans_utils
|
||||
from attributs import *
|
||||
import attributs
|
||||
from ldap_locks import CransLock
|
||||
|
||||
uri = 'ldap://ldap.adm.crans.org/'
|
||||
|
@ -109,7 +109,7 @@ def ldif_to_cldif(ldif, conn, check_ctxt = True):
|
|||
"""
|
||||
cldif = {}
|
||||
for attr, vals in ldif.items():
|
||||
cldif[attr] = [ attrify(val, attr, ldif, conn, check_ctxt) for val in vals]
|
||||
cldif[attr] = [ attributs.attrify(val, attr, ldif, conn, check_ctxt) for val in vals]
|
||||
return cldif
|
||||
|
||||
def cldif_to_ldif(cldif):
|
||||
|
@ -153,7 +153,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object):
|
|||
self.dn = dn
|
||||
self.droits = self.search_s(dn, ldap.SCOPE_BASE, attrlist=['droits'])[0][1].get('droits', [])
|
||||
if dn == admin_dn:
|
||||
self.droits += [nounou]
|
||||
self.droits += [attributs.nounou]
|
||||
else:
|
||||
self.conn = self.simple_bind_s()
|
||||
self.dn = None
|
||||
|
@ -209,7 +209,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object):
|
|||
for m in mlist:
|
||||
m._proprio = parent[dn]
|
||||
allmachines.append(m)
|
||||
return allmachines,parent.values() # on renvoie la liste des machines et des adherents (dont club et crans)
|
||||
return allmachines, parent.values() # on renvoie la liste des machines et des adherents (dont club et crans)
|
||||
|
||||
def allMachines(self):
|
||||
"""Renvoie la liste de toutes les machines, Conçue pour
|
||||
|
@ -321,7 +321,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object):
|
|||
continue
|
||||
else:
|
||||
# On crée l'attribut associé, pour parser sa valeur.
|
||||
my_id = attrify(unicode(i), attr, {}, self, False)
|
||||
my_id = attributs.attrify(unicode(i), attr, {}, self, False)
|
||||
if my_id.value != i:
|
||||
continue
|
||||
else:
|
||||
|
@ -340,20 +340,20 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object):
|
|||
"""
|
||||
|
||||
if obj.dn.endswith(self.dn) and obj.dn != self.dn:
|
||||
return [parent]
|
||||
return [attributs.parent]
|
||||
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def _is_self(obj1, obj2):
|
||||
def _is_self(self, obj):
|
||||
"""
|
||||
Teste si l'objet qui se binde est celui qui est en cours de modif.
|
||||
Retourne une liste qui s'ajoutera à la liste des droits
|
||||
"""
|
||||
|
||||
if obj.dn == self.dn:
|
||||
return [soi]
|
||||
return [attributs.soi]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
@ -427,22 +427,12 @@ class CransLdapObject(object):
|
|||
Cette classe ne devrait pas être utilisée directement."""
|
||||
|
||||
""" Qui peut faire quoi ? """
|
||||
can_be_by = { created: [nounou],
|
||||
modified: [nounou],
|
||||
deleted: [nounou],
|
||||
can_be_by = { created: [attributs.nounou],
|
||||
modified: [attributs.nounou],
|
||||
deleted: [attributs.nounou],
|
||||
}
|
||||
|
||||
""" Champs uniques et nécessaires """
|
||||
ufields = []
|
||||
|
||||
""" Champs uniques facultatifs """
|
||||
ofields = []
|
||||
|
||||
""" Champs multivalués facultatifs """
|
||||
mfields = []
|
||||
|
||||
""" Champs obligatoires multivalué """
|
||||
xfields = []
|
||||
attribs = []
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif = None):
|
||||
'''
|
||||
|
@ -508,7 +498,7 @@ class CransLdapObject(object):
|
|||
|
||||
def _get_fields(self):
|
||||
"""Renvoie la liste des champs LDAP de l'objet"""
|
||||
return self.ofields + self.xfields + self.ufields + self.mfields
|
||||
return self.attribs
|
||||
fields = property(_get_fields)
|
||||
|
||||
def history_add(self, login, chain):
|
||||
|
@ -596,17 +586,16 @@ class CransLdapObject(object):
|
|||
return []
|
||||
raise KeyError(attr)
|
||||
|
||||
def has_key(self,attr):
|
||||
def has_key(self, attr):
|
||||
"""Est-ce que notre objet a l'attribut en question ?"""
|
||||
return attr in self.ofields or attr in self.xfields or\
|
||||
attr in self.ufields or attr in self.mfields
|
||||
return attr in [attrib.__class__.__name__ for attrib in self.attributs]
|
||||
|
||||
def __setitem__(self, attr, values):
|
||||
if self.mode not in ['w', 'rw']:
|
||||
raise ValueError("Objet en lecture seule")
|
||||
if not isinstance(values, list):
|
||||
values = [ values ]
|
||||
self._modifs[attr] = [ attrify(val, attr, self._modifs, self.conn) for val in values ]
|
||||
self._modifs[attr] = [ attributs.attrify(val, attr, self._modifs, self.conn) for val in values ]
|
||||
|
||||
def search_historique(self, ign_fields=HIST_IGNORE_FIELDS):
|
||||
u"""Récupère l'historique
|
||||
|
@ -657,10 +646,10 @@ class CransLdapObject(object):
|
|||
# blacklistes virtuelle si on est un adhérent pour carte étudiant et chambre invalides
|
||||
if self.__class__.__name__ == "adherent" and self.paiement_ok():
|
||||
if not config.periode_transitoire and config.bl_carte_et_actif and not self.carte_ok() and not self.sursis_carte():
|
||||
bl = blacklist(u'%s$%s$%s$%s' % ('-', '-', 'carte_etudiant', ''), {}, self.conn, False)
|
||||
bl = attributs.blacklist(u'%s$%s$%s$%s' % ('-', '-', 'carte_etudiant', ''), {}, self.conn, False)
|
||||
blacklist_liste.append(bl)
|
||||
if self['chbre'][0].value == '????':
|
||||
bl = blacklist(u'%s$%s$%s$%s' % ('-', '-', 'chambre_invalide', ''), {}, self.conn, False)
|
||||
bl = attributs.blacklist(u'%s$%s$%s$%s' % ('-', '-', 'chambre_invalide', ''), {}, self.conn, False)
|
||||
blacklist_liste.append(bl)
|
||||
attrs = (self.attrs if self.mode not in ["w", "rw"] else self._modifs)
|
||||
blacklist_liste.extend(filter((lambda bl: bl.is_actif()), attrs.get("blacklist",[])))
|
||||
|
@ -679,22 +668,19 @@ class CransLdapObject(object):
|
|||
debut = int(time.time())
|
||||
if fin == 'now':
|
||||
fin = int(time.time())
|
||||
bl = blacklist(u'%s$%s$%s$%s' % (debut, fin, sanction, commentaire), {}, self.conn, False)
|
||||
bl = attributs.blacklist(u'%s$%s$%s$%s' % (debut, fin, sanction, commentaire), {}, self.conn, False)
|
||||
|
||||
self._modifs.setdefault('blacklist', []).append(bl)
|
||||
|
||||
|
||||
class proprio(CransLdapObject):
|
||||
u""" Un propriétaire de machine (adhérent, club…) """
|
||||
can_be_by = { created: [nounou, bureau, cableur],
|
||||
modified: [nounou, bureau, soi, cableur],
|
||||
deleted: [nounou, bureau],
|
||||
can_be_by = { created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
modified: [attributs.nounou, attributs.bureau, attributs.soi, attributs.cableur],
|
||||
deleted: [attributs.nounou, attributs.bureau],
|
||||
}
|
||||
|
||||
ufields = [ 'nom', 'chbre' ]
|
||||
mfields = [ 'paiement', 'info', 'blacklist', 'controle']
|
||||
ofields = []
|
||||
xfields = []
|
||||
attribs = [attributs.nom, attributs.chbre, attributs.paiement, attributs.info, attributs.blacklist, attributs.controle]
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif = None, machines=[]):
|
||||
super(proprio, self).__init__(conn, dn, mode, ldif)
|
||||
|
@ -780,16 +766,16 @@ class proprio(CransLdapObject):
|
|||
|
||||
class machine(CransLdapObject):
|
||||
u""" Une machine """
|
||||
can_be_by = { created: [nounou, bureau, cableur, parent],
|
||||
modified: [nounou, bureau, cableur, parent],
|
||||
deleted: [nounou, bureau, cableur, parent],
|
||||
can_be_by = { created: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent],
|
||||
modified: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent],
|
||||
deleted: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent],
|
||||
}
|
||||
|
||||
ufields = ['mid', 'macAddress', 'host', 'midType']
|
||||
ofields = ['rid']
|
||||
mfields = ['info', 'blacklist', 'hostAlias', 'exempt',
|
||||
'portTCPout', 'portTCPin', 'portUDPout', 'portUDPin','sshFingerprint', 'ipHostNumber', 'ip6HostNumber']
|
||||
xfields = []
|
||||
attribs = [attributs.mid, attributs.macAddress, attributs.host, attributs.midType,
|
||||
attributs.rid, attributs.info, attributs.blacklist, attributs.hostAlias,
|
||||
attributs.exempt, attributs.portTCPout, attributs.portTCPin,
|
||||
attributs.portUDPout, attributs.portUDPin, attributs.sshFingerprint,
|
||||
attributs.ipHostNumber, attributs.ip6HostNumber]
|
||||
|
||||
def __init__(self, conn, dn, mode='ro', ldif = None):
|
||||
super(machine, self).__init__(conn, dn, mode, ldif)
|
||||
|
@ -819,17 +805,15 @@ class AssociationCrans(proprio):
|
|||
|
||||
class adherent(proprio):
|
||||
u"""Adhérent crans."""
|
||||
ufields = proprio.ufields + ['aid', 'prenom', 'tel', 'mail', 'mailInvalide', 'uid']
|
||||
ofields = proprio.ofields + ['charteMA',
|
||||
'canonicalAlias', 'solde', 'contourneGreylist',
|
||||
'rewriteMailHeaders', 'derniereConnexion',
|
||||
'homepageAlias','gpgFingerprint',
|
||||
'compteWiki',
|
||||
]
|
||||
mfields = proprio.mfields + ['carteEtudiant', 'mailAlias', 'droits' ]
|
||||
xfields = ['etudes', 'postalAddress']
|
||||
attribs = proprio.attribs + [attributs.aid, attributs.prenom, attributs.tel,
|
||||
attributs.mail, attributs.mailInvalide, attributs.uid,
|
||||
attributs.charteMA, attributs.canonicalAlias, attributs.solde,
|
||||
attributs.contourneGreylist, attributs.derniereConnexion,
|
||||
attributs.homepageAlias, attributs.gpgFingerprint,
|
||||
attributs.carteEtudiant, attributs.mailAlias,
|
||||
attributs.droits, attributs.etudes, attributs.postalAddress]
|
||||
|
||||
def compte(self,login = None, uidNumber=0, hash_pass = '', shell=config.login_shell):
|
||||
def compte(self, login = None, uidNumber=0, hash_pass = '', shell=config.login_shell):
|
||||
u"""Renvoie le nom du compte crans. S'il n'existe pas, et que uid
|
||||
est précisé, le crée."""
|
||||
|
||||
|
@ -898,8 +882,7 @@ class adherent(proprio):
|
|||
|
||||
class club(proprio):
|
||||
u"""Club crans"""
|
||||
ufields = ['cid', 'responsable']
|
||||
mfields = ['imprimeurClub']
|
||||
attribs = proprio.attribs + [attributs.cid, attributs.responsable, attributs.imprimeurClub]
|
||||
|
||||
class machineFixe(machine):
|
||||
u"""Machine fixe"""
|
||||
|
@ -907,35 +890,31 @@ class machineFixe(machine):
|
|||
|
||||
class machineWifi(machine):
|
||||
u"""Machine wifi"""
|
||||
ufields = machine.ufields + ['ipsec']
|
||||
attribs = machine.attribs + [attributs.ipsec]
|
||||
|
||||
class machineCrans(machine):
|
||||
can_be_by = { created: [nounou],
|
||||
modified: [nounou],
|
||||
deleted: [nounou],
|
||||
can_be_by = { created: [attributs.nounou],
|
||||
modified: [attributs.nounou],
|
||||
deleted: [attributs.nounou],
|
||||
}
|
||||
ufields = machine.ufields + ['prise']
|
||||
ofields = machine.ofields + ['nombrePrises']
|
||||
attribs = machine.attribs + [attributs.prise, attributs.nombrePrises]
|
||||
|
||||
class borneWifi(machine):
|
||||
can_be_by = { created: [nounou],
|
||||
modified: [nounou],
|
||||
deleted: [nounou],
|
||||
can_be_by = { created: [attributs.nounou],
|
||||
modified: [attributs.nounou],
|
||||
deleted: [attributs.nounou],
|
||||
}
|
||||
ufields = machine.ufields + ['canal', 'puissance', 'hotspot',
|
||||
'prise', 'positionBorne', 'nvram']
|
||||
attribs = machine.attribs + [attributs.canal, attributs.puissance, attributs.hotspot,
|
||||
attributs.prise, attributs.positionBorne, attributs.nvram]
|
||||
|
||||
class facture(CransLdapObject):
|
||||
can_be_by = { created: [nounou, bureau, cableur],
|
||||
modified: [nounou, bureau, cableur],
|
||||
deleted: [nounou, bureau, cableur],
|
||||
can_be_by = { created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
modified: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
deleted: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
}
|
||||
ufields = ['fid', 'modePaiement', 'recuPaiement']
|
||||
attribs = [attributs.fid, attributs.modePaiement, attributs.recuPaiement]
|
||||
|
||||
class service(CransLdapObject): pass
|
||||
|
||||
class lock(CransLdapObject): pass
|
||||
|
||||
|
||||
MODIFIABLE_ATTRS = [ 'tel', 'chbre', 'mailAlias', 'loginShell' ]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue