From 35f9c36461b7336c07df80a68a05e21f5b141744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Thu, 3 Apr 2014 17:30:09 +0200 Subject: [PATCH] =?UTF-8?q?[lc=5Fldap/clubs]=20La=20mise=20en=20place=20de?= =?UTF-8?q?s=20clubs=20dans=20l'intranet=20a=20=C3=A9t=C3=A9=20faite=20tro?= =?UTF-8?q?p=20t=C3=B4t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Aucun système de droit permettant au responsable de modifier club/machines de club n'avait été mis en place. C'est corrigé. --- attributs.py | 2 +- lc_ldap.py | 15 ++++++++++++++- objets.py | 24 ++++++++++++++---------- variables.py | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/attributs.py b/attributs.py index 9c1db76..814ddfe 100644 --- a/attributs.py +++ b/attributs.py @@ -1238,7 +1238,7 @@ class homeDirectory(Attr): Une adresse mail n'est modifiable que si on a au moins autant de droits que la personne à qui est l'adresse mail """ - modifiables = set() + modifiables = set() for i in liste_droits: if i in DROITS_SUPERVISEUR: modifiables = modifiables.union(DROITS_SUPERVISEUR[i]) diff --git a/lc_ldap.py b/lc_ldap.py index 017127c..b2f7f34 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -538,7 +538,6 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): if objdn.endswith(self.dn) and objdn != self.dn: return [attributs.parent] - else: return [] @@ -554,7 +553,21 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): else: return [] + def _check_respo(self, obj): + """ + Teste si l'objet fourni a pour responsable self. + Retourne une liste qui s'ajoutera à la liste des droits + """ + if "cid=" in obj.dn: + club = obj + if isinstance(obj, objets.machine) or isinstance(obj, objets.facture): + club = obj.proprio() + if isinstance(club, objets.club) and "aid=" + str(club['responsable'][0]) + "," + variables.base_dn == self.dn: + return [attributs.respo] + return [] + + return [] def get_local_machines(self, mode='ro'): filter="" diff --git a/objets.py b/objets.py index cfe40ef..2039df8 100644 --- a/objets.py +++ b/objets.py @@ -134,7 +134,7 @@ class CransLdapObject(object): la méthode est en anglais pour ne pas interférer avec les attributs droits et jinja2 où les méthodes de l'objet et ses attributs sont appelé de la même manière """ - return self.conn.droits + self.conn._check_parent(self.dn) + self.conn._check_self(self.dn) + return self.conn.droits + self.conn._check_parent(self.dn) + self.conn._check_self(self.dn) + self.conn._check_respo(self) def __init__(self, conn, dn, mode='ro', uldif=None, lockId=None): ''' @@ -180,15 +180,15 @@ class CransLdapObject(object): if dn == variables.base_dn: mode = 'ro' - if mode in ['w', 'rw']: - if not self.may_be(variables.modified): - raise EnvironmentError("Vous n'avez pas le droit de modifier cet objet.") - self.mode = mode + if self.mode in ['w', 'rw']: + if not self.may_be(variables.modified): + raise EnvironmentError("Vous n'avez pas le droit de modifier cet objet. DEB(dn=%s,user=%s,rights=%s)" % (dn, self.conn.dn, self.rights())) + self.update_attribs() - if mode in ['w', 'rw']: + if self.mode in ['w', 'rw']: # Vérification que `λv. str(Attr(v))` est bien une projection # C'est-à-dire que si on str(Attr(str(Attr(v)))) on retombe sur str(Attr(v)) oldif = lc_ldap.ldif_to_uldif(self.attrs.to_ldif()) @@ -578,7 +578,7 @@ class CransLdapObject(object): except ldap_locks.LockError: # Si on ne parvient pas à prendre le lock pour l'une des valeurs # on libère les locks pris jusque là et on propage l'erreur - # les anciens locks et self._modifs reste bien inchangés + # les anciens locks et self._modifs reste bien inchangés for (a, b, c) in locked: self.conn.lockholder.removelock(a, b, c) raise @@ -918,9 +918,9 @@ class proprio(CransLdapObject): class machine(CransLdapObject): u""" Une machine """ - can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent], - variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent], - variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent], + can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo], + variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo], + variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo], } attribs = [attributs.mid, attributs.macAddress, attributs.host, @@ -1150,6 +1150,10 @@ class adherent(proprio): @crans_object class club(proprio): u"""Club crans""" + can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur], + variables.modified: [attributs.nounou, attributs.bureau, attributs.respo, attributs.cableur], + variables.deleted: [attributs.nounou, attributs.bureau], + } attribs = proprio.attribs + [attributs.cid, attributs.responsable, attributs.imprimeurClub] ldap_name = "club" diff --git a/variables.py b/variables.py index 2e84ac4..4a4bbfe 100644 --- a/variables.py +++ b/variables.py @@ -6,7 +6,7 @@ ##: Encodage qu'on utilise pour parler à l'utilisateur si on n'a pas réussi à le détecter #fallback_encoding = 'utf-8' #: Encodage de la base LDAP -ldap_encoding = "utf-8" +ldap_encoding = "utf-8" #: uri par défaut de la base LDAP uri = "ldap://ldap.adm.crans.org/" #: dn racine de l'endroit où sont stockées les données