able to choose mailboxes for a domain
This commit is contained in:
parent
ec8f120085
commit
f5bc166f39
|
@ -20,7 +20,10 @@
|
|||
|
||||
{% if not current_user.is_premium() %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
This feature is only available for Premium users. <a href="https://app.simplelogin.io/dashboard/pricing" target="_blank" rel="noopener">Upgrade<i class="fe fe-external-link"></i></a>
|
||||
This feature is only available on Premium plan.
|
||||
<a href="https://app.simplelogin.io/dashboard/pricing" target="_blank" rel="noopener">
|
||||
Upgrade<i class="fe fe-external-link"></i>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@ -46,33 +49,99 @@
|
|||
</span>
|
||||
{% endif %}
|
||||
</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">
|
||||
|
||||
<h6 class="card-subtitle mb-4 text-muted">
|
||||
Created {{ custom_domain.created_at | dt }} <br>
|
||||
<span class="font-weight-bold">{{ custom_domain.nb_alias() }}</span> aliases.
|
||||
<br><br>
|
||||
|
||||
<b>Mailboxes:</b>
|
||||
<i class="fe fe-info" data-toggle="tooltip"
|
||||
title="Aliases created with this domain are automatically owned by these mailboxes">
|
||||
</i>
|
||||
<br>
|
||||
|
||||
{% set domain_mailboxes=custom_domain.mailboxes %}
|
||||
<form method="post" class="mt-2">
|
||||
<input type="hidden" name="form-name" value="update">
|
||||
<input type="hidden" name="domain-id" value="{{ custom_domain.id }}">
|
||||
|
||||
<div class="d-flex">
|
||||
<div class="flex-grow-1 mr-2">
|
||||
<select data-width="100%" required
|
||||
class="mailbox-select" multiple name="mailbox_ids">
|
||||
{% for mailbox in mailboxes %}
|
||||
<option value="{{ mailbox.id }}" {% if mailbox in domain_mailboxes %}
|
||||
selected {% endif %}>
|
||||
{{ mailbox.email }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn btn-outline-primary btn-sm">Update</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</h6>
|
||||
|
||||
<a href="{{ url_for('dashboard.domain_detail', custom_domain_id=custom_domain.id) }}">Details ➡</a>
|
||||
<a href="{{ url_for('dashboard.domain_detail', custom_domain_id=custom_domain.id) }}" class="mt-3">
|
||||
Details ➡
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
{{ new_custom_domain_form.csrf_token }}
|
||||
<input type="hidden" name="form-name" value="create">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<h2 class="h4">New Domain</h2>
|
||||
<form method="post" class="mt-2">
|
||||
{{ new_custom_domain_form.csrf_token }}
|
||||
<input type="hidden" name="form-name" value="create">
|
||||
|
||||
{{ new_custom_domain_form.domain(class="form-control", placeholder="my-domain.com", maxlength=128) }}
|
||||
{{ render_field_errors(new_custom_domain_form.domain) }}
|
||||
<div class="small-text">Please use full path domain, for ex <em>my-subdomain.my-domain.com</em></div>
|
||||
<h2 class="h4">New Domain</h2>
|
||||
|
||||
<button class="btn btn-lg btn-success mt-2">Create</button>
|
||||
</form>
|
||||
{{ new_custom_domain_form.domain(class="form-control", placeholder="my-domain.com", maxlength=128) }}
|
||||
{{ render_field_errors(new_custom_domain_form.domain) }}
|
||||
<div class="small-text">
|
||||
Please use full path domain, for ex <em>my-subdomain.my-domain.com</em>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 small-text alert alert-info">
|
||||
By default, aliases created with your domain are "owned" by your default
|
||||
mailbox <b>{{ current_user.default_mailbox.email }}</b>. <br>
|
||||
This below option allow you to choose the mailbox(es) that a new alias automatically belongs to.
|
||||
</div>
|
||||
|
||||
<select data-width="100%"
|
||||
class="mailbox-select" multiple name="mailbox_ids">
|
||||
{% for mailbox in mailboxes %}
|
||||
<option value="{{ mailbox.id }}" {% if mailbox.id == current_user.default_mailbox_id %}
|
||||
selected {% endif %}>
|
||||
{{ mailbox.email }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<button class="btn btn-lg btn-success mt-2">Create</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script>
|
||||
$('.mailbox-select').multipleSelect();
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -7,7 +7,7 @@ from app.config import EMAIL_SERVERS_WITH_PRIORITY
|
|||
from app.dashboard.base import dashboard_bp
|
||||
from app.email_utils import get_email_domain_part
|
||||
from app.extensions import db
|
||||
from app.models import CustomDomain
|
||||
from app.models import CustomDomain, Mailbox, DomainMailbox
|
||||
|
||||
|
||||
class NewCustomDomainForm(FlaskForm):
|
||||
|
@ -20,7 +20,7 @@ class NewCustomDomainForm(FlaskForm):
|
|||
@login_required
|
||||
def custom_domain():
|
||||
custom_domains = CustomDomain.query.filter_by(user_id=current_user.id).all()
|
||||
|
||||
mailboxes = current_user.mailboxes()
|
||||
new_custom_domain_form = NewCustomDomainForm()
|
||||
|
||||
errors = {}
|
||||
|
@ -54,6 +54,28 @@ def custom_domain():
|
|||
)
|
||||
db.session.commit()
|
||||
|
||||
mailbox_ids = request.form.getlist("mailbox_ids")
|
||||
if mailbox_ids:
|
||||
# check if mailbox is not tempered with
|
||||
mailboxes = []
|
||||
for mailbox_id in mailbox_ids:
|
||||
mailbox = Mailbox.get(mailbox_id)
|
||||
if (
|
||||
not mailbox
|
||||
or mailbox.user_id != current_user.id
|
||||
or not mailbox.verified
|
||||
):
|
||||
flash("Something went wrong, please retry", "warning")
|
||||
return redirect(url_for("dashboard.custom_domain"))
|
||||
mailboxes.append(mailbox)
|
||||
|
||||
for mailbox in mailboxes:
|
||||
DomainMailbox.create(
|
||||
domain_id=new_custom_domain.id, mailbox_id=mailbox.id
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
flash(
|
||||
f"New domain {new_custom_domain.domain} is created", "success"
|
||||
)
|
||||
|
@ -64,6 +86,43 @@ def custom_domain():
|
|||
custom_domain_id=new_custom_domain.id,
|
||||
)
|
||||
)
|
||||
elif request.form.get("form-name") == "update":
|
||||
domain_id = request.form.get("domain-id")
|
||||
domain = CustomDomain.get(domain_id)
|
||||
|
||||
if not domain or domain.user_id != current_user.id:
|
||||
flash("Unknown error. Refresh the page", "warning")
|
||||
return redirect(url_for("dashboard.custom_domain"))
|
||||
|
||||
mailbox_ids = request.form.getlist("mailbox_ids")
|
||||
# check if mailbox is not tempered with
|
||||
mailboxes = []
|
||||
for mailbox_id in mailbox_ids:
|
||||
mailbox = Mailbox.get(mailbox_id)
|
||||
if (
|
||||
not mailbox
|
||||
or mailbox.user_id != current_user.id
|
||||
or not mailbox.verified
|
||||
):
|
||||
flash("Something went wrong, please retry", "warning")
|
||||
return redirect(url_for("dashboard.custom_domain"))
|
||||
mailboxes.append(mailbox)
|
||||
|
||||
if not mailboxes:
|
||||
flash("You must select at least 1 mailbox", "warning")
|
||||
return redirect(url_for("dashboard.custom_domain"))
|
||||
|
||||
# first remove all existing domain-mailboxes links
|
||||
DomainMailbox.query.filter_by(domain_id=domain.id).delete()
|
||||
db.session.flush()
|
||||
|
||||
for mailbox in mailboxes:
|
||||
DomainMailbox.create(domain_id=domain.id, mailbox_id=mailbox.id)
|
||||
|
||||
db.session.commit()
|
||||
flash(f"Domain {domain.domain} has been updated", "success")
|
||||
|
||||
return redirect(url_for("dashboard.custom_domain"))
|
||||
|
||||
return render_template(
|
||||
"dashboard/custom_domain.html",
|
||||
|
@ -71,4 +130,5 @@ def custom_domain():
|
|||
new_custom_domain_form=new_custom_domain_form,
|
||||
EMAIL_SERVERS_WITH_PRIORITY=EMAIL_SERVERS_WITH_PRIORITY,
|
||||
errors=errors,
|
||||
mailboxes=mailboxes,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue