Remove POSIX users.

This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2015-07-13 19:50:58 +05:30
1 parent d672e24ac4
commit 2adf14b8b7
14 files changed
+15 -327

No files matched your search

+6 -49
View File
@@ -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',
@@ -31,12 +31,6 @@
{{ form|bootstrap }}
{% if is_posix_user %}
<p>This user is also a POSIX system user and password for POSIX system
user will also be updated.
</p>
{% endif %}
{% if is_ldap_user %}
<p>This user is also an LDAP user and password for LDAP user will also
be updated.
@@ -24,12 +24,6 @@
<h3>Delete User <em>{{ object.username }}</em></h3>
{% if is_posix_user %}
<p>This user is also a POSIX system user. POSIX system user will also be
deleted.
</p>
{% endif %}
{% if is_ldap_user %}
<p>This user is also an LDAP user. LDAP user will also be deleted.</p>
{% endif %}
@@ -46,12 +46,6 @@
{{ form|bootstrap }}
{% if is_posix_user %}
<p>This user is also a POSIX system user and, if active, can log in to
the system through SSH.
</p>
{% endif %}
{% if is_ldap_user %}
<p>This user is also an LDAP user.</p>
{% endif %}
-12
View File
@@ -88,8 +88,6 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
def get_context_data(self, **kwargs):
"""Return the data to be used for rendering templates."""
context = super(UserUpdate, self).get_context_data(**kwargs)
output = actions.run('check-user-exists', [self.object.username])
context['is_posix_user'] = 'User exists' in output
output = actions.run('check-ldap-user-exists', [self.object.username])
context['is_ldap_user'] = 'User exists' in output
return context
@@ -114,8 +112,6 @@ class UserDelete(ContextMixin, DeleteView):
def get_context_data(self, **kwargs):
"""Return the data to be used for rendering templates."""
context = super(UserDelete, self).get_context_data(**kwargs)
output = actions.run('check-user-exists', [self.kwargs['slug']])
context['is_posix_user'] = 'User exists' in output
output = actions.run('check-ldap-user-exists', [self.kwargs['slug']])
context['is_ldap_user'] = 'User exists' in output
return context
@@ -131,12 +127,6 @@ class UserDelete(ContextMixin, DeleteView):
message = _('User %s deleted.') % self.kwargs['slug']
messages.success(self.request, message)
try:
actions.superuser_run('delete-user', [self.kwargs['slug']])
except ActionError:
messages.error(self.request,
_('Deleting POSIX system user failed.'))
try:
actions.superuser_run('delete-ldap-user', [self.kwargs['slug']])
except ActionError:
@@ -163,8 +153,6 @@ class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
def get_context_data(self, **kwargs):
"""Return the data to be used for rendering templates."""
context = super(UserChangePassword, self).get_context_data(**kwargs)
output = actions.run('check-user-exists', [self.kwargs['slug']])
context['is_posix_user'] = 'User exists' in output
output = actions.run('check-ldap-user-exists', [self.kwargs['slug']])
context['is_ldap_user'] = 'User exists' in output
return context