mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 17:35:27 +08:00
Override Alias.create to check in global trash first
This commit is contained in:
parent
18e50e4a28
commit
300f1d7032
2 changed files with 15 additions and 0 deletions
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)
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue