Compare commits

...

7 Commits

6 changed files with 25 additions and 33 deletions

View File

@ -4,9 +4,9 @@
{% block content %} {% block content %}
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
<p>{% blocktrans with address_name=object.full_address_name %}Are you sure that you want remove the address: "{{ address_name }}"?{% endblocktrans %}</p> <p>{% blocktrans with address_name=object.email %}Are you sure that you want remove the address: "{{ address_name }}"?{% endblocktrans %}</p>
<p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p> <p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p>
<a class="btn btn-light mr-2" href="{% url 'musician:address-update' object.pk %}">{% trans 'Cancel' %}</a>
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}"> <input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
<a class="btn btn-secondary" href="{% url 'musician:address-update' view.kwargs.pk %}">{% trans 'Cancel' %}</a>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -30,7 +30,7 @@
<td> <td>
{% for addr in mailbox.addresses.all %} {% for addr in mailbox.addresses.all %}
<a href="{% url 'musician:address-update' addr.pk %}"> <a href="{% url 'musician:address-update' addr.pk %}">
{{ addr.full_address_name }} {{ addr.email }}
</a><br/> </a><br/>
{% endfor %} {% endfor %}
</td> </td>

View File

@ -37,7 +37,7 @@
{% endif %} {% endif %}
<td>{{ resource.address_name}}</td> <td>{{ resource.address_name}}</td>
<td>{{ resource.admin_email }}</td> <td>{{ resource.admin_email }}</td>
<td><a href="{{ resource.manager_url }}" target="_blank" rel="noopener noreferrer">Mailtrain <i class="fas fa-external-link-alt"></i></a></td> <td><a href="{{ resource.get_absolute_url }}" target="_blank" rel="noopener noreferrer">Mailman <i class="fas fa-external-link-alt"></i></a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -5,12 +5,15 @@ URL routes definition.
Describe the paths where the views are accesible. Describe the paths where the views are accesible.
""" """
from django.urls import path from django.urls import path
from django.views.generic import RedirectView
from . import views from . import views
app_name = 'musician' app_name = 'musician'
urlpatterns = [ urlpatterns = [
path('', RedirectView.as_view(pattern_name='musician:dashboard', permanent=False), name='index'),
path('auth/login/', views.LoginView.as_view(), name='login'), path('auth/login/', views.LoginView.as_view(), name='login'),
path('auth/logout/', views.LogoutView.as_view(), name='logout'), path('auth/logout/', views.LogoutView.as_view(), name='logout'),
path('dashboard/', views.DashboardView.as_view(), name='dashboard'), path('dashboard/', views.DashboardView.as_view(), name='dashboard'),

View File

@ -1,3 +1,6 @@
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from orchestra.contrib.domains.helpers import domain_for_validation from orchestra.contrib.domains.helpers import domain_for_validation
from orchestra.contrib.domains.models import Record from orchestra.contrib.domains.models import Record
from orchestra.contrib.domains.validators import validate_zone from orchestra.contrib.domains.validators import validate_zone

View File

@ -1,10 +1,12 @@
import logging import logging
import smtplib import smtplib
from typing import Any
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.mail import mail_managers from django.core.mail import mail_managers
from django.db.models.query import QuerySet
from django.http import (HttpResponse, HttpResponseNotFound, from django.http import (HttpResponse, HttpResponseNotFound,
HttpResponseRedirect) HttpResponseRedirect)
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
@ -290,6 +292,9 @@ class MailUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
success_url = reverse_lazy("musician:address-list") success_url = reverse_lazy("musician:address-list")
extra_context = {'service': service_class} extra_context = {'service': service_class}
def get_queryset(self) -> QuerySet[Any]:
return self.model.objects.filter(account=self.request.user)
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super().get_form_kwargs() kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user kwargs["user"] = self.request.user
@ -298,22 +303,11 @@ class MailUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
template_name = "musician/address_check_delete.html" template_name = "musician/address_check_delete.html"
model = Address
success_url = reverse_lazy("musician:address-list") success_url = reverse_lazy("musician:address-list")
def get_object(self, queryset=None): def get_queryset(self) -> QuerySet[Any]:
obj = self.orchestra.retrieve_mail_address(self.kwargs['pk']) return self.model.objects.filter(account=self.request.user)
return obj
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
try:
self.orchestra.delete_mail_address(self.object.id)
messages.success(self.request, _('Address deleted!'))
except HTTPError as e:
messages.error(self.request, _('Cannot process your request, please try again later.'))
logger.error(e)
return HttpResponseRedirect(self.success_url)
class MailingListsView(ServiceListView): class MailingListsView(ServiceListView):
@ -397,29 +391,21 @@ class MailboxUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
class MailboxDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): class MailboxDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
model = Mailbox
template_name = "musician/mailbox_check_delete.html" template_name = "musician/mailbox_check_delete.html"
success_url = reverse_lazy("musician:mailbox-list") success_url = reverse_lazy("musician:mailbox-list")
def get_object(self, queryset=None): def get_queryset(self) -> QuerySet[Any]:
obj = self.orchestra.retrieve_mailbox(self.kwargs['pk']) return self.model.objects.filter(account=self.request.user)
return obj
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
self.object = self.get_object() response = super().delete(request, *args, **kwargs)
try:
self.orchestra.delete_mailbox(self.object.id)
messages.success(self.request, _('Mailbox deleted!'))
except HTTPError as e:
messages.error(self.request, _('Cannot process your request, please try again later.'))
logger.error(e)
self.notify_managers(self.object) self.notify_managers(self.object)
return response
return HttpResponseRedirect(self.success_url)
def notify_managers(self, mailbox): def notify_managers(self, mailbox):
user = self.get_context_data()['profile'] user = self.request.user
subject = 'Mailbox {} ({}) deleted | Musician'.format(mailbox.id, mailbox.name) subject = f"Mailbox '{mailbox.name}' ({mailbox.id}) deleted | Musician"
content = ( content = (
"User {} ({}) has deleted its mailbox {} ({}) via musician.\n" "User {} ({}) has deleted its mailbox {} ({}) via musician.\n"
"The mailbox has been marked as inactive but has not been removed." "The mailbox has been marked as inactive but has not been removed."