implement password change for mailboxes
- implement managemails.forms.ChangeMailboxPasswordForm - extract code for determining hosting package and customer from URL into HostingPackageAndCustomerMixin - implement managemails.views.ChangeMailboxPassword - add new URL pattern 'change_mailbox_password' to managemails.urls - add template managemails/mailbox_setpassword.html - link from template hostingpackages/customerhostingpackage_detail.html to change_mailbox_password - add german translation for new strings - document new feature in changelog
This commit is contained in:
parent
d1119331d8
commit
2e4efe7839
8 changed files with 178 additions and 21 deletions
|
@ -7,18 +7,46 @@ from __future__ import absolute_import, unicode_literals
|
|||
from django.http import HttpResponseForbidden
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
UpdateView,
|
||||
)
|
||||
from django.contrib import messages
|
||||
|
||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||
|
||||
from hostingpackages.models import CustomerHostingPackage
|
||||
|
||||
from .forms import CreateMailboxForm
|
||||
from .forms import (
|
||||
CreateMailboxForm,
|
||||
ChangeMailboxPasswordForm,
|
||||
)
|
||||
from .models import Mailbox
|
||||
|
||||
|
||||
class CreateMailbox(StaffOrSelfLoginRequiredMixin, CreateView):
|
||||
|
||||
class HostingPackageAndCustomerMixin(object):
|
||||
"""
|
||||
Mixin for views that gets the hosting package instance from the URL
|
||||
keyword argument 'package'.
|
||||
|
||||
"""
|
||||
hosting_package_kwarg = 'package'
|
||||
"""Keyword argument used to find the hosting package in the URL."""
|
||||
|
||||
def get_hosting_package(self):
|
||||
return get_object_or_404(
|
||||
CustomerHostingPackage,
|
||||
pk=int(self.kwargs[self.hosting_package_kwarg]))
|
||||
|
||||
def get_customer_object(self):
|
||||
return self.get_hosting_package().customer
|
||||
|
||||
|
||||
|
||||
class CreateMailbox(
|
||||
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView
|
||||
):
|
||||
"""
|
||||
This view is used to setup new mailboxes for a customer hosting package.
|
||||
|
||||
|
@ -30,28 +58,21 @@ class CreateMailbox(StaffOrSelfLoginRequiredMixin, CreateView):
|
|||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
resp = super(CreateMailbox, self).dispatch(request, *args, **kwargs)
|
||||
if not self._get_hosting_package().may_add_mailbox():
|
||||
if not self.get_hosting_package().may_add_mailbox():
|
||||
resp = HttpResponseForbidden(
|
||||
_('You are not allowed to add more mailboxes to this'
|
||||
' hosting package'))
|
||||
return resp
|
||||
|
||||
def _get_hosting_package(self):
|
||||
return get_object_or_404(
|
||||
CustomerHostingPackage, pk=int(self.kwargs['package']))
|
||||
|
||||
def get_customer_object(self):
|
||||
return self._get_hosting_package().customer
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateMailbox, self).get_context_data(**kwargs)
|
||||
context['hostingpackage'] = self._get_hosting_package()
|
||||
context['hostingpackage'] = self.get_hosting_package()
|
||||
context['customer'] = self.get_customer_object()
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(CreateMailbox, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self._get_hosting_package()
|
||||
kwargs['hostingpackage'] = self.get_hosting_package()
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -62,4 +83,39 @@ class CreateMailbox(StaffOrSelfLoginRequiredMixin, CreateView):
|
|||
mailbox=mailbox.username
|
||||
)
|
||||
)
|
||||
return redirect(self._get_hosting_package().get_absolute_url())
|
||||
return redirect(self.get_hosting_package())
|
||||
|
||||
|
||||
class ChangeMailboxPassword(
|
||||
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, UpdateView
|
||||
):
|
||||
"""
|
||||
This view is used to set a new password for an existing mailbox.
|
||||
|
||||
"""
|
||||
context_object_name = 'mailbox'
|
||||
form_class = ChangeMailboxPasswordForm
|
||||
model = Mailbox
|
||||
slug_field = 'username'
|
||||
template_name_suffix = '_setpassword'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ChangeMailboxPassword, self).get_context_data(**kwargs)
|
||||
context['hostingpackage'] = self.get_hosting_package()
|
||||
context['customer'] = self.get_customer_object()
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(ChangeMailboxPassword, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self.get_hosting_package()
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
mailbox = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully set new password for mailbox {mailbox}.').format(
|
||||
mailbox=mailbox.username
|
||||
)
|
||||
)
|
||||
return redirect(self.get_hosting_package())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue