diff --git a/app/alias_utils.py b/app/alias_utils.py index f4ff0d3b..faed3856 100644 --- a/app/alias_utils.py +++ b/app/alias_utils.py @@ -330,7 +330,10 @@ def try_auto_create_via_domain(address: str) -> Optional[Alias]: def delete_alias( - alias: Alias, user: User, reason: AliasDeleteReason = AliasDeleteReason.Unspecified + alias: Alias, + user: User, + reason: AliasDeleteReason = AliasDeleteReason.Unspecified, + commit: bool = False, ): """ Delete an alias and add it to either global or domain trash @@ -366,6 +369,8 @@ def delete_alias( EventDispatcher.send_event( user, EventContent(alias_deleted=AliasDeleted(alias_id=alias.id)) ) + if commit: + Session.commit() def aliases_for_mailbox(mailbox: Mailbox) -> [Alias]: diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index a9a4f263..d48d7f38 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -145,7 +145,7 @@ def index(): LOG.i(f"User {current_user} requested deletion of alias {alias}") email = alias.email alias_utils.delete_alias( - alias, current_user, AliasDeleteReason.ManualAction + alias, current_user, AliasDeleteReason.ManualAction, commit=True ) flash(f"Alias {email} has been deleted", "success") elif request.form.get("form-name") == "disable-alias": diff --git a/app/subscription_webhook.py b/app/subscription_webhook.py index e117153c..6fd731bc 100644 --- a/app/subscription_webhook.py +++ b/app/subscription_webhook.py @@ -2,6 +2,7 @@ import requests from requests import RequestException from app import config +from app.db import Session from app.events.event_dispatcher import EventDispatcher from app.events.generated.event_pb2 import EventContent, UserPlanChanged from app.log import LOG @@ -29,10 +30,11 @@ def execute_subscription_webhook(user: User): LOG.i("Sent request to subscription update webhook successfully") else: LOG.i( - f"Request to webhook failed with statue {response.status_code}: {response.text}" + f"Request to webhook failed with status {response.status_code}: {response.text}" ) except RequestException as e: LOG.error(f"Subscription request exception: {e}") event = UserPlanChanged(plan_end_time=sl_subscription_end) EventDispatcher.send_event(user, EventContent(user_plan_change=event)) + Session.commit()