implement database user password change

- implement userdbs.forms.ChangeDatabaseUserPasswordForm
- implement userdbs.views.ChangeDatabaseUserPassword
- add URL pattern 'change_dbuser_password' to userdbs.urls
- add template userdbs/databaseuser_setpassword.html
- link from hostingpackage detail template to 'change_dbuser_password'
- add changelog entry
This commit is contained in:
Jan Dittberner 2015-01-26 12:39:42 +01:00
parent 486c07d27d
commit fd6449dff1
6 changed files with 100 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from django.shortcuts import redirect
from django.utils.translation import ugettext as _
from django.views.generic.edit import (
CreateView,
UpdateView,
)
from django.contrib import messages
@ -16,9 +17,11 @@ from gvawebcore.views import HostingPackageAndCustomerMixin
from .forms import (
AddUserDatabaseForm,
ChangeDatabaseUserPasswordForm,
)
from .models import (
DB_TYPES,
DatabaseUser,
UserDatabase,
)
@ -62,3 +65,38 @@ class AddUserDatabase(
dbname=userdatabase.db_name, db_user=userdatabase.db_user)
)
return redirect(self.get_hosting_package())
class ChangeDatabaseUserPassword(
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, UpdateView
):
"""
This view is used to change a database user's password.
"""
model = DatabaseUser
slug_field = 'name'
context_object_name = 'dbuser'
template_name_suffix = '_setpassword'
form_class = ChangeDatabaseUserPasswordForm
def get_form_kwargs(self):
kwargs = super(ChangeDatabaseUserPassword, self).get_form_kwargs()
kwargs['hostingpackage'] = self.get_hosting_package()
return kwargs
def get_context_data(self, **kwargs):
context = super(ChangeDatabaseUserPassword, self).get_context_data(
**kwargs)
context['hostingpackage'] = self.get_hosting_package()
context['customer'] = self.get_customer_object()
return context
def form_valid(self, form):
db_user = form.save()
messages.success(
self.request,
_('Successfully changed password of database user {dbuser}'
).format(dbuser=db_user.name)
)
return redirect(self.get_hosting_package())