From 50265a5c4b85f8cd9ea9eead40d6c71ecea931fb Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 9 Aug 2018 00:23:08 +0200 Subject: [PATCH] Fix bug evaluation des emailaddress + func get_mail sur user --- users/models.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/users/models.py b/users/models.py index 42310a03..73982b49 100755 --- a/users/models.py +++ b/users/models.py @@ -273,6 +273,20 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, else: raise NotImplementedError("Type inconnu") + @cached_property + def get_mail_addresses(self): + if self.local_email_enabled: + return self.emailaddress_set.all() + return None + + @cached_property + def get_mail(self): + """Return the mail address choosen by the user""" + if not OptionalUser.get_cached_value('local_email_accounts_enabled') or not self.local_email_enabled or self.local_email_redirect: + return str(self.email) + else: + return str(self.emailaddress_set.get(local_part=self.pseudo)) + @cached_property def class_name(self): """Renvoie si il s'agit d'un adhérent ou d'un club""" @@ -538,7 +552,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, user_ldap.sn = self.pseudo user_ldap.dialupAccess = str(self.has_access()) user_ldap.home_directory = '/home/' + self.pseudo - user_ldap.mail = self.email + user_ldap.mail = self.get_mail user_ldap.given_name = self.surname.lower() + '_'\ + self.name.lower()[:3] user_ldap.gid = LDAP['user_gid'] @@ -1684,11 +1698,11 @@ class EMailAddress(RevMixin, AclMixin, models.Model): verbose_name_plural = "Local email accounts" def __str__(self): - return self.local_part + OptionalUser.get_cached_value('local_email_domain') + return str(self.local_part) + OptionalUser.get_cached_value('local_email_domain') @cached_property def complete_email_address(self): - return self.local_part + OptionalUser.get_cached_value('local_email_domain') + return str(self.local_part) + OptionalUser.get_cached_value('local_email_domain') @staticmethod def can_create(user_request, userid, *_args, **_kwargs):