Compare commits
7 Commits
ddd80fbf0e
...
8fe15e370b
Author | SHA1 | Date |
---|---|---|
Santiago L | 8fe15e370b | |
Santiago L | 954ddafec3 | |
Santiago L | 4dc5de4016 | |
Santiago L | 1a3a015d61 | |
Santiago L | f140fe480e | |
Santiago L | d4b44d58c8 | |
Santiago L | 216c4d9419 |
|
@ -4,9 +4,9 @@
|
|||
{% block content %}
|
||||
<form method="post">
|
||||
{% 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>
|
||||
<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' %}">
|
||||
<a class="btn btn-secondary" href="{% url 'musician:address-update' view.kwargs.pk %}">{% trans 'Cancel' %}</a>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<td>
|
||||
{% for addr in mailbox.addresses.all %}
|
||||
<a href="{% url 'musician:address-update' addr.pk %}">
|
||||
{{ addr.full_address_name }}
|
||||
{{ addr.email }}
|
||||
</a><br/>
|
||||
{% endfor %}
|
||||
</td>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
{% endif %}
|
||||
<td>{{ resource.address_name}}</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>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -5,12 +5,15 @@ URL routes definition.
|
|||
Describe the paths where the views are accesible.
|
||||
"""
|
||||
from django.urls import path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'musician'
|
||||
|
||||
urlpatterns = [
|
||||
path('', RedirectView.as_view(pattern_name='musician:dashboard', permanent=False), name='index'),
|
||||
|
||||
path('auth/login/', views.LoginView.as_view(), name='login'),
|
||||
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
|
||||
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
|
||||
|
|
|
@ -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.models import Record
|
||||
from orchestra.contrib.domains.validators import validate_zone
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import logging
|
||||
import smtplib
|
||||
from typing import Any
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.mail import mail_managers
|
||||
from django.db.models.query import QuerySet
|
||||
from django.http import (HttpResponse, HttpResponseNotFound,
|
||||
HttpResponseRedirect)
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
@ -290,6 +292,9 @@ class MailUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
|||
success_url = reverse_lazy("musician:address-list")
|
||||
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):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs["user"] = self.request.user
|
||||
|
@ -298,22 +303,11 @@ class MailUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
|||
|
||||
class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
|
||||
template_name = "musician/address_check_delete.html"
|
||||
model = Address
|
||||
success_url = reverse_lazy("musician:address-list")
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
obj = self.orchestra.retrieve_mail_address(self.kwargs['pk'])
|
||||
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)
|
||||
def get_queryset(self) -> QuerySet[Any]:
|
||||
return self.model.objects.filter(account=self.request.user)
|
||||
|
||||
|
||||
class MailingListsView(ServiceListView):
|
||||
|
@ -397,29 +391,21 @@ class MailboxUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
|||
|
||||
|
||||
class MailboxDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView):
|
||||
model = Mailbox
|
||||
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 get_queryset(self) -> QuerySet[Any]:
|
||||
return self.model.objects.filter(account=self.request.user)
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
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)
|
||||
|
||||
response = super().delete(request, *args, **kwargs)
|
||||
self.notify_managers(self.object)
|
||||
|
||||
return HttpResponseRedirect(self.success_url)
|
||||
return response
|
||||
|
||||
def notify_managers(self, mailbox):
|
||||
user = self.get_context_data()['profile']
|
||||
subject = 'Mailbox {} ({}) deleted | Musician'.format(mailbox.id, mailbox.name)
|
||||
user = self.request.user
|
||||
subject = f"Mailbox '{mailbox.name}' ({mailbox.id}) deleted | Musician"
|
||||
content = (
|
||||
"User {} ({}) has deleted its mailbox {} ({}) via musician.\n"
|
||||
"The mailbox has been marked as inactive but has not been removed."
|
||||
|
|
Loading…
Reference in New Issue