mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
users: Add field to set user's SSH key.
This commit is contained in:
1 parent
81b3f959fe
commit
ad7d6db968
3 files changed
+126
-1
No files matched your search
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
Reference in new issue
Block a user