add list, delete and edit comment of SSH public keys

- add sshkeys to hostingpackage detail view context
- implement new osusers.forms.EditSshPublicKeyCommentForm
- implement new views ListSshPublicKeys, DeleteSshPublicKey and
  EditSshPublicKeyComment
- add new URL patterns 'list_ssh_keys', 'edit_ssh_key_comment' and
  'delete_ssh_key'
- link from hosting package detail view to 'list_ssh_keys' when there are
  SSH keys assigned to the shown hosting package
- add new templates osusers/sshpublickey_list.html,
  osusers/sshpublickey_confirm_delete.html and
  osusers/sshpublickey_edit_comment
- add operating system user output to template
  osusers/sshpublickey_create.html
- add changelog entry
This commit is contained in:
Jan Dittberner 2015-02-01 01:55:09 +01:00
parent 0c7bb79109
commit 832a611602
10 changed files with 222 additions and 5 deletions

View file

@ -110,3 +110,25 @@ class AddSshPublicKeyForm(forms.ModelForm):
self.instance.data = keydata
self.instance.comment = comment
return super(AddSshPublicKeyForm, self).save(commit)
class EditSshPublicKeyCommentForm(forms.ModelForm):
"""
A form for editing :py:class:`SSH public key
<osusers.models.SshPublicKey>` comment fields.
"""
class Meta:
model = SshPublicKey
fields = ['comment']
def __init__(self, *args, **kwargs):
hosting_package = kwargs.pop('hostingpackage')
self.osuser = hosting_package.osuser
super(EditSshPublicKeyCommentForm, self).__init__(*args, **kwargs)
self.fields['comment'].widget = forms.TextInput()
self.helper = FormHelper()
self.helper.form_action = reverse(
'edit_ssh_key_comment',
kwargs={'package': hosting_package.id, 'pk': self.instance.id})
self.helper.add_input(Submit('submit', _('Change Comment')))

View file

@ -8,6 +8,9 @@ from django.conf.urls import patterns, url
from .views import (
AddSshPublicKey,
DeleteSshPublicKey,
EditSshPublicKeyComment,
ListSshPublicKeys,
SetOsUserPassword,
)
@ -16,6 +19,12 @@ urlpatterns = patterns(
'',
url(r'^(?P<slug>[\w0-9@.+-_]+)/setpassword$', SetOsUserPassword.as_view(),
name='set_osuser_password'),
url(r'^(?P<package>\d+)/add-ssh-key$', AddSshPublicKey.as_view(),
url(r'^(?P<package>\d+)/ssh-keys/$', ListSshPublicKeys.as_view(),
name='list_ssh_keys'),
url(r'^(?P<package>\d+)/ssh-keys/add$', AddSshPublicKey.as_view(),
name='add_ssh_key'),
url(r'^(?P<package>\d+)/ssh-keys/(?P<pk>\d+)/edit-comment$',
EditSshPublicKeyComment.as_view(), name='edit_ssh_key_comment'),
url(r'^(?P<package>\d+)/ssh-keys/(?P<pk>\d+)/delete$',
DeleteSshPublicKey.as_view(), name='delete_ssh_key'),
)

View file

@ -4,10 +4,13 @@ This module defines the views for gnuviechadmin operating system user handling.
"""
from __future__ import unicode_literals, absolute_import
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.views.generic import (
UpdateView,
CreateView,
DeleteView,
ListView,
UpdateView,
)
from django.utils.translation import ugettext as _
from django.contrib import messages
@ -18,6 +21,7 @@ from gvawebcore.views import HostingPackageAndCustomerMixin
from .forms import (
AddSshPublicKeyForm,
ChangeOsUserPasswordForm,
EditSshPublicKeyCommentForm,
)
from .models import (
SshPublicKey,
@ -89,3 +93,70 @@ class AddSshPublicKey(
algorithm=key.algorithm)
)
return redirect(self.get_hosting_package())
class ListSshPublicKeys(
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, ListView
):
model = SshPublicKey
context_object_name = 'keys'
def get_context_data(self, **kwargs):
context = super(ListSshPublicKeys, self).get_context_data(**kwargs)
context.update({
'hostingpackage': self.get_hosting_package(),
'customer': self.get_customer_object(),
'osuser': self.get_hosting_package().osuser.username,
})
return context
class DeleteSshPublicKey(
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, DeleteView
):
model = SshPublicKey
context_object_name = 'key'
def get_context_data(self, **kwargs):
context = super(DeleteSshPublicKey, self).get_context_data(**kwargs)
context.update({
'hostingpackage': self.get_hosting_package(),
'customer': self.get_customer_object(),
'osuser': self.get_hosting_package().osuser.username,
})
return context
def get_success_url(self):
return reverse(
'list_ssh_keys', kwargs={'package': self.get_hosting_package().id}
)
class EditSshPublicKeyComment(
HostingPackageAndCustomerMixin, StaffOrSelfLoginRequiredMixin, UpdateView
):
model = SshPublicKey
context_object_name = 'key'
fields = ['comment']
template_name_suffix = '_edit_comment'
form_class = EditSshPublicKeyCommentForm
def get_form_kwargs(self):
kwargs = super(EditSshPublicKeyComment, self).get_form_kwargs()
kwargs['hostingpackage'] = self.get_hosting_package()
return kwargs
def get_context_data(self, **kwargs):
context = super(EditSshPublicKeyComment, self).get_context_data(
**kwargs)
context.update({
'hostingpackage': self.get_hosting_package(),
'customer': self.get_customer_object(),
'osuser': self.get_hosting_package().osuser.username,
})
return context
def get_success_url(self):
return reverse(
'list_ssh_keys', kwargs={'package': self.get_hosting_package().id}
)