Override Alias.create to check in global trash first

This commit is contained in:
Son NK 2020-05-07 22:23:36 +02:00
parent 18e50e4a28
commit 300f1d7032
2 changed files with 15 additions and 0 deletions

3
app/errors.py Normal file
View File

@ -0,0 +1,3 @@
class AliasInTrashError(Exception):
"""raised when alias is deleted before """
pass

View File

@ -630,6 +630,18 @@ class Alias(db.Model, ModelMixin):
user = db.relationship(User)
mailbox = db.relationship("Mailbox")
@classmethod
def create(cls, **kw):
r = cls(**kw)
# make sure alias is not in global trash, i.e. DeletedAlias table
email = kw["email"]
if DeletedAlias.get_by(email=email):
raise AliasInTrashError
db.session.add(r)
return r
@classmethod
def create_new(cls, user, prefix, note=None, mailbox_id=None):
if not prefix: