user can block contact directly on the dashboard

This commit is contained in:
Son 2021-11-03 11:29:46 +01:00
parent 2aab48a3f9
commit 0ae40d599a
3 changed files with 43 additions and 0 deletions

View File

@ -327,6 +327,8 @@
{{ contact.website_email }}
<i class="fa fa-paper-plane mr-2" data-toggle="tooltip" title="Email sent to alias"></i>
{{ email_log.created_at | dt }}
{% include 'partials/toggle_contact.html' %}
{% endif %}
{% else %}
No emails received/sent in the last 14 days. Created {{ alias.created_at | dt }}.

View File

@ -15,6 +15,7 @@ from app.models import (
AliasGeneratorEnum,
User,
EmailLog,
Contact,
)
@ -188,3 +189,28 @@ def index():
filter=alias_filter,
stats=stats,
)
@dashboard_bp.route("/contacts/<int:contact_id>/toggle", methods=["POST"])
def toggle_contact(contact_id):
"""
Block/Unblock contact
"""
contact = Contact.get(contact_id)
if not contact or contact.alias.user_id != current_user.id:
return "Forbidden", 403
contact.block_forward = not contact.block_forward
Session.commit()
if contact.block_forward:
toast_msg = f"{contact.website_email} can no longer send emails to {contact.alias.email}"
else:
toast_msg = (
f"{contact.website_email} can now send emails to {contact.alias.email}"
)
return render_template(
"partials/toggle_contact.html", contact=contact, toast_msg=toast_msg
)

View File

@ -0,0 +1,15 @@
<button
class="ml-2 btn btn-sm {% if contact.block_forward %} btn-outline-success {% else %} btn-outline-warning {% endif %}"
hx-post="{{ url_for('dashboard.toggle_contact', contact_id=contact.id) }}" hx-swap="outerHTML">
{% if contact.block_forward %}
Unblock sender
{% else %}
Block sender
{% endif %}
</button>
{% if toast_msg %}
<script>
toastr.success("{{ toast_msg }}");
</script>
{% endif %}