8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 00:13:45 +00:00

Sync du pseudo et mailalias à la creation de l'user

This commit is contained in:
Gabriel Detraz 2018-06-30 02:53:19 +02:00
parent 081ae1e8dd
commit c942d87256

View file

@ -929,6 +929,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
'internal_address' : self.can_change_internal_address, 'internal_address' : self.can_change_internal_address,
} }
def clean(self, *args, **kwargs):
"""Check if this pseudo is already used by any mailalias.
Better than raising an error in post-save and catching it"""
if MailAlias.objects.filter(valeur=self.pseudo).exclude(user=self):
raise ValidationError("Ce pseudo est déjà utilisé")
def __str__(self): def __str__(self):
return self.pseudo return self.pseudo
@ -1051,9 +1057,11 @@ class Club(User):
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def user_post_save(**kwargs): def user_post_save(**kwargs):
""" Synchronisation post_save : envoie le mail de bienvenue si creation """ Synchronisation post_save : envoie le mail de bienvenue si creation
Synchronise le pseudo, en créant un alias mail correspondant
Synchronise le ldap""" Synchronise le ldap"""
is_created = kwargs['created'] is_created = kwargs['created']
user = kwargs['instance'] user = kwargs['instance']
mail_alias, created = MailAlias.objects.get_or_create(valeur=user.pseudo, user=user)
if is_created: if is_created:
user.notif_inscription() user.notif_inscription()
user.ldap_sync( user.ldap_sync(