From a3ff19dac4772fed2515310f28e79dd3f53e6b9a Mon Sep 17 00:00:00 2001
From: Son NK <>
Date: Sat, 23 May 2020 11:48:43 +0200
Subject: [PATCH] create custom domain trash page
---
.../dashboard/domain_detail/base.html | 5 ++
.../dashboard/domain_detail/trash.html | 50 +++++++++++++++++
app/dashboard/views/domain_detail.py | 56 ++++++++++++++++++-
3 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 app/dashboard/templates/dashboard/domain_detail/trash.html
diff --git a/app/dashboard/templates/dashboard/domain_detail/base.html b/app/dashboard/templates/dashboard/domain_detail/base.html
index 81484eaa..a2cd6cc7 100644
--- a/app/dashboard/templates/dashboard/domain_detail/base.html
+++ b/app/dashboard/templates/dashboard/domain_detail/base.html
@@ -15,6 +15,11 @@
class="list-group-item list-group-item-action {{ 'active' if domain_detail_page == 'dns' }}">
DNS
+
+
+ Deleted Alias
+
diff --git a/app/dashboard/templates/dashboard/domain_detail/trash.html b/app/dashboard/templates/dashboard/domain_detail/trash.html
new file mode 100644
index 00000000..a4931a54
--- /dev/null
+++ b/app/dashboard/templates/dashboard/domain_detail/trash.html
@@ -0,0 +1,50 @@
+{% extends 'dashboard/domain_detail/base.html' %}
+
+{% set domain_detail_page = "trash" %}
+
+{% block title %}
+ {{ custom_domain.domain }} deleted aliases
+{% endblock %}
+
+{% block domain_detail_content %}
+
{{ custom_domain.domain }} deleted alias (aka Trash)
+
+ How to use
+
+
+
+
+ On this page you can view all aliases that have been deleted and belong to the domain
+ {{ custom_domain.domain }}.
+ When an alias is in the trash, it cannot be re-created, either via the alias creation page or on-the-fly with the
+ domain catch-all option.
+
+
+ {% if domain_deleted_aliases | length > 0 %}
+
+ {% else %}
+ There's no deleted alias recorded for this domain.
+ {% endif %}
+
+
+ {% for deleted_alias in domain_deleted_aliases %}
+
+ {{ deleted_alias.email }} -
+ deleted {{ deleted_alias.created_at | dt }}
+
+ {% endfor %}
+
+
+{% endblock %}
diff --git a/app/dashboard/views/domain_detail.py b/app/dashboard/views/domain_detail.py
index 497b3471..5e00f18d 100644
--- a/app/dashboard/views/domain_detail.py
+++ b/app/dashboard/views/domain_detail.py
@@ -10,7 +10,7 @@ from app.dns_utils import (
get_cname_record,
)
from app.extensions import db
-from app.models import CustomDomain, Alias
+from app.models import CustomDomain, Alias, DomainDeletedAlias
@dashboard_bp.route("/domains//dns", methods=["GET", "POST"])
@@ -171,3 +171,57 @@ def domain_detail(custom_domain_id):
nb_alias = Alias.filter_by(custom_domain_id=custom_domain.id).count()
return render_template("dashboard/domain_detail/info.html", **locals())
+
+
+@dashboard_bp.route("/domains//trash", methods=["GET", "POST"])
+@login_required
+def domain_detail_trash(custom_domain_id):
+ custom_domain = CustomDomain.get(custom_domain_id)
+ if not custom_domain or custom_domain.user_id != current_user.id:
+ flash("You cannot see this page", "warning")
+ return redirect(url_for("dashboard.index"))
+
+ if request.method == "POST":
+ if request.form.get("form-name") == "empty-all":
+ DomainDeletedAlias.filter_by(domain_id=custom_domain.id).delete()
+ db.session.commit()
+
+ flash("All deleted aliases can now be re-created", "success")
+ return redirect(
+ url_for(
+ "dashboard.domain_detail_trash", custom_domain_id=custom_domain.id
+ )
+ )
+ elif request.form.get("form-name") == "remove-single":
+ deleted_alias_id = request.form.get("deleted-alias-id")
+ deleted_alias = DomainDeletedAlias.get(deleted_alias_id)
+ if not deleted_alias or deleted_alias.domain_id != custom_domain.id:
+ flash("Unknown error, refresh the page", "warning")
+ return redirect(
+ url_for(
+ "dashboard.domain_detail_trash",
+ custom_domain_id=custom_domain.id,
+ )
+ )
+
+ DomainDeletedAlias.delete(deleted_alias.id)
+ db.session.commit()
+ flash(
+ f"{deleted_alias.email} can now be re-created", "success",
+ )
+
+ return redirect(
+ url_for(
+ "dashboard.domain_detail_trash", custom_domain_id=custom_domain.id
+ )
+ )
+
+ domain_deleted_aliases = DomainDeletedAlias.filter_by(
+ domain_id=custom_domain.id
+ ).all()
+
+ return render_template(
+ "dashboard/domain_detail/trash.html",
+ domain_deleted_aliases=domain_deleted_aliases,
+ custom_domain=custom_domain,
+ )