add view osusers.views.AddSshPublicKey
- implement new form osusers.forms.AddSshPublicKeyForm - move message texts from osusers.admin to osusers.forms - add new view osusers.views.AddSshPublicKey - add new URL patter 'add_ssh_key' to osusers.urls - add new template osusers/sshpublickey_create.html - link from hosting package detail template to 'add_ssh_key' - add changelog entry for new feature
This commit is contained in:
parent
79b460c4a6
commit
0c7bb79109
7 changed files with 159 additions and 9 deletions
|
@ -5,14 +5,24 @@ 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.views.generic import (
|
||||
UpdateView,
|
||||
CreateView,
|
||||
)
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.contrib import messages
|
||||
|
||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||
from gvawebcore.views import HostingPackageAndCustomerMixin
|
||||
|
||||
from .forms import ChangeOsUserPasswordForm
|
||||
from .models import User
|
||||
from .forms import (
|
||||
AddSshPublicKeyForm,
|
||||
ChangeOsUserPasswordForm,
|
||||
)
|
||||
from .models import (
|
||||
SshPublicKey,
|
||||
User,
|
||||
)
|
||||
|
||||
|
||||
class SetOsUserPassword(StaffOrSelfLoginRequiredMixin, UpdateView):
|
||||
|
@ -43,3 +53,39 @@ class SetOsUserPassword(StaffOrSelfLoginRequiredMixin, UpdateView):
|
|||
username=osuser.username
|
||||
))
|
||||
return redirect(osuser.customerhostingpackage)
|
||||
|
||||
|
||||
class AddSshPublicKey(
|
||||
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, CreateView
|
||||
):
|
||||
"""
|
||||
This view is used to add an SSH key for an existing hosting account's
|
||||
operating system user.
|
||||
|
||||
"""
|
||||
model = SshPublicKey
|
||||
context_object_name = 'key'
|
||||
template_name_suffix = '_create'
|
||||
form_class = AddSshPublicKeyForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddSshPublicKey, self).get_form_kwargs()
|
||||
kwargs['hostingpackage'] = self.get_hosting_package()
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddSshPublicKey, self).get_context_data(**kwargs)
|
||||
context.update({
|
||||
'customer': self.get_customer_object(),
|
||||
'osuser': self.get_hosting_package().osuser.username,
|
||||
})
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
key = form.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Successfully added new {algorithm} SSH public key').format(
|
||||
algorithm=key.algorithm)
|
||||
)
|
||||
return redirect(self.get_hosting_package())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue