From b6e09c13a976b7490512e8e3ddce79b46caf5809 Mon Sep 17 00:00:00 2001 From: Roven Gabriel Date: Mon, 12 Aug 2013 18:44:05 +0200 Subject: [PATCH] suppression bug ajout membre, gestion ajout membre, correction bug ajout machine --- Brie/brie/controllers/edit.py | 45 +++++++++--- Brie/brie/controllers/members.py | 2 +- Brie/brie/lib/ldap_helper.py | 48 +++++++++++-- Brie/brie/model/ldap.py | 10 ++- .../member_room_interface_edit_views.html | 72 +++++++------------ Brie/brie/templates/members/index.html | 4 -- 6 files changed, 115 insertions(+), 66 deletions(-) diff --git a/Brie/brie/controllers/edit.py b/Brie/brie/controllers/edit.py index 09cb10f..3686a08 100644 --- a/Brie/brie/controllers/edit.py +++ b/Brie/brie/controllers/edit.py @@ -36,16 +36,31 @@ class EditController(AuthenticatedBaseController): """ Controller fils de gestion des machines """ machine = None + + member = None + def __init__(self, new_show): self.show = new_show self.wifi = WifiRestController(new_show) self.machine = MachineController() self.room = RoomController(new_show) + self.member = MemberModificationController() + + """ Affiche les détails éditables de la chambre """ + @expose("brie.templates.edit.room") + def room(self, residence, room_id): + return self.show.room(residence, room_id) + #end def + +#end class + +class MemberModificationController(AuthenticatedRestController): + require_group = groups_enum.admin """ Affiche les détails éditables du membre et de la chambre """ @expose("brie.templates.edit.member") - def member(self, residence, uid): + def get(self, residence, uid): residence_dn = Residences.get_dn_by_name(self.user, residence) if residence_dn is None: @@ -78,14 +93,20 @@ class EditController(AuthenticatedBaseController): "rooms" : rooms } #end def - - """ Affiche les détails éditables de la chambre """ - @expose("brie.templates.edit.room") - def room(self, residence, room_id): - return self.show.room(residence, room_id) - #end def -#end class + @expose() + def post(self, residence, member_uid, sn, givenName, mail, comment): + residence_dn = Residences.get_dn_by_name(self.user, residence) + member = Member.get_by_uid(self.user, residence_dn, member_uid) + + member.sn.replace(member.sn.first(), sn) + + member.givenName.replace(member.givenName.first(), givenName) + member.mail.replace(member.mail.first(), mail) + member.get("x-comment").replace(member.get("x-comment").first(), comment) + + self.user.ldap_bind.save(member) + #end def """ Controller de gestion des machines """ class MachineController(AuthenticatedBaseController): @@ -167,6 +188,14 @@ class MachineAddController(AuthenticatedRestController): taken_attribute = IpReservation.taken_attr(str(datetime.today())) self.user.ldap_bind.add_attr(ip.dn, taken_attribute) + machine_folder = Machine.folder_attr() + machine_folder_dn = ldap_config.machine_base_dn + member.dn + try: + self.user.ldap_bind.add_entry(machine_folder_dn, machine_folder) + except ldap.ALREADY_EXISTS: + pass # OKAY + #end try + # Attributs ldap de l'objet machine (regroupant dns et dhcp) machine_top = Machine.entry_attr(name) diff --git a/Brie/brie/controllers/members.py b/Brie/brie/controllers/members.py index bc7c5dd..9696354 100644 --- a/Brie/brie/controllers/members.py +++ b/Brie/brie/controllers/members.py @@ -74,7 +74,7 @@ class MembersAddController(AuthenticatedRestController): def post(self, residence, prenom, nom, mail): member_uid = Translations.to_uid(prenom, nom) - member = Member.entry_attr(member_uid, prenom, nom, mail, 1) + member = Member.entry_attr(member_uid, prenom, nom, mail, -1) residence_dn = Residences.get_dn_by_name(self.user, residence) diff --git a/Brie/brie/lib/ldap_helper.py b/Brie/brie/lib/ldap_helper.py index fd2a525..3feb3dc 100644 --- a/Brie/brie/lib/ldap_helper.py +++ b/Brie/brie/lib/ldap_helper.py @@ -86,11 +86,32 @@ class Ldap(object): def search_dn(self, dn): return self.search_first(dn, "(objectClass=*)", ldap.SCOPE_BASE) + + @staticmethod + def str_attributes(attributes): + def str_value(value): + if isinstance(value, str): + return value + elif isinstance(value, list): + return [str(subval) for subval in value] + #end if + + return str(value) + #end def + + return dict([ + (keyval[0], str_value(keyval[1])) + for keyval in attributes.iteritems() + ]) + #end def + """ Remplace les attributs d'un dn donné dn : adresse de l'élément attributes : dictionnaire d'attributs """ def replace_attr(self, dn, attributes): + attributes = Ldap.str_attributes(attributes) + modlist = [] for attribute in attributes.iteritems(): modlist.append((ldap.MOD_REPLACE, attribute[0], attribute[1])) @@ -103,6 +124,8 @@ class Ldap(object): attributes : dictionnaire des nouveaux attributs """ def add_attr(self, dn, attributes): + attributes = Ldap.str_attributes(attributes) + modlist = [] for attribute in attributes.iteritems(): modlist.append((ldap.MOD_ADD, attribute[0], attribute[1])) @@ -118,6 +141,8 @@ class Ldap(object): attributes : dictionnaire des attributs à supprimer """ def delete_attr(self, dn, attributes): + attributes = Ldap.str_attributes(attributes) + modlist = [] for attribute in attributes.iteritems(): modlist.append((ldap.MOD_DELETE, attribute[0], attribute[1])) @@ -133,6 +158,8 @@ class Ldap(object): attributes : dictionnaire des attributes de l'élément """ def add_entry(self, dn, attributes): + attributes = Ldap.str_attributes(attributes) + modlist = [] for attribute in attributes.iteritems(): modlist.append((attribute[0], attribute[1])) @@ -169,7 +196,7 @@ class Ldap(object): modlist = [] for global_deletion in ldap_entry._deletions: - modlist.append((ldap.MOD_DELETE, global_deletion, NONE)) + modlist.append((ldap.MOD_DELETE, global_deletion, None)) #end for ldap_entry._deletions = [] @@ -187,12 +214,14 @@ class Ldap(object): print "modified : " + str(ldap_attribute._modified) if ldap_attribute._deletions != []: - modlist.append((ldap.MOD_DELETE, ldap_attribute.name, ldap_attribute._deletions)) + str_values = [str(value) for value in ldap_attribute._deletions] + modlist.append((ldap.MOD_DELETE, ldap_attribute.name, str_values)) ldap_attribute._deletions = [] #end if if ldap_attribute._additions != []: - modlist.append((ldap.MOD_ADD, ldap_attribute.name, ldap_attribute._additions)) + str_values = [str(value) for value in ldap_attribute._additions] + modlist.append((ldap.MOD_ADD, ldap_attribute.name, str_values)) ldap_attribute._additions = [] #end if @@ -247,7 +276,10 @@ class LdapEntry(object): #end def def __getattr__(self, name): - return None + attr = LdapAttribute(name, []) + self.__dict__[name] = attr + + return attr #end def """ Ajoute un attribut """ @@ -346,7 +378,9 @@ class LdapAttribute(object): si la valeur est nulle, modifie la première valeur """ def replace(self, old, new): - + if old == new: + return + # Fonction usuelle de remplacement def replace(current): if current == old: @@ -360,6 +394,8 @@ class LdapAttribute(object): # l'ancienne valeur n'est que supprimée if new in self.values: self.delete(old) + elif self.values == []: + self.add(new) else: self.values = [replace(value) for value in self.values] @@ -370,7 +406,7 @@ class LdapAttribute(object): self._modified = True #end if - #end def + #end class diff --git a/Brie/brie/model/ldap.py b/Brie/brie/model/ldap.py index 56928ad..e70a668 100644 --- a/Brie/brie/model/ldap.py +++ b/Brie/brie/model/ldap.py @@ -14,7 +14,7 @@ class Member(object): "cn" : (prenom + " " + nom.upper()).encode("utf-8"), "sn" : (nom.upper()).encode("utf-8"), "givenName" : (prenom).encode("utf-8"), - "uidNumber" : uid_number, + "uidNumber" : str(uid_number), "gidNumber" : "10000", "homeDirectory" : ("/net/home/" + uid).encode("utf-8"), "mail" : mail.encode("utf-8"), @@ -120,6 +120,14 @@ class Wifi(object): class Machine(object): + @staticmethod + def folder_attr(): + return { + "objectClass" : ["organizationalRole", "top"], + "cn" : "machines" + } + #end def + @staticmethod def entry_attr(machine_id): return { diff --git a/Brie/brie/templates/edit/member_room_interface_edit_views.html b/Brie/brie/templates/edit/member_room_interface_edit_views.html index c8d9c8e..b6c0bc5 100644 --- a/Brie/brie/templates/edit/member_room_interface_edit_views.html +++ b/Brie/brie/templates/edit/member_room_interface_edit_views.html @@ -11,55 +11,35 @@ RETOUR -
- ${member_ldap.cn.first()} -
+
+ + +
+ ${member_ldap.cn.first()}
- Prénom - -
-
- Nom - -
-
- Fin de connexion - - Pas de fin de connexion - ${member_ldap.get("x-connectionEnd").first()} - -
-
- E-mail - -
-
- Certificat - - - oui - non - - -
-
- Commentaire - - - ${member_ldap.get("x-comment").first()} - -
-
- Cas spécial - - - oui - non - - +
+ Prénom + +
+
+ Nom + +
+
+ E-mail + +
+
+ Commentaire + +
+
+ + +
-
+
MACHINES
diff --git a/Brie/brie/templates/members/index.html b/Brie/brie/templates/members/index.html index 52984e1..1866a9d 100644 --- a/Brie/brie/templates/members/index.html +++ b/Brie/brie/templates/members/index.html @@ -52,10 +52,6 @@ ${member.givenName.first()} ${member.sn.first()} - - - ${member.room.cn.first()} -