diff --git a/app/dashboard/templates/dashboard/domain_detail/info.html b/app/dashboard/templates/dashboard/domain_detail/info.html index f279e91e..bababf01 100644 --- a/app/dashboard/templates/dashboard/domain_detail/info.html +++ b/app/dashboard/templates/dashboard/domain_detail/info.html @@ -125,8 +125,8 @@ let that = $(this); bootbox.confirm({ - message: "All aliases associated with {{ custom_domain.domain }} will be also deleted, " + - " please confirm.", + message: "All aliases associated with {{ custom_domain.domain }} will be also deleted.
" + + "This operation is not reversible, please confirm.", buttons: { confirm: { label: 'Yes, delete it', diff --git a/app/dashboard/views/domain_detail.py b/app/dashboard/views/domain_detail.py index 09f5c604..58f752f4 100644 --- a/app/dashboard/views/domain_detail.py +++ b/app/dashboard/views/domain_detail.py @@ -1,3 +1,5 @@ +from threading import Thread + from flask import render_template, request, redirect, url_for, flash from flask_login import login_required, current_user @@ -9,8 +11,11 @@ from app.dns_utils import ( get_txt_record, get_cname_record, ) +from app.email_utils import send_email from app.extensions import db +from app.log import LOG from app.models import CustomDomain, Alias, DomainDeletedAlias +from server import create_light_app @dashboard_bp.route("/domains//dns", methods=["GET", "POST"]) @@ -181,9 +186,13 @@ def domain_detail(custom_domain_id): ) elif request.form.get("form-name") == "delete": name = custom_domain.domain - CustomDomain.delete(custom_domain_id) - db.session.commit() - flash(f"Domain {name} has been deleted", "success") + LOG.d("Schedule deleting %s", custom_domain) + Thread(target=delete_domain, args=(custom_domain_id,)).start() + flash( + f"{name} scheduled for deletion." + f"You will receive a confirmation email when the deletion is finished", + "success", + ) return redirect(url_for("dashboard.custom_domain")) @@ -192,6 +201,31 @@ def domain_detail(custom_domain_id): return render_template("dashboard/domain_detail/info.html", **locals()) +def delete_domain(custom_domain_id: CustomDomain): + with create_light_app().app_context(): + custom_domain = CustomDomain.get(custom_domain_id) + if not custom_domain: + return + + domain_name = custom_domain.domain + user = custom_domain.user + + CustomDomain.delete(custom_domain.id) + db.session.commit() + + LOG.d("Domain %s deleted", domain_name) + + send_email( + user.email, + f"Your domain {domain_name} has been deleted", + f"""Domain {domain_name} along with its aliases are deleted successfully. + +Regards, +SimpleLogin team. + """, + ) + + @dashboard_bp.route("/domains//trash", methods=["GET", "POST"]) @login_required def domain_detail_trash(custom_domain_id):