mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 23:16:00 +08:00
Put all aliases belonging to a directory to global trash when this directory is deleted
This commit is contained in:
parent
7a1f944887
commit
9898d85722
|
@ -1107,6 +1107,21 @@ class Directory(db.Model, ModelMixin):
|
|||
def nb_alias(self):
|
||||
return Alias.filter_by(directory_id=self.id).count()
|
||||
|
||||
@classmethod
|
||||
def delete(cls, obj_id):
|
||||
cls.query.filter(cls.id == obj_id).delete()
|
||||
db.session.commit()
|
||||
|
||||
# Put all aliases belonging to this mailbox to global trash
|
||||
try:
|
||||
for alias in Alias.query.filter_by(directory_id=obj_id):
|
||||
DeletedAlias.create(email=alias.email)
|
||||
db.session.commit()
|
||||
# this can happen when a previously deleted alias is re-created via catch-all or directory feature
|
||||
except IntegrityError:
|
||||
LOG.error("Some aliases have been added before to DeletedAlias")
|
||||
db.session.rollback()
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Directory {self.name}>"
|
||||
|
||||
|
|
Loading…
Reference in a new issue