--short and --full options for group_list and permission_list

This commit is contained in:
Alexandre Aubin 2019-09-11 15:16:09 +02:00
parent 41e6f1b81c
commit 45483f4116
3 changed files with 40 additions and 30 deletions

View file

@ -208,13 +208,13 @@ user:
action_help: List existing groups
api: GET /users/groups
arguments:
-n:
full: --names-only
help: Only list the name of the groups without any additional info
-s:
full: --short
help: List only the names of groups
action: store_true
-f:
full: --full
help: List all the info available for each groups
help: Display all informations known about each groups
action: store_true
### user_group_create()
@ -281,6 +281,16 @@ user:
list:
action_help: List permissions and corresponding accesses
api: GET /users/permissions/<permission>
arguments:
-s:
full: --short
help: List only the names of permissions
action: store_true
-f:
full: --full
help: Display all informations known about each permissions, including the full list of users corresponding to allowed groups.
action: store_true
### user_permission_update()
update:

View file

@ -43,29 +43,35 @@ logger = getActionLogger('yunohost.user')
#
def user_permission_list():
def user_permission_list(short=False, full=False):
"""
List permissions and corresponding accesses
"""
from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract
# Fetch relevant informations
# Fetch all permissions objects
from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract
ldap = _get_ldap_interface()
permissions_infos = ldap.search('ou=permission,dc=yunohost,dc=org',
'(objectclass=permissionYnh)',
['cn', 'groupPermission', 'inheritPermission', 'URL'])
["cn", 'groupPermission', 'inheritPermission', 'URL'])
# Parse / organize information to be outputed
permissions = {}
for infos in permissions_infos:
name = infos['cn'][0]
permissions[name] = {}
permissions[name] = {
"allowed_users": [_ldap_path_extract(p, "uid") for p in infos.get('inheritPermission', [])],
"allowed_groups": [_ldap_path_extract(p, "cn") for p in infos.get('groupPermission', [])],
"urls": infos.get("URL", [])
}
permissions[name]["allowed"] = [_ldap_path_extract(p, "cn") for p in infos.get('groupPermission', [])]
if full:
permissions[name]["corresponding_users"] = [_ldap_path_extract(p, "uid") for p in infos.get('inheritPermission', [])],
permissions[name]["urls"] = infos.get("URL", [])
if short:
permissions = permissions.keys()
return {'permissions': permissions}

View file

@ -489,12 +489,12 @@ def user_info(username):
#
# Group subcategory
#
def user_group_list(names_only=False, full=False):
def user_group_list(short=False, full=False):
"""
List users
Keyword argument:
names-only -- Only list the name of the groups without any additional info
short -- Only list the name of the groups without any additional info
full -- List all the info available for each groups
"""
@ -502,30 +502,24 @@ def user_group_list(names_only=False, full=False):
from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract
ldap = _get_ldap_interface()
if names_only:
fields_to_fetch = ["cn"]
elif full:
fields_to_fetch = ["cn", "member", "permission"]
else:
fields_to_fetch = ["cn", "member"]
groups_infos = ldap.search('ou=groups,dc=yunohost,dc=org',
'(objectclass=groupOfNamesYnh)',
fields_to_fetch)
["cn", "member", "permission"])
# Parse / organize information to be outputed
groups = {}
for infos in groups_infos:
name = infos["cn"][0]
groups[name] = {}
if "member" in fields_to_fetch:
groups[name]["members"] = [_ldap_path_extract(p, "uid") for p in infos.get("member", [])]
if "permission" in fields_to_fetch:
groups[name]["members"] = [_ldap_path_extract(p, "uid") for p in infos.get("member", [])]
if full:
groups[name]["permissions"] = [_ldap_path_extract(p, "cn") for p in infos.get("permission", [])]
if names_only:
if short:
groups = groups.keys()
return {'groups': groups}
@ -719,9 +713,9 @@ def user_group_info(groupname):
# Permission subcategory
#
def user_permission_list():
def user_permission_list(short=False, full=False):
import yunohost.permission
return yunohost.permission.user_permission_list()
return yunohost.permission.user_permission_list(short, full)
@is_unit_operation([('permission', 'user')])