mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
When enabling/disabling Django user, also enable/disable the corresponding POSIX user.
This commit is contained in:
parent
eeced1c213
commit
45b5ce8de9
26
actions/disable-user
Executable file
26
actions/disable-user
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Must be run as root.
|
||||||
|
|
||||||
|
username="$1"
|
||||||
|
|
||||||
|
usermod --expiredate 1 "$username"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed"
|
||||||
|
fi
|
||||||
26
actions/enable-user
Executable file
26
actions/enable-user
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Must be run as root.
|
||||||
|
|
||||||
|
username="$1"
|
||||||
|
|
||||||
|
usermod --expiredate "" "$username"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed"
|
||||||
|
fi
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.forms import UserCreationForm, SetPasswordForm
|
from django.contrib.auth.forms import UserCreationForm, SetPasswordForm
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
@ -41,6 +42,26 @@ class CreateUserForm(UserCreationForm):
|
|||||||
return user
|
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):
|
class UserChangePasswordForm(SetPasswordForm):
|
||||||
"""Custom form that also updates password for POSIX users."""
|
"""Custom form that also updates password for POSIX users."""
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import update_session_auth_hash
|
from django.contrib.auth import update_session_auth_hash
|
||||||
from django.contrib.auth.models import User
|
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 django.views.generic import ListView
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from .forms import CreateUserForm, UserChangePasswordForm
|
from .forms import CreateUserForm, UserUpdateForm, UserChangePasswordForm
|
||||||
|
|
||||||
|
|
||||||
subsubmenu = [{'url': reverse_lazy('users:index'),
|
subsubmenu = [{'url': reverse_lazy('users:index'),
|
||||||
@ -65,19 +64,11 @@ class UserList(ContextMixin, ListView):
|
|||||||
class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
|
class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
|
||||||
"""View to update a user's details."""
|
"""View to update a user's details."""
|
||||||
template_name = 'users_update.html'
|
template_name = 'users_update.html'
|
||||||
fields = ('username', 'groups', 'is_active')
|
|
||||||
model = User
|
model = User
|
||||||
|
form_class = UserUpdateForm
|
||||||
slug_field = 'username'
|
slug_field = 'username'
|
||||||
success_message = _('User %(username)s updated.')
|
success_message = _('User %(username)s updated.')
|
||||||
title = _('Edit User')
|
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):
|
def get_success_url(self):
|
||||||
"""Return the URL to redirect to in case of successful updation."""
|
"""Return the URL to redirect to in case of successful updation."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user