Allow deleting a mailbox (mark as inactive)
This commit is contained in:
parent
9b52bc4b92
commit
a0808896b4
|
@ -24,6 +24,7 @@ API_PATHS = {
|
|||
'address-list': 'addresses/',
|
||||
'address-detail': 'addresses/{pk}/',
|
||||
'mailbox-list': 'mailboxes/',
|
||||
'mailbox-detail': 'mailboxes/{pk}/',
|
||||
'mailinglist-list': 'lists/',
|
||||
'saas-list': 'saas/',
|
||||
'website-list': 'websites/',
|
||||
|
@ -168,10 +169,26 @@ class Orchestra(object):
|
|||
resource = '{}-list'.format(Mailbox.api_name)
|
||||
return self.request("POST", resource=resource, data=data, raise_exception=False)
|
||||
|
||||
def retrieve_mailbox(self, pk):
|
||||
path = API_PATHS.get('mailbox-detail').format_map({'pk': pk})
|
||||
|
||||
url = urllib.parse.urljoin(self.base_url, path)
|
||||
status, data_json = self.request("GET", url=url, raise_exception=False)
|
||||
if status == 404:
|
||||
raise Http404(_("No mailbox found matching the query"))
|
||||
return Mailbox.new_from_json(data_json)
|
||||
|
||||
def retrieve_mailbox_list(self):
|
||||
mailboxes = self.retrieve_service_list(Mailbox.api_name)
|
||||
return [Mailbox.new_from_json(mailbox_data) for mailbox_data in mailboxes]
|
||||
|
||||
def delete_mailbox(self, pk):
|
||||
path = API_PATHS.get('mailbox-detail').format_map({'pk': pk})
|
||||
url = urllib.parse.urljoin(self.base_url, path)
|
||||
# Mark as inactive instead of deleting
|
||||
# return self.request("DELETE", url=url, render_as=None)
|
||||
return self.request("PATCH", url=url, data={"is_active": False})
|
||||
|
||||
def retrieve_domain(self, pk):
|
||||
path = API_PATHS.get('domain-detail').format_map({'pk': pk})
|
||||
|
||||
|
|
12
musician/templates/musician/mailbox_check_delete.html
Normal file
12
musician/templates/musician/mailbox_check_delete.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% extends "musician/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<p>{% blocktrans with name=object.name %}Are you sure that you want remove the mailbox: "{{ name }}"?{% endblocktrans %}</p>
|
||||
<p><strong>{% trans 'NOTE: This action cannot be undone.' %}</strong></p>
|
||||
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
|
||||
<a class="btn btn-secondary" href="{% url 'musician:mailbox-list' %}">{% trans 'Cancel' %}</a>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -15,11 +15,13 @@
|
|||
<th scope="col">{% trans "Name" %}</th>
|
||||
<th scope="col">{% trans "Filtering" %}</th>
|
||||
<th scope="col">{% trans "Addresses" %}</th>
|
||||
<th scope="col">{% trans "Active" %}</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for mailbox in object_list %}
|
||||
{# <!-- Exclude (don't render) inactive mailboxes -->#}
|
||||
{% if mailbox.is_active %}
|
||||
<tr>
|
||||
<td>{{ mailbox.name }}</td>
|
||||
<td>{{ mailbox.filtering }}</td>
|
||||
|
@ -30,8 +32,12 @@
|
|||
</a><br/>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="pl-4 text-{{ mailbox.is_active|yesno:'success,danger' }}"><i class="fas fa-{{ mailbox.is_active|yesno:'check,times' }}"></i></td>
|
||||
<td>
|
||||
|
||||
<a class="btn btn-outline-danger" href="{% url 'musician:mailbox-delete' mailbox.id %}" title="{% trans 'Delete' %}"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}{# <!-- /is_active --> #}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% include "musician/components/table_paginator.html" %}
|
||||
|
|
|
@ -25,6 +25,7 @@ urlpatterns = [
|
|||
path('address/<int:pk>/delete/', views.AddressDeleteView.as_view(), name='address-delete'),
|
||||
path('mailboxes/', views.MailboxesView.as_view(), name='mailbox-list'),
|
||||
path('mailboxes/new/', views.MailboxCreateView.as_view(), name='mailbox-create'),
|
||||
path('mailboxes/<int:pk>/delete/', views.MailboxDeleteView.as_view(), name='mailbox-delete'),
|
||||
path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'),
|
||||
path('databases/', views.DatabasesView.as_view(), name='database-list'),
|
||||
path('saas/', views.SaasView.as_view(), name='saas-list'),
|
||||
|
|
|
@ -277,7 +277,8 @@ class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
|
|||
try:
|
||||
self.orchestra.delete_mail_address(self.object.id)
|
||||
except HTTPError as e:
|
||||
print(e)
|
||||
# TODO(@slamora): show error message to user
|
||||
logger.error(e)
|
||||
|
||||
return HttpResponseRedirect(self.success_url)
|
||||
|
||||
|
@ -355,6 +356,25 @@ class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, FormView):
|
|||
return super().form_valid(form)
|
||||
|
||||
|
||||
class MailboxDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
|
||||
template_name = "musician/mailbox_check_delete.html"
|
||||
success_url = reverse_lazy("musician:mailbox-list")
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
obj = self.orchestra.retrieve_mailbox(self.kwargs['pk'])
|
||||
return obj
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
try:
|
||||
self.orchestra.delete_mailbox(self.object.id)
|
||||
except HTTPError as e:
|
||||
# TODO(@slamora): show error message to user
|
||||
logger.error(e)
|
||||
|
||||
return HttpResponseRedirect(self.success_url)
|
||||
|
||||
|
||||
class DatabasesView(ServiceListView):
|
||||
template_name = "musician/databases.html"
|
||||
service_class = DatabaseService
|
||||
|
|
Loading…
Reference in a new issue