fix Directory.create: use alias_utils.delete_alias
This commit is contained in:
parent
2cae0200a8
commit
b4eb110971
|
@ -1451,15 +1451,11 @@ class Directory(db.Model, ModelMixin):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, obj_id):
|
def delete(cls, obj_id):
|
||||||
# Put all aliases belonging to this directory to global trash
|
obj: Directory = cls.get(obj_id)
|
||||||
try:
|
user = obj.user
|
||||||
|
# Put all aliases belonging to this directory to global or domain trash
|
||||||
for alias in Alias.query.filter_by(directory_id=obj_id):
|
for alias in Alias.query.filter_by(directory_id=obj_id):
|
||||||
DeletedAlias.create(email=alias.email)
|
alias_utils.delete_alias(alias, user)
|
||||||
db.session.commit()
|
|
||||||
# this can happen when a previously deleted alias is re-created via catch-all or directory feature
|
|
||||||
except IntegrityError:
|
|
||||||
LOG.exception("Some aliases have been added before to DeletedAlias")
|
|
||||||
db.session.rollback()
|
|
||||||
|
|
||||||
cls.query.filter(cls.id == obj_id).delete()
|
cls.query.filter(cls.id == obj_id).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in a new issue