--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 action_help: List existing groups
api: GET /users/groups api: GET /users/groups
arguments: arguments:
-n: -s:
full: --names-only full: --short
help: Only list the name of the groups without any additional info help: List only the names of groups
action: store_true action: store_true
-f: -f:
full: --full full: --full
help: List all the info available for each groups help: Display all informations known about each groups
action: store_true action: store_true
### user_group_create() ### user_group_create()
@ -281,6 +281,16 @@ user:
list: list:
action_help: List permissions and corresponding accesses action_help: List permissions and corresponding accesses
api: GET /users/permissions/<permission> 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() ### user_permission_update()
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 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() ldap = _get_ldap_interface()
permissions_infos = ldap.search('ou=permission,dc=yunohost,dc=org', permissions_infos = ldap.search('ou=permission,dc=yunohost,dc=org',
'(objectclass=permissionYnh)', '(objectclass=permissionYnh)',
['cn', 'groupPermission', 'inheritPermission', 'URL']) ["cn", 'groupPermission', 'inheritPermission', 'URL'])
# Parse / organize information to be outputed
permissions = {} permissions = {}
for infos in permissions_infos: for infos in permissions_infos:
name = infos['cn'][0] name = infos['cn'][0]
permissions[name] = {}
permissions[name] = { permissions[name]["allowed"] = [_ldap_path_extract(p, "cn") for p in infos.get('groupPermission', [])]
"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', [])], if full:
"urls": infos.get("URL", []) 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} return {'permissions': permissions}

View file

@ -489,12 +489,12 @@ def user_info(username):
# #
# Group subcategory # Group subcategory
# #
def user_group_list(names_only=False, full=False): def user_group_list(short=False, full=False):
""" """
List users List users
Keyword argument: 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 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 from yunohost.utils.ldap import _get_ldap_interface, _ldap_path_extract
ldap = _get_ldap_interface() 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', groups_infos = ldap.search('ou=groups,dc=yunohost,dc=org',
'(objectclass=groupOfNamesYnh)', '(objectclass=groupOfNamesYnh)',
fields_to_fetch) ["cn", "member", "permission"])
# Parse / organize information to be outputed # Parse / organize information to be outputed
groups = {} groups = {}
for infos in groups_infos: for infos in groups_infos:
name = infos["cn"][0] name = infos["cn"][0]
groups[name] = {} groups[name] = {}
if "member" in fields_to_fetch:
groups[name]["members"] = [_ldap_path_extract(p, "uid") for p in infos.get("member", [])] groups[name]["members"] = [_ldap_path_extract(p, "uid") for p in infos.get("member", [])]
if "permission" in fields_to_fetch:
if full:
groups[name]["permissions"] = [_ldap_path_extract(p, "cn") for p in infos.get("permission", [])] groups[name]["permissions"] = [_ldap_path_extract(p, "cn") for p in infos.get("permission", [])]
if names_only: if short:
groups = groups.keys() groups = groups.keys()
return {'groups': groups} return {'groups': groups}
@ -719,9 +713,9 @@ def user_group_info(groupname):
# Permission subcategory # Permission subcategory
# #
def user_permission_list(): def user_permission_list(short=False, full=False):
import yunohost.permission import yunohost.permission
return yunohost.permission.user_permission_list() return yunohost.permission.user_permission_list(short, full)
@is_unit_operation([('permission', 'user')]) @is_unit_operation([('permission', 'user')])