plug users and hosting packages together

- document new feature in changelog
- add autogenerated documentation for osusers.urls and osusers.views
- add osuser URLs to gnuviechadmin.urls
- implement get_absolute_url in hostingpackages.models.CustomerHostingPackage
- use set_ldap_user_password instead of create_ldap_user for existing OS users
  in osusers.models.User.set_password
- add URL pattern set_osuser_password in osusers.urls
- implement osusers.views.SetOsUserPassword to set the password of an existing
  operating system user
- link to hosting package detail view on user dashboard
- add template hostingpackages/customerhostingpackage_detail.html
- add template osusers/user_setpassword.html
This commit is contained in:
Jan Dittberner 2015-01-24 16:26:32 +01:00
parent 0d08d9876b
commit 150366a524
11 changed files with 181 additions and 6 deletions

View file

@ -29,6 +29,7 @@ from ldaptasks.tasks import (
delete_ldap_group,
delete_ldap_user,
remove_ldap_user_from_group,
set_ldap_user_password,
)
from fileservertasks.tasks import (
@ -245,15 +246,26 @@ class User(TimeStampedModel, models.Model):
"""
if hasattr(self, 'shadow'):
self.shadow.set_password(password)
success = set_ldap_user_password.delay(
self.username, password).get()
if success:
_LOGGER.info(
"successfully set LDAP password for %s", self.username)
else:
_LOGGER.error(
"setting the LDAP password for %s failed", self.username)
return success
else:
self.shadow = Shadow.objects.create_shadow(
user=self, password=password
)
dn = create_ldap_user.delay(
self.username, self.uid, self.group.gid, self.gecos,
self.homedir, self.shell, password
).get()
logging.info("set LDAP password for %s", dn)
dn = create_ldap_user.delay(
self.username, self.uid, self.group.gid, self.gecos,
self.homedir, self.shell, password
).get()
_LOGGER.info("set LDAP password for %s", dn)
return True
@transaction.atomic
def save(self, *args, **kwargs):

View file

@ -0,0 +1,16 @@
"""
This module defines the URL patterns for operating system user related views.
"""
from __future__ import absolute_import, unicode_literals
from django.conf.urls import patterns, url
from .views import SetOsUserPassword
urlpatterns = patterns(
'',
url(r'^(?P<slug>[\w0-9@.+-_]+)/setpassword$', SetOsUserPassword.as_view(),
name='set_osuser_password'),
)

View file

@ -0,0 +1,45 @@
"""
This module defines the views for gnuviechadmin operating system user handling.
"""
from __future__ import unicode_literals, absolute_import
from django.shortcuts import redirect
from django.views.generic import UpdateView
from django.utils.translation import ugettext as _
from django.contrib import messages
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
from .forms import ChangeOsUserPasswordForm
from .models import User
class SetOsUserPassword(StaffOrSelfLoginRequiredMixin, UpdateView):
"""
This view is used for setting a new operating system user password.
"""
model = User
slug_field = 'username'
template_name_suffix = '_setpassword'
context_object_name = 'osuser'
form_class = ChangeOsUserPasswordForm
def get_customer_object(self):
return self.get_object().customer
def get_context_data(self, *args, **kwargs):
context = super(SetOsUserPassword, self).get_context_data(
*args, **kwargs)
context['customer'] = self.get_customer_object()
return context
def form_valid(self, form):
osuser = form.save()
messages.success(
self.request,
_("New password for {username} has been set successfully.").format(
username=osuser.username
))
return redirect(osuser.customerhostingpackage)