diff --git a/app/dashboard/templates/dashboard/domain_detail/auto-create.html b/app/dashboard/templates/dashboard/domain_detail/auto-create.html
index 7c56fc30..d6356d82 100644
--- a/app/dashboard/templates/dashboard/domain_detail/auto-create.html
+++ b/app/dashboard/templates/dashboard/domain_detail/auto-create.html
@@ -125,6 +125,39 @@
+
+
+
Debug Zone
+
You can test whether an alias will be automatically created given the rules above
+
+ No worries, no alias will be created during the test :)
+
+
+
+ {% if auto_create_test_result %}
+
+ {{ auto_create_test_result }}
+
+ {% endif %}
+
+
diff --git a/app/dashboard/views/domain_detail.py b/app/dashboard/views/domain_detail.py
index 10096e81..420b8dc9 100644
--- a/app/dashboard/views/domain_detail.py
+++ b/app/dashboard/views/domain_detail.py
@@ -1,3 +1,4 @@
+import re
from threading import Thread
from flask import render_template, request, redirect, url_for, flash
@@ -382,6 +383,12 @@ class AutoCreateRuleForm(FlaskForm):
)
+class AutoCreateTestForm(FlaskForm):
+ local = StringField(
+ "local part", validators=[validators.DataRequired(), validators.Length(max=128)]
+ )
+
+
@dashboard_bp.route(
"/domains//auto-create", methods=["GET", "POST"]
)
@@ -391,6 +398,13 @@ def domain_detail_auto_create(custom_domain_id):
mailboxes = current_user.mailboxes()
new_auto_create_rule_form = AutoCreateRuleForm()
+ auto_create_test_form = AutoCreateTestForm()
+ auto_create_test_local, auto_create_test_result, auto_create_test_passed = (
+ "",
+ "",
+ False,
+ )
+
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"))
@@ -476,6 +490,28 @@ def domain_detail_auto_create(custom_domain_id):
AutoCreateRule.delete(rule_id)
db.session.commit()
flash(f"Rule #{rule_order} has been deleted", "success")
+ elif request.form.get("form-name") == "test-auto-create-rule":
+ if auto_create_test_form.validate():
+ local = auto_create_test_form.local.data
+ auto_create_test_local = local
+
+ for rule in custom_domain.auto_create_rules:
+ rule: AutoCreateRule
+ regex = re.compile(rule.regex)
+ if re.fullmatch(regex, local):
+ auto_create_test_result = (
+ f"{local}@{custom_domain.domain} passes rule #{rule.order}"
+ )
+ auto_create_test_passed = True
+ break
+ else: # no rule passes
+ auto_create_test_result = (
+ f"{local}@{custom_domain.domain} doesn't pass any rule"
+ )
+
+ return render_template(
+ "dashboard/domain_detail/auto-create.html", **locals()
+ )
return redirect(
url_for(
@@ -483,6 +519,4 @@ def domain_detail_auto_create(custom_domain_id):
)
)
- nb_alias = Alias.filter_by(custom_domain_id=custom_domain.id).count()
-
return render_template("dashboard/domain_detail/auto-create.html", **locals())