mirror of
https://github.com/simple-login/app.git
synced 2024-09-29 21:21:29 +02:00
user can block contact directly on the dashboard
This commit is contained in:
parent
2aab48a3f9
commit
0ae40d599a
@ -327,6 +327,8 @@
|
|||||||
{{ contact.website_email }}
|
{{ contact.website_email }}
|
||||||
<i class="fa fa-paper-plane mr-2" data-toggle="tooltip" title="Email sent to alias"></i>
|
<i class="fa fa-paper-plane mr-2" data-toggle="tooltip" title="Email sent to alias"></i>
|
||||||
{{ email_log.created_at | dt }}
|
{{ email_log.created_at | dt }}
|
||||||
|
{% include 'partials/toggle_contact.html' %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
No emails received/sent in the last 14 days. Created {{ alias.created_at | dt }}.
|
No emails received/sent in the last 14 days. Created {{ alias.created_at | dt }}.
|
||||||
|
@ -15,6 +15,7 @@ from app.models import (
|
|||||||
AliasGeneratorEnum,
|
AliasGeneratorEnum,
|
||||||
User,
|
User,
|
||||||
EmailLog,
|
EmailLog,
|
||||||
|
Contact,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -188,3 +189,28 @@ def index():
|
|||||||
filter=alias_filter,
|
filter=alias_filter,
|
||||||
stats=stats,
|
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
|
||||||
|
)
|
||||||
|
15
templates/partials/toggle_contact.html
Normal file
15
templates/partials/toggle_contact.html
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user