users: Add field to set user's SSH key.

This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2016-01-30 15:30:32 +05:30
1 parent 81b3f959fe
commit ad7d6db968
3 files changed
+126 -1

No files matched your search

+14 -1
View File
@@ -88,10 +88,18 @@ class CreateUserForm(UserCreationForm):
class UserUpdateForm(forms.ModelForm):
"""When user info is changed, also updates LDAP user."""
ssh_key = forms.CharField(
label=ugettext_lazy('SSH Key'),
required=False,
widget=forms.Textarea,
help_text=\
ugettext_lazy('Setting an SSH public key will allow this user to log '
'in to the system without having to send a password '
'over the network.'))
class Meta:
"""Metadata to control automatic form building."""
fields = ('username', 'groups', 'is_active')
fields = ('username', 'groups', 'ssh_key', 'is_active')
model = User
widgets = {
'groups': forms.widgets.CheckboxSelectMultiple(),
@@ -148,6 +156,11 @@ class UserUpdateForm(forms.ModelForm):
messages.error(self.request,
_('Failed to add user to group.'))
actions.superuser_run(
'ssh', ['set-key',
'--username', user.get_username(),
'--key', self.cleaned_data['ssh_key'].strip()])
return user
+6
View File
@@ -85,6 +85,12 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
kwargs['username'] = self.object.username
return kwargs
def get_initial(self):
initial = super(UserUpdate, self).get_initial()
initial['ssh_key'] = actions.superuser_run(
'ssh', ['get-key', '--username', self.object.username]).strip()
return initial
def get_success_url(self):
"""Return the URL to redirect to in case of successful updation."""
return reverse('users:edit', kwargs={'slug': self.object.username})