From 219c3f4b06b92a461409bdbced6e0eb5520a88f0 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 27 May 2015 19:02:23 -0400 Subject: [PATCH] users: Show if user is also an LDAP user. --- actions/check-ldap-user-exists | 27 +++++++++++++++++++ .../modules/users/templates/users_update.html | 4 +++ plinth/modules/users/views.py | 2 ++ 3 files changed, 33 insertions(+) create mode 100755 actions/check-ldap-user-exists diff --git a/actions/check-ldap-user-exists b/actions/check-ldap-user-exists new file mode 100755 index 000000000..f747a4de2 --- /dev/null +++ b/actions/check-ldap-user-exists @@ -0,0 +1,27 @@ +#!/bin/bash +# +# 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 . +# + +username="$1" + +results=$(ldapsearch -x -D 'cn=admin,dc=thisbox' -w $(sudo cat /var/lib/plinth/ldap-admin) -b 'ou=users,dc=thisbox' -LLL "(uid=$username)" uid) + +if [ -z "$results" ]; then + echo "User does not exist" +else + echo "User exists" +fi diff --git a/plinth/modules/users/templates/users_update.html b/plinth/modules/users/templates/users_update.html index bf04b4e69..b1d0a0b2b 100644 --- a/plinth/modules/users/templates/users_update.html +++ b/plinth/modules/users/templates/users_update.html @@ -52,6 +52,10 @@

{% endif %} + {% if is_ldap_user %} +

This user is also an LDAP user.

+ {% endif %} + diff --git a/plinth/modules/users/views.py b/plinth/modules/users/views.py index 05d6a4f3d..edb8360c1 100644 --- a/plinth/modules/users/views.py +++ b/plinth/modules/users/views.py @@ -90,6 +90,8 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView): 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 def get_success_url(self):