From 9883db6fa28ec854cc569e2286620a16279bf804 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:00:30 +0100 Subject: [PATCH 1/6] implement new module gvawebcore to provide common code - add gvawebcore.forms.PasswordModelFormMixin - add generated documentation - add german translation --- docs/code.rst | 1 + docs/code/gvawebcore.rst | 11 +++++ gnuviechadmin/gvawebcore/__init__.py | 5 +++ gnuviechadmin/gvawebcore/forms.py | 43 +++++++++++++++++++ .../locale/de/LC_MESSAGES/django.po | 32 ++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 docs/code/gvawebcore.rst create mode 100644 gnuviechadmin/gvawebcore/__init__.py create mode 100644 gnuviechadmin/gvawebcore/forms.py create mode 100644 gnuviechadmin/gvawebcore/locale/de/LC_MESSAGES/django.po diff --git a/docs/code.rst b/docs/code.rst index adc9570..e334f04 100644 --- a/docs/code.rst +++ b/docs/code.rst @@ -15,6 +15,7 @@ Common code .. toctree:: code/gvacommon + code/gvawebcore Celery task stubs diff --git a/docs/code/gvawebcore.rst b/docs/code/gvawebcore.rst new file mode 100644 index 0000000..7fdd1b0 --- /dev/null +++ b/docs/code/gvawebcore.rst @@ -0,0 +1,11 @@ +:py:mod:`gvawebcore` +==================== + +.. automodule:: gvawebcore + + +:py:mod:`forms ` +---------------------------------- + +.. automodule:: gvawebcore.forms + :members: diff --git a/gnuviechadmin/gvawebcore/__init__.py b/gnuviechadmin/gvawebcore/__init__.py new file mode 100644 index 0000000..21b9749 --- /dev/null +++ b/gnuviechadmin/gvawebcore/__init__.py @@ -0,0 +1,5 @@ +""" +This is a collection of modules that can be used by multiple gnuviechadmin +apps. + +""" diff --git a/gnuviechadmin/gvawebcore/forms.py b/gnuviechadmin/gvawebcore/forms.py new file mode 100644 index 0000000..7a72d83 --- /dev/null +++ b/gnuviechadmin/gvawebcore/forms.py @@ -0,0 +1,43 @@ +""" +This module defines form classes that can be extended by other gnuviechadmin +apps' forms. + +""" +from __future__ import absolute_import, unicode_literals + +from django import forms +from django.utils.translation import ugettext_lazy as _ + + +PASSWORD_MISMATCH_ERROR = _("Passwords don't match") +""" +Error message for non matching passwords. +""" + + +class PasswordModelFormMixin(forms.Form): + """ + A form for entering a password in two password fields. The form checks + whether both fields contain the same string. + + """ + password1 = forms.CharField( + label=_('Password'), widget=forms.PasswordInput, + ) + password2 = forms.CharField( + label=_('Password (again)'), widget=forms.PasswordInput, + ) + + def clean_password2(self): + """ + Check that the two password entries match. + + :return: the validated password + :rtype: str or None + + """ + password1 = self.cleaned_data.get('password1') + password2 = self.cleaned_data.get('password2') + if password1 and password2 and password1 != password2: + raise forms.ValidationError(PASSWORD_MISMATCH_ERROR) + return password2 diff --git a/gnuviechadmin/gvawebcore/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/gvawebcore/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..e460e21 --- /dev/null +++ b/gnuviechadmin/gvawebcore/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,32 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: gvawebcore\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-01-25 11:49+0100\n" +"PO-Revision-Date: 2015-01-25 11:49+0100\n" +"Last-Translator: Jan Dittberner \n" +"Language-Team: Jan Dittberner \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 1.6.10\n" +"X-Poedit-SourceCharset: UTF-8\n" + +#: forms.py:12 +msgid "Passwords don't match" +msgstr "Passwörter stimmen nicht überein" + +#: forms.py:25 +msgid "Password" +msgstr "Passwort: " + +#: forms.py:28 +msgid "Password (again)" +msgstr "Passwortwiederholung" From 2b989799abd1073a738432007ff6864351aed845 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:02:31 +0100 Subject: [PATCH 2/6] refactor osusers password forms - use PasswordModelFormMixin from gvawebcore instead of own implementation in ChangeOsUserPasswordForm - change import for PASSWORD_MISMATCH_ERROR --- gnuviechadmin/osusers/admin.py | 2 +- gnuviechadmin/osusers/forms.py | 32 +++----------------------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/gnuviechadmin/osusers/admin.py b/gnuviechadmin/osusers/admin.py index 7d757be..6fec6e7 100644 --- a/gnuviechadmin/osusers/admin.py +++ b/gnuviechadmin/osusers/admin.py @@ -6,7 +6,7 @@ from django import forms from django.utils.translation import ugettext as _ from django.contrib import admin -from .forms import ( +from gvawebcore.forms import ( PASSWORD_MISMATCH_ERROR ) from .models import ( diff --git a/gnuviechadmin/osusers/forms.py b/gnuviechadmin/osusers/forms.py index 1ed1c82..73faa02 100644 --- a/gnuviechadmin/osusers/forms.py +++ b/gnuviechadmin/osusers/forms.py @@ -11,28 +11,16 @@ from django.utils.translation import ugettext_lazy as _ from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit +from gvawebcore.forms import PasswordModelFormMixin + from .models import User -PASSWORD_MISMATCH_ERROR = _("Passwords don't match") -""" -Error message for non matching passwords. -""" - -class ChangeOsUserPasswordForm(forms.ModelForm): +class ChangeOsUserPasswordForm(PasswordModelFormMixin, forms.ModelForm): """ A form for setting an OS user's password. """ - password1 = forms.CharField( - label=_('Password'), widget=forms.PasswordInput, - required=False, - ) - password2 = forms.CharField( - label=_('Password (again)'), widget=forms.PasswordInput, - required=False, - ) - class Meta: model = User fields = [] @@ -44,20 +32,6 @@ class ChangeOsUserPasswordForm(forms.ModelForm): 'set_osuser_password', kwargs={'slug': self.instance.username}) self.helper.add_input(Submit('submit', _('Set password'))) - def clean_password2(self): - """ - Check that the two password entries match. - - :return: the validated password - :rtype: str or None - - """ - password1 = self.cleaned_data.get('password1') - password2 = self.cleaned_data.get('password2') - if password1 and password2 and password1 != password2: - raise forms.ValidationError(PASSWORD_MISMATCH_ERROR) - return password2 - def save(self, commit=True): """ Save the provided password in hashed format. From 6cb61ea105ca721bc0ae12e21366ac7b07aa8448 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:08:30 +0100 Subject: [PATCH 3/6] add changelog entry for refactoring --- docs/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4b2668d..21e995d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,7 @@ Changelog ========= +* :support:`-` move common form code to new module gvawebcore.forms * :feature:`-` make it possible to assign domains to a customer * :feature:`-` add hosting packages list for staff users * :feature:`-` allow creation of new hosting packages for staff users without From 449af174ecea7e23ad7f4c6b2f0da62bd808f0dc Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:10:17 +0100 Subject: [PATCH 4/6] implement create_mailbox functionality - implement managemails.forms.CreateMailboxForm - implement managemails.views.CreateMailbox - add url pattern 'create_mailbox' to managemails.urls - add templates managemails/base.html and managemails/mailbox_create.html - add german translation - add generated code documentation --- docs/code/managemails.rst | 23 ++++++- gnuviechadmin/locale/de/LC_MESSAGES/django.po | 30 ++++++++- gnuviechadmin/managemails/forms.py | 48 ++++++++++++++ .../locale/de/LC_MESSAGES/django.po | 17 ++++- gnuviechadmin/managemails/urls.py | 18 +++++ gnuviechadmin/managemails/views.py | 65 +++++++++++++++++++ gnuviechadmin/templates/managemails/base.html | 1 + .../templates/managemails/mailbox_create.html | 34 ++++++++++ 8 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 gnuviechadmin/managemails/forms.py create mode 100644 gnuviechadmin/managemails/urls.py create mode 100644 gnuviechadmin/managemails/views.py create mode 100644 gnuviechadmin/templates/managemails/base.html create mode 100644 gnuviechadmin/templates/managemails/mailbox_create.html diff --git a/docs/code/managemails.rst b/docs/code/managemails.rst index 17c1763..42f060d 100644 --- a/docs/code/managemails.rst +++ b/docs/code/managemails.rst @@ -12,14 +12,35 @@ :py:mod:`apps ` ------------------------------------ +--------------------------------- .. automodule:: managemails.apps :members: +:py:mod:`forms ` +----------------------------------- + +.. automodule:: managemails.forms + :members: + + :py:mod:`models ` ------------------------------------- .. automodule:: managemails.models :members: + + +:py:mod:`urls ` +--------------------------------- + +.. automodule:: managemails.urls + :members: + + +:py:mod:`views ` +----------------------------------- + +.. automodule:: managemails.views + :members: diff --git a/gnuviechadmin/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/locale/de/LC_MESSAGES/django.po index b70640b..8056f97 100644 --- a/gnuviechadmin/locale/de/LC_MESSAGES/django.po +++ b/gnuviechadmin/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: gnuviechadmin\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-25 00:46+0100\n" -"PO-Revision-Date: 2015-01-25 00:55+0100\n" +"POT-Creation-Date: 2015-01-25 12:04+0100\n" +"PO-Revision-Date: 2015-01-25 12:06+0100\n" "Last-Translator: Jan Dittberner \n" "Language-Team: Jan Dittberner \n" "Language: de\n" @@ -793,6 +793,27 @@ msgstr "Diesem Hostingpaket sind noch keine Datenbanken zugeordnet." msgid "Add database" msgstr "Datenbank hinzufügen" +#: templates/managemails/mailbox_create.html:6 +#: templates/managemails/mailbox_create.html:15 +#, python-format +msgid "Add Mailbox to Hosting Package %(package)s" +msgstr "Postfach zum Hostingpaket %(package)s hinzufügen" + +#: templates/managemails/mailbox_create.html:8 +#: templates/managemails/mailbox_create.html:17 +#, python-format +msgid "Add Mailbox to Hosting Package %(package)s of Customer %(full_name)s" +msgstr "" +"Postfach zum Hostingpaket %(package)s des Kunden %(full_name)s hinzufügen" + +#: templates/managemails/mailbox_create.html:23 +msgid "Please specify the password for your new mailbox." +msgstr "Bitte geben Sie das Passwort für Ihr neues Postfach ein." + +#: templates/managemails/mailbox_create.html:23 +msgid "Please specify the password for the new mailbox." +msgstr "Bitte geben Sie das Passwort für das neue Postfach ein." + #: templates/osusers/user_setpassword.html:5 #: templates/osusers/user_setpassword.html:13 #, python-format @@ -897,5 +918,10 @@ msgstr "" "%(site_name)s zu nutzen. Als letzten Schritt füllen Sie bitte folgendes " "Formular aus:" +#, fuzzy +#~| msgid "Password Reset" +#~ msgid "Password (again)" +#~ msgstr "Passwort zurücksetzen" + #~ msgid "My Profile" #~ msgstr "Mein Profil" diff --git a/gnuviechadmin/managemails/forms.py b/gnuviechadmin/managemails/forms.py new file mode 100644 index 0000000..00c309f --- /dev/null +++ b/gnuviechadmin/managemails/forms.py @@ -0,0 +1,48 @@ +""" +This module defines form classes for mailbox and mail address editing. + +""" +from __future__ import absolute_import, unicode_literals + +from django import forms +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext as _ + +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Submit + +from .models import Mailbox +from gvawebcore.forms import PasswordModelFormMixin + + +class CreateMailboxForm(PasswordModelFormMixin, forms.ModelForm): + """ + This form is used to create new Mailbox instances. + + """ + class Meta: + model = Mailbox + fields = [] + + def __init__(self, *args, **kwargs): + self.hosting_package = kwargs.pop('hostingpackage') + super(CreateMailboxForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_action = reverse( + 'create_mailbox', kwargs={'package': self.hosting_package.id}) + self.helper.add_input(Submit('submit', _('Create mailbox'))) + + def save(self, commit=True): + """ + Set the new mailbox's password and osuser. + + :param boolean commit: whether to save the created mailbox + :return: mailbox instance + :rtype: :py:class:`managemails.models.Mailbox` + + """ + osuser = self.hosting_package.osuser + self.instance.osuser = osuser + self.instance.username = Mailbox.objects.get_next_mailbox_name(osuser) + self.instance.set_password(self.cleaned_data['password1']) + return super(CreateMailboxForm, self).save(commit=commit) diff --git a/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po index 52f2d8f..818ecd3 100644 --- a/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po +++ b/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: managemails\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-25 00:46+0100\n" -"PO-Revision-Date: 2015-01-25 00:48+0100\n" +"POT-Creation-Date: 2015-01-25 12:04+0100\n" +"PO-Revision-Date: 2015-01-25 12:07+0100\n" "Last-Translator: Jan Dittberner \n" "Language-Team: Jan Dittberner \n" "Language: de\n" @@ -47,6 +47,10 @@ msgstr "Deaktivieren" msgid "Mailboxes and Mail Addresses" msgstr "Postfächer und E-Mailadressen" +#: managemails/forms.py:33 +msgid "Create mailbox" +msgstr "Postfach anlegen" + #: managemails/models.py:79 msgid "Mailbox" msgstr "Postfach" @@ -70,3 +74,12 @@ msgstr "E-Mailadresse" #: managemails/models.py:142 msgid "mailbox" msgstr "Postfach" + +#: managemails/views.py:35 +msgid "You are not allowed to add more mailboxes to this hosting package" +msgstr "Sie können keine weiteren Postfächer zu diesem Hostingpaket hinzufügen" + +#: managemails/views.py:61 +#, python-brace-format +msgid "Mailbox {mailbox} created successfully." +msgstr "Postfach {mailbox} erfolgreich angelegt." diff --git a/gnuviechadmin/managemails/urls.py b/gnuviechadmin/managemails/urls.py new file mode 100644 index 0000000..6695cd2 --- /dev/null +++ b/gnuviechadmin/managemails/urls.py @@ -0,0 +1,18 @@ +""" +This module defines the URL patterns for mailbox and mail address related +views. + +""" +from __future__ import absolute_import, unicode_literals + +from django.conf.urls import patterns, url + +from .views import ( + CreateMailbox, +) + +urlpatterns = patterns( + '', + url(r'^(?P\d+)/mailbox/create$', + CreateMailbox.as_view(), name='create_mailbox'), +) diff --git a/gnuviechadmin/managemails/views.py b/gnuviechadmin/managemails/views.py new file mode 100644 index 0000000..c53cca8 --- /dev/null +++ b/gnuviechadmin/managemails/views.py @@ -0,0 +1,65 @@ +""" +This module defines views for mailbox and mail address handling. + +""" +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.contrib import messages + +from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin + +from hostingpackages.models import CustomerHostingPackage + +from .forms import CreateMailboxForm +from .models import Mailbox + + +class CreateMailbox(StaffOrSelfLoginRequiredMixin, CreateView): + """ + This view is used to setup new mailboxes for a customer hosting package. + + """ + model = Mailbox + context_object_name = 'mailbox' + template_name_suffix = '_create' + form_class = CreateMailboxForm + + def dispatch(self, request, *args, **kwargs): + resp = super(CreateMailbox, self).dispatch(request, *args, **kwargs) + 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['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() + return kwargs + + def form_valid(self, form): + mailbox = form.save() + messages.success( + self.request, + _('Mailbox {mailbox} created successfully.').format( + mailbox=mailbox.username + ) + ) + return redirect(self._get_hosting_package().get_absolute_url()) diff --git a/gnuviechadmin/templates/managemails/base.html b/gnuviechadmin/templates/managemails/base.html new file mode 100644 index 0000000..94d9808 --- /dev/null +++ b/gnuviechadmin/templates/managemails/base.html @@ -0,0 +1 @@ +{% extends "base.html" %} diff --git a/gnuviechadmin/templates/managemails/mailbox_create.html b/gnuviechadmin/templates/managemails/mailbox_create.html new file mode 100644 index 0000000..7446d6c --- /dev/null +++ b/gnuviechadmin/templates/managemails/mailbox_create.html @@ -0,0 +1,34 @@ +{% extends "managemails/base.html" %} +{% load i18n crispy_forms_tags %} +{% block title %}{{ block.user }} - {% spaceless %} +{% with full_name=customer.get_full_name package=hostingpackage.name %} +{% if customer == user %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }}{% endblocktrans %} +{% else %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }} of Customer {{ full_name }}{% endblocktrans %} +{% endif %} +{% endwith %} +{% endspaceless %}{% endblock title %} +{% block page_title %}{% spaceless %} +{% with full_name=customer.get_full_name package=hostingpackage.name %} +{% if customer == user %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }}{% endblocktrans %} +{% else %} +{% blocktrans %}Add Mailbox to Hosting Package {{ package }} of Customer {{ full_name }}{% endblocktrans %} +{% endif %} +{% endwith %} +{% endspaceless %}{% endblock page_title %} + +{% block content %} +

{% if customer == user %}{% trans "Please specify the password for your new mailbox." %}{% else %}{% trans "Please specify the password for the new mailbox." %}{% endif %}

+{% crispy form %} +{% endblock content %} + +{% block extra_js %} + +{% endblock extra_js %} From d1119331d89441d0a0a219d9ba773fc02d6f27bd Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:16:18 +0100 Subject: [PATCH 5/6] enable mailbox creation - add managemails.urls to gnuviechadmin.urls - add link to create_mailbox to customerhostingpackage_detail.html template - document feature in changelog --- docs/changelog.rst | 1 + gnuviechadmin/gnuviechadmin/urls.py | 1 + .../hostingpackages/customerhostingpackage_detail.html | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 21e995d..c35b573 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,7 @@ Changelog ========= +* :feature:`-` implement creation of new mailboxes for hosting packages * :support:`-` move common form code to new module gvawebcore.forms * :feature:`-` make it possible to assign domains to a customer * :feature:`-` add hosting packages list for staff users diff --git a/gnuviechadmin/gnuviechadmin/urls.py b/gnuviechadmin/gnuviechadmin/urls.py index ebc4157..d8f621d 100644 --- a/gnuviechadmin/gnuviechadmin/urls.py +++ b/gnuviechadmin/gnuviechadmin/urls.py @@ -12,6 +12,7 @@ urlpatterns = patterns( url(r'^accounts/', include('allauth.urls')), url(r'^domains/', include('domains.urls')), url(r'^hosting/', include('hostingpackages.urls')), + url(r'^mail/', include('managemails.urls')), url(r'^osuser/', include('osusers.urls')), url(r'^admin/', include(admin.site.urls)), ) diff --git a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html index 43f0e2d..338622c 100644 --- a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html +++ b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html @@ -140,7 +140,7 @@

{% trans "There are no mailboxes assigned to this hosting package yet." %}

{% endif %} {% if hostingpackage.may_add_mailbox %} -

{% trans "Add mailbox" %}

+

{% trans "Add mailbox" %}

{% endif %} From 2e4efe78395d5fd8fc18cbcd6df377f64e0e5b6d Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 25 Jan 2015 12:49:31 +0100 Subject: [PATCH 6/6] 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 --- docs/changelog.rst | 1 + gnuviechadmin/locale/de/LC_MESSAGES/django.po | 24 +++++- gnuviechadmin/managemails/forms.py | 33 ++++++++ .../locale/de/LC_MESSAGES/django.po | 18 +++- gnuviechadmin/managemails/urls.py | 3 + gnuviechadmin/managemails/views.py | 84 +++++++++++++++---- .../customerhostingpackage_detail.html | 2 +- .../managemails/mailbox_setpassword.html | 34 ++++++++ 8 files changed, 178 insertions(+), 21 deletions(-) create mode 100644 gnuviechadmin/templates/managemails/mailbox_setpassword.html diff --git a/docs/changelog.rst b/docs/changelog.rst index c35b573..e3fca35 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,7 @@ Changelog ========= +* :feature:`-` implement password change functionality for mailboxes * :feature:`-` implement creation of new mailboxes for hosting packages * :support:`-` move common form code to new module gvawebcore.forms * :feature:`-` make it possible to assign domains to a customer diff --git a/gnuviechadmin/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/locale/de/LC_MESSAGES/django.po index 8056f97..d9a7e5a 100644 --- a/gnuviechadmin/locale/de/LC_MESSAGES/django.po +++ b/gnuviechadmin/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: gnuviechadmin\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-25 12:04+0100\n" -"PO-Revision-Date: 2015-01-25 12:06+0100\n" +"POT-Creation-Date: 2015-01-25 12:46+0100\n" +"PO-Revision-Date: 2015-01-25 12:49+0100\n" "Last-Translator: Jan Dittberner \n" "Language-Team: Jan Dittberner \n" "Language: de\n" @@ -814,6 +814,26 @@ msgstr "Bitte geben Sie das Passwort für Ihr neues Postfach ein." msgid "Please specify the password for the new mailbox." msgstr "Bitte geben Sie das Passwort für das neue Postfach ein." +#: templates/managemails/mailbox_setpassword.html:6 +#: templates/managemails/mailbox_setpassword.html:15 +#, python-format +msgid "Set Password for Mailbox %(mailbox)s" +msgstr "Passwort für Postfach %(mailbox)s setzen" + +#: templates/managemails/mailbox_setpassword.html:8 +#: templates/managemails/mailbox_setpassword.html:17 +#, python-format +msgid "Set Password for Mailbox %(mailbox)s of Customer %(full_name)s" +msgstr "Passwort für Postfach %(mailbox)s des Kunden %(full_name)s setzen" + +#: templates/managemails/mailbox_setpassword.html:23 +msgid "Please specify the new password for your mailbox." +msgstr "Bitte geben Sie das neue Passwort für Ihr Postfach ein." + +#: templates/managemails/mailbox_setpassword.html:23 +msgid "Please specify the new password for the mailbox." +msgstr "Bitte geben Sie das neue Passwort für das Postfach ein." + #: templates/osusers/user_setpassword.html:5 #: templates/osusers/user_setpassword.html:13 #, python-format diff --git a/gnuviechadmin/managemails/forms.py b/gnuviechadmin/managemails/forms.py index 00c309f..04829f8 100644 --- a/gnuviechadmin/managemails/forms.py +++ b/gnuviechadmin/managemails/forms.py @@ -46,3 +46,36 @@ class CreateMailboxForm(PasswordModelFormMixin, forms.ModelForm): self.instance.username = Mailbox.objects.get_next_mailbox_name(osuser) self.instance.set_password(self.cleaned_data['password1']) return super(CreateMailboxForm, self).save(commit=commit) + + +class ChangeMailboxPasswordForm(PasswordModelFormMixin, forms.ModelForm): + """ + This form is used to set a new password for an existing mailbox. + + """ + class Meta: + model = Mailbox + fields = [] + + def __init__(self, *args, **kwargs): + self.hosting_package = kwargs.pop('hostingpackage') + super(ChangeMailboxPasswordForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_action = reverse( + 'change_mailbox_password', kwargs={ + 'package': self.hosting_package.id, + 'slug': self.instance.username, + }) + self.helper.add_input(Submit('submit', _('Set password'))) + + def save(self, commit=True): + """ + Set the mailbox password. + + :param boolean commit: whether to save the mailbox instance + :return: mailbox instance + :rtype: :py:class:`managemails.models.Mailbox` + + """ + self.instance.set_password(self.cleaned_data['password1']) + return super(ChangeMailboxPasswordForm, self).save(commit=commit) diff --git a/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po b/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po index 818ecd3..449ad57 100644 --- a/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po +++ b/gnuviechadmin/managemails/locale/de/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: managemails\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-01-25 12:04+0100\n" -"PO-Revision-Date: 2015-01-25 12:07+0100\n" +"POT-Creation-Date: 2015-01-25 12:46+0100\n" +"PO-Revision-Date: 2015-01-25 12:47+0100\n" "Last-Translator: Jan Dittberner \n" "Language-Team: Jan Dittberner \n" "Language: de\n" @@ -51,6 +51,10 @@ msgstr "Postfächer und E-Mailadressen" msgid "Create mailbox" msgstr "Postfach anlegen" +#: managemails/forms.py:69 +msgid "Set password" +msgstr "Passwort setzen" + #: managemails/models.py:79 msgid "Mailbox" msgstr "Postfach" @@ -75,11 +79,17 @@ msgstr "E-Mailadresse" msgid "mailbox" msgstr "Postfach" -#: managemails/views.py:35 +#: managemails/views.py:63 msgid "You are not allowed to add more mailboxes to this hosting package" msgstr "Sie können keine weiteren Postfächer zu diesem Hostingpaket hinzufügen" -#: managemails/views.py:61 +#: managemails/views.py:82 #, python-brace-format msgid "Mailbox {mailbox} created successfully." msgstr "Postfach {mailbox} erfolgreich angelegt." + +#: managemails/views.py:117 +#, python-brace-format +msgid "Successfully set new password for mailbox {mailbox}." +msgstr "" +"Für das Postfach {mailbox} wurde erfolgreich ein neues Passwort gesetzt." diff --git a/gnuviechadmin/managemails/urls.py b/gnuviechadmin/managemails/urls.py index 6695cd2..5e942d2 100644 --- a/gnuviechadmin/managemails/urls.py +++ b/gnuviechadmin/managemails/urls.py @@ -8,6 +8,7 @@ from __future__ import absolute_import, unicode_literals from django.conf.urls import patterns, url from .views import ( + ChangeMailboxPassword, CreateMailbox, ) @@ -15,4 +16,6 @@ urlpatterns = patterns( '', url(r'^(?P\d+)/mailbox/create$', CreateMailbox.as_view(), name='create_mailbox'), + url(r'^(?P\d+)/mailbox/(?P[\w0-9]+)/setpassword$', + ChangeMailboxPassword.as_view(), name='change_mailbox_password'), ) diff --git a/gnuviechadmin/managemails/views.py b/gnuviechadmin/managemails/views.py index c53cca8..837edd4 100644 --- a/gnuviechadmin/managemails/views.py +++ b/gnuviechadmin/managemails/views.py @@ -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()) diff --git a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html index 338622c..25c2e3f 100644 --- a/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html +++ b/gnuviechadmin/templates/hostingpackages/customerhostingpackage_detail.html @@ -131,7 +131,7 @@ {{ mailbox.mailaddresses|join:", " }} {% if mailbox.active %}{% trans "Active" %}{% else %}{% trans "inactive" %}{% endif %} - {% trans "Set mailbox password" %} + {% trans "Set mailbox password" %} {% endfor %} diff --git a/gnuviechadmin/templates/managemails/mailbox_setpassword.html b/gnuviechadmin/templates/managemails/mailbox_setpassword.html new file mode 100644 index 0000000..10829b5 --- /dev/null +++ b/gnuviechadmin/templates/managemails/mailbox_setpassword.html @@ -0,0 +1,34 @@ +{% extends "managemails/base.html" %} +{% load i18n crispy_forms_tags %} +{% block title %}{{ block.user }} - {% spaceless %} +{% with full_name=customer.get_full_name mailbox=mailbox.username %} +{% if customer == user %} +{% blocktrans %}Set Password for Mailbox {{ mailbox }}{% endblocktrans %} +{% else %} +{% blocktrans %}Set Password for Mailbox {{ mailbox }} of Customer {{ full_name }}{% endblocktrans %} +{% endif %} +{% endwith %} +{% endspaceless %}{% endblock title %} +{% block page_title %}{% spaceless %} +{% with full_name=customer.get_full_name mailbox=mailbox.username %} +{% if customer == user %} +{% blocktrans %}Set Password for Mailbox {{ mailbox }}{% endblocktrans %} +{% else %} +{% blocktrans %}Set Password for Mailbox {{ mailbox }} of Customer {{ full_name }}{% endblocktrans %} +{% endif %} +{% endwith %} +{% endspaceless %}{% endblock page_title %} + +{% block content %} +

{% if customer == user %}{% trans "Please specify the new password for your mailbox." %}{% else %}{% trans "Please specify the new password for the mailbox." %}{% endif %}

+{% crispy form %} +{% endblock content %} + +{% block extra_js %} + +{% endblock extra_js %}