mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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',
|
||||
help='LDAP group to remove the user from')
|
||||
|
||||
help_get_admin_user = 'Get the list of all users in an LDAP group'
|
||||
subparser = subparsers.add_parser('get-group-users', help=help_get_admin_user)
|
||||
subparser.add_argument('groupname', help='name of the LDAP group to get the '
|
||||
'list of users')
|
||||
help_get_group_users = 'Get the list of all users in an LDAP group'
|
||||
subparser = subparsers.add_parser('get-group-users',
|
||||
help=help_get_group_users)
|
||||
subparser.add_argument(
|
||||
'groupname', help='name of the LDAP group to get the '
|
||||
'list of users')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
@ -351,13 +353,14 @@ def subcommand_remove_user_from_group(arguments):
|
||||
|
||||
|
||||
def subcommand_get_group_users(arguments):
|
||||
""" Get the list of admin users """
|
||||
process = _run(['ldapgid', arguments.groupname], stdout=subprocess.PIPE)
|
||||
output = str(process.stdout).split()
|
||||
users_info = output[1].split('=')[1].strip('\\n').split(',')
|
||||
for user_info in users_info:
|
||||
user_name = user_info.split('(')[1].split(')')[0]
|
||||
print(user_name)
|
||||
""" Get the list of users of an LDAP group."""
|
||||
process = _run(['ldapgid', '-P', arguments.groupname],
|
||||
stdout=subprocess.PIPE)
|
||||
output = process.stdout.decode()
|
||||
users = output.rsplit(':')[-1]
|
||||
if users:
|
||||
for user in users.strip().split(','):
|
||||
print(user)
|
||||
|
||||
|
||||
def flush_cache():
|
||||
|
||||
@ -111,9 +111,8 @@ def get_last_admin_user():
|
||||
""" Check if there is only one admin user
|
||||
if yes return its name else return None
|
||||
"""
|
||||
admin_users = actions.superuser_run('users',
|
||||
['get-group-users','admin']
|
||||
).strip().split('\n')
|
||||
if len(admin_users) > 1:
|
||||
return None
|
||||
return admin_users[0]
|
||||
admin_users = actions.superuser_run(
|
||||
'users', ['get-group-users', 'admin']).strip().split('\n')
|
||||
if len(admin_users) == 1:
|
||||
return admin_users[0]
|
||||
return None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user