From dd94fcd228889219e598adf99676d2be37df7be7 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sat, 15 Mar 2014 22:45:06 +0100 Subject: [PATCH] =?UTF-8?q?[services]=20Cr=C3=A9ation=20et=20suppression?= =?UTF-8?q?=20des=20homes=20si=20modif=20de=20l'objectClass=20cransAccount?= =?UTF-8?q?,=20rattrapage=20d'une=20erreur=20si=20le=20service=20a=20red?= =?UTF-8?q?=C3=A9marrer=20existe=20d=C3=A9j=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/services.py b/services.py index e9af93c..61ee752 100644 --- a/services.py +++ b/services.py @@ -138,7 +138,7 @@ def services_to_time_mail_bienvenue(x): if u'cransAccount' in [ str(o) for o in adh['objectClass']]: return [ NOW + 660 ] else: - return [ 0 ] + return [ NOW + 660 ] # génération des arguments du service à redémarrer (par defaut []) services_to_args={} @@ -302,7 +302,7 @@ def service_to_restart(conn, new=None, args=[], start=0): 'start': start }) try: conn.add_s(serv_dn, modlist) - except ldap.ALREADY_EXISTS: + except (ldap.ALREADY_EXISTS, ldap.TYPE_OR_VALUE_EXISTS): # Existe déja => rien à faire pass @@ -311,6 +311,18 @@ def services_to_restart(conn, old_attrs={}, new_attrs={}, created_object=[], del update_now() + added_objectClass = [obc for obc in new_attrs.get("objectClass", []) if not obc in old_attrs.get("objectClass", [])] + deleted_objectClass = [obc for obc in old_attrs.get("objectClass", []) if not obc in new_attrs.get("objectClass", [])] + + # Je met la reconfiguration du home / del_user à la main pour la création/suppression d'un compte crans + # parce que que je vois pas vraiement comment faire autrement + if 'cransAccount' in added_objectClass: + arg = services_to_args['home'](added_objectClass[0]) + service_to_restart(conn, "home", list(arg), 0) + + if 'cransAccount' in deleted_objectClass: + service_to_restart(conn, "del_user", ["%s,%s" % (old_attrs['uid'][0], old_attrs['homeDirectory'][0])], 0) + # On tranforme les dico *_attrs du type string -> attr en *_attrs_c du type class -> attr old_attrs_c = dict((attributs.AttributeFactory.get(key), value) for key,value in old_attrs.items() if attributs.AttributeFactory.get(key, fallback=None) != None and value) new_attrs_c = dict((attributs.AttributeFactory.get(key), value) for key,value in new_attrs.items() if attributs.AttributeFactory.get(key, fallback=None) != None and value)