1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-12 10:45:38 +02:00

Sync update of localpart, domain_name and email

This commit is contained in:
Alexander Graf 2021-03-12 17:56:17 +01:00
parent 0c38128c4e
commit 8bc4445572
2 changed files with 17 additions and 5 deletions

View File

@ -355,9 +355,21 @@ class Email(object):
self.localpart, self.domain_name = value.rsplit('@', 1)
self._email = value
# hack for email declared attr - when _email is not updated yet
def __str__(self):
return str(f'{self.localpart}@{self.domain_name}')
@staticmethod
def _update_localpart(target, value, *_):
if target.domain_name:
target._email = f'{value}@{target.domain_name}'
@staticmethod
def _update_domain_name(target, value, *_):
if target.localpart:
target._email = f'{target.localpart}@{value}'
@classmethod
def __declare_last__(cls):
# gets called after mappings are completed
sqlalchemy.event.listen(User.localpart, 'set', cls._update_localpart, propagate=True)
sqlalchemy.event.listen(User.domain_name, 'set', cls._update_domain_name, propagate=True)
def sendmail(self, subject, body):
""" send an email to the address """

View File

@ -1030,8 +1030,8 @@ class BaseSchema(ma.SQLAlchemyAutoSchema, Storage):
self.opts.sqla_session.add(item)
return item
# stop early if item has no password attribute
if not hasattr(item, 'password'):
# stop early when not updating or item has no password attribute
if not self.context.get('update') or not hasattr(item, 'password'):
return item
# did we hash a new plaintext password?