mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Remove POSIX users.
This commit is contained in:
1 parent
d672e24ac4
commit
2adf14b8b7
14 files changed
+15
-327
No files matched your search
@@ -28,16 +28,9 @@ from plinth.errors import ActionError
|
||||
class CreateUserForm(UserCreationForm):
|
||||
"""Custom user create form.
|
||||
|
||||
Include options to also create POSIX and LDAP user.
|
||||
Include option to also create LDAP user.
|
||||
"""
|
||||
|
||||
add_posix_user = forms.BooleanField(
|
||||
label=_('Also create a POSIX system user'),
|
||||
required=False,
|
||||
help_text=_('This will allow the new user to log in to the system '
|
||||
'through SSH. The new user will also have administrative '
|
||||
'privileges (sudo).'))
|
||||
|
||||
add_ldap_user = forms.BooleanField(
|
||||
label=_('Also create an LDAP user'),
|
||||
required=False,
|
||||
@@ -50,19 +43,10 @@ class CreateUserForm(UserCreationForm):
|
||||
super(CreateUserForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Save the user model and create POSIX user if required."""
|
||||
"""Save the user model and create LDAP user if required."""
|
||||
user = super(CreateUserForm, self).save(commit)
|
||||
|
||||
if commit:
|
||||
if self.cleaned_data['add_posix_user']:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'create-user',
|
||||
[user.get_username(), self.cleaned_data['password1']])
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Creating POSIX system user failed.'))
|
||||
|
||||
if self.cleaned_data['add_ldap_user']:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
@@ -76,7 +60,7 @@ class CreateUserForm(UserCreationForm):
|
||||
|
||||
|
||||
class UserUpdateForm(forms.ModelForm):
|
||||
"""When user is enabled/disabled, also enables/disables the POSIX user."""
|
||||
"""When user info is changed, also updates LDAP user."""
|
||||
|
||||
class Meta:
|
||||
"""Metadata to control automatic form building."""
|
||||
@@ -93,29 +77,11 @@ class UserUpdateForm(forms.ModelForm):
|
||||
super(UserUpdateForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Enable/disable POSIX user after saving user model."""
|
||||
"""Update LDAP user name after saving user model."""
|
||||
user = super(UserUpdateForm, self).save(commit)
|
||||
|
||||
if commit:
|
||||
try:
|
||||
if user.is_active:
|
||||
actions.superuser_run('enable-user', [user.get_username()])
|
||||
else:
|
||||
actions.superuser_run('disable-user',
|
||||
[user.get_username()])
|
||||
except ActionError:
|
||||
messages.error(
|
||||
self.request,
|
||||
_('Setting active status for POSIX system user failed.'))
|
||||
|
||||
if self.username != user.get_username():
|
||||
try:
|
||||
actions.superuser_run('rename-user',
|
||||
[self.username, user.get_username()])
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('Renaming POSIX system user failed.'))
|
||||
|
||||
try:
|
||||
actions.superuser_run('rename-ldap-user',
|
||||
[self.username, user.get_username()])
|
||||
@@ -127,7 +93,7 @@ class UserUpdateForm(forms.ModelForm):
|
||||
|
||||
|
||||
class UserChangePasswordForm(SetPasswordForm):
|
||||
"""Custom form that also updates password for POSIX users."""
|
||||
"""Custom form that also updates password for LDAP users."""
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
"""Initialize the form with extra request argument."""
|
||||
@@ -135,18 +101,9 @@ class UserChangePasswordForm(SetPasswordForm):
|
||||
super(UserChangePasswordForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Save the user model and change POSIX password as well."""
|
||||
"""Save the user model and change LDAP password as well."""
|
||||
user = super(UserChangePasswordForm, self).save(commit)
|
||||
if commit:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'change-user-password',
|
||||
[user.get_username(), self.cleaned_data['new_password1']])
|
||||
except ActionError:
|
||||
messages.error(
|
||||
self.request,
|
||||
_('Changing POSIX system user password failed.'))
|
||||
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'change-ldap-user-password',
|
||||
|
||||
Reference in new issue
Block a user