mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
Change get-group-users to a simpler implementation
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
1a095564b0
commit
a50b40ee56
@ -86,10 +86,12 @@ def parse_arguments():
|
|||||||
subparser.add_argument('groupname',
|
subparser.add_argument('groupname',
|
||||||
help='LDAP group to remove the user from')
|
help='LDAP group to remove the user from')
|
||||||
|
|
||||||
help_get_admin_user = 'Get the list of all users in an LDAP group'
|
help_get_group_users = 'Get the list of all users in an LDAP group'
|
||||||
subparser = subparsers.add_parser('get-group-users', help=help_get_admin_user)
|
subparser = subparsers.add_parser('get-group-users',
|
||||||
subparser.add_argument('groupname', help='name of the LDAP group to get the '
|
help=help_get_group_users)
|
||||||
'list of users')
|
subparser.add_argument(
|
||||||
|
'groupname', help='name of the LDAP group to get the '
|
||||||
|
'list of users')
|
||||||
|
|
||||||
subparsers.required = True
|
subparsers.required = True
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
@ -351,13 +353,14 @@ def subcommand_remove_user_from_group(arguments):
|
|||||||
|
|
||||||
|
|
||||||
def subcommand_get_group_users(arguments):
|
def subcommand_get_group_users(arguments):
|
||||||
""" Get the list of admin users """
|
""" Get the list of users of an LDAP group."""
|
||||||
process = _run(['ldapgid', arguments.groupname], stdout=subprocess.PIPE)
|
process = _run(['ldapgid', '-P', arguments.groupname],
|
||||||
output = str(process.stdout).split()
|
stdout=subprocess.PIPE)
|
||||||
users_info = output[1].split('=')[1].strip('\\n').split(',')
|
output = process.stdout.decode()
|
||||||
for user_info in users_info:
|
users = output.rsplit(':')[-1]
|
||||||
user_name = user_info.split('(')[1].split(')')[0]
|
if users:
|
||||||
print(user_name)
|
for user in users.strip().split(','):
|
||||||
|
print(user)
|
||||||
|
|
||||||
|
|
||||||
def flush_cache():
|
def flush_cache():
|
||||||
|
|||||||
@ -111,9 +111,8 @@ def get_last_admin_user():
|
|||||||
""" Check if there is only one admin user
|
""" Check if there is only one admin user
|
||||||
if yes return its name else return None
|
if yes return its name else return None
|
||||||
"""
|
"""
|
||||||
admin_users = actions.superuser_run('users',
|
admin_users = actions.superuser_run(
|
||||||
['get-group-users','admin']
|
'users', ['get-group-users', 'admin']).strip().split('\n')
|
||||||
).strip().split('\n')
|
if len(admin_users) == 1:
|
||||||
if len(admin_users) > 1:
|
return admin_users[0]
|
||||||
return None
|
return None
|
||||||
return admin_users[0]
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user