diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index ebdd2b982..ece642d0d 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -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/ + 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: diff --git a/src/yunohost/permission.py b/src/yunohost/permission.py index 20c34ada8..ab79ff7ed 100644 --- a/src/yunohost/permission.py +++ b/src/yunohost/permission.py @@ -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} diff --git a/src/yunohost/user.py b/src/yunohost/user.py index 92bdcf7a4..80f558809 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -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')])