Show if user is also a POSIX user in edit user form.

This commit is contained in:
James Valleroy 2015-01-07 20:02:42 -05:00 committed by Sunil Mohan Adapa
parent 45b5ce8de9
commit 2da8619248
3 changed files with 40 additions and 0 deletions

28
actions/check-user-exists Executable file
View File

@ -0,0 +1,28 @@
#!/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/>.
#
# Can be run as normal user.
username="$1"
getent passwd "$username" >/dev/null
if [ $? -eq 0 ]; then
echo "User exists"
else
echo "User does not exist"
fi

View File

@ -46,6 +46,11 @@
{{ form|bootstrap }}
{% if is_posix_user %}
<p>This user is also a POSIX user and (if active) can log in to the
system through SSH.</p>
{% endif %}
<input type="submit" class="btn btn-primary" value="Save Changes"/>
</form>

View File

@ -26,6 +26,7 @@ from django.views.generic import ListView
from gettext import gettext as _
from .forms import CreateUserForm, UserUpdateForm, UserChangePasswordForm
from plinth import actions
subsubmenu = [{'url': reverse_lazy('users:index'),
@ -70,6 +71,12 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
success_message = _('User %(username)s updated.')
title = _('Edit User')
def get_context_data(self, **kwargs):
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
return context
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})