From 990f791298cf294edaf52109c1ebbb4ee940b4a6 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 31 Oct 2015 12:55:19 +0100 Subject: [PATCH] =?UTF-8?q?Permet=20la=20cr=C3=A9ation=20de=20compte=20Cra?= =?UTF-8?q?ns=20quand=20l'objet=20est=20un=20club?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- objets.py | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/objets.py b/objets.py index 0e95dd8..6d4d673 100644 --- a/objets.py +++ b/objets.py @@ -948,7 +948,6 @@ class proprio(CransLdapObject): return self['uid'][0] elif login: - fn = crans_utils.strip_accents(unicode(self['prenom'][0]).capitalize()) ln = crans_utils.strip_accents(unicode(self['nom'][0]).capitalize()) login = crans_utils.strip_spaces(crans_utils.strip_accents(login), by=u'-').lower() if not re.match('^[a-z][-a-z]{1,15}$', login): @@ -956,24 +955,40 @@ class proprio(CransLdapObject): if crans_utils.mailexist(login): raise ValueError("Login existant ou correspondant à un alias mail.") - home = u'/home/' + login - if os.path.exists(home): - raise ValueError('Création du compte impossible : home existant') + if self.ldap_name == u'adherent': - if os.path.exists("/var/mail/" + login): - raise ValueError('Création du compte impossible : /var/mail/%s existant' % str(login)) + home = u'/home/' + login[0] + '/' + login + if os.path.exists(home): + raise ValueError('Création du compte impossible : home existant') - self._modifs['objectClass'] = [u'adherent', u'cransAccount', u'posixAccount', u'shadowAccount'] - self['uid'] = [login] - self['homeDirectory'] = [home] - self['mail'] = [login + u"@crans.org"] - calias = crans_utils.strip_spaces(fn) + u'.' + crans_utils.strip_spaces(ln) + '@crans.org' - if crans_utils.mailexist(calias): - calias = login + u'@crans.org' + if os.path.exists("/home/mail/" + login): + raise ValueError('Création du compte impossible : /home/mail/%s existant' % str(login)) + + fn = crans_utils.strip_accents(unicode(self['prenom'][0]).capitalize()) + self._modifs['objectClass'] = [u'adherent', u'cransAccount', u'posixAccount', u'shadowAccount'] + self['homeDirectory'] = [home] + self['cn'] = [fn + u' ' + ln] + self['mail'] = [login + u"@crans.org"] + calias = crans_utils.strip_spaces(fn) + u'.' + crans_utils.strip_spaces(ln) + '@crans.org' if crans_utils.mailexist(calias): - raise ValueError('Creation impossible, Alias canonique déjà pris, merci de choisir un autre login') - self['canonicalAlias'] = [calias] - self['cn'] = [fn + u' ' + ln] + calias = login + u'@crans.org' + if crans_utils.mailexist(calias): + raise ValueError('Creation impossible, Alias canonique déjà pris, merci de choisir un autre login') + self['canonicalAlias'] = [calias] + + else: + # C'est un club + home = u'/home/c/' + login + if os.path.exists(home): + raise ValueError('Création du compte impossible : home existant') + if os.path.exists("/home/mail/" + login): + raise ValueError('Création du compte impossible : /home/mail/%s existant' % str(login)) + self._modifs['objectClass'] = [u'club', u'cransAccount', u'posixAccount', u'shadowAccount'] + self['homeDirectory'] = [home] + self['cn'] = [ln] + + # Les attributs communs + self['uid'] = [login] self['loginShell'] = [unicode(shell)] if hash_pass: self['userPassword'] = [unicode(hash_pass)]