When enabling/disabling Django user, also enable/disable the corresponding POSIX user.

This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2015-01-20 12:37:04 +05:30
1 parent eeced1c213
commit 45b5ce8de9
4 files changed
+75 -11

No files matched your search

+21
View File
@@ -16,6 +16,7 @@
#
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm, SetPasswordForm
from gettext import gettext as _
@@ -41,6 +42,26 @@ class CreateUserForm(UserCreationForm):
return user
class UserUpdateForm(forms.ModelForm):
"""When user is enabled/disabled, also enables/disables the POSIX user."""
class Meta:
fields = ('username', 'groups', 'is_active')
model = User
widgets = {
'groups': forms.widgets.CheckboxSelectMultiple(),
}
def save(self, commit=True):
user = super(UserUpdateForm, self).save(commit)
if commit:
if user.is_active:
actions.superuser_run('enable-user', [user.username])
else:
actions.superuser_run('disable-user', [user.username])
return user
class UserChangePasswordForm(SetPasswordForm):
"""Custom form that also updates password for POSIX users."""
+2 -11
View File
@@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django import forms
from django.contrib import messages
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.models import User
@@ -26,7 +25,7 @@ from django.views.generic.edit import (CreateView, DeleteView, UpdateView,
from django.views.generic import ListView
from gettext import gettext as _
from .forms import CreateUserForm, UserChangePasswordForm
from .forms import CreateUserForm, UserUpdateForm, UserChangePasswordForm
subsubmenu = [{'url': reverse_lazy('users:index'),
@@ -65,19 +64,11 @@ class UserList(ContextMixin, ListView):
class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
"""View to update a user's details."""
template_name = 'users_update.html'
fields = ('username', 'groups', 'is_active')
model = User
form_class = UserUpdateForm
slug_field = 'username'
success_message = _('User %(username)s updated.')
title = _('Edit User')
widgets = {
'groups': forms.widgets.CheckboxSelectMultiple(),
}
def get_form_class(self):
"""Return a form class generated from user model."""
return forms.models.modelform_factory(self.model, fields=self.fields,
widgets=self.widgets)
def get_success_url(self):
"""Return the URL to redirect to in case of successful updation."""