Override Alias.create to check in global trash first
This commit is contained in:
parent
18e50e4a28
commit
300f1d7032
3
app/errors.py
Normal file
3
app/errors.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class AliasInTrashError(Exception):
|
||||||
|
"""raised when alias is deleted before """
|
||||||
|
pass
|
|
@ -630,6 +630,18 @@ class Alias(db.Model, ModelMixin):
|
||||||
user = db.relationship(User)
|
user = db.relationship(User)
|
||||||
mailbox = db.relationship("Mailbox")
|
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
|
@classmethod
|
||||||
def create_new(cls, user, prefix, note=None, mailbox_id=None):
|
def create_new(cls, user, prefix, note=None, mailbox_id=None):
|
||||||
if not prefix:
|
if not prefix:
|
||||||
|
|
Loading…
Reference in a new issue