diff --git a/action_map.yml b/action_map.yml index b1778ebd..88f0a5da 100644 --- a/action_map.yml +++ b/action_map.yml @@ -284,6 +284,11 @@ app: full: --raw help: Return complete dict action: store_true + -u: + full: --user + help: Allowed app map for a user + pattern: '^[a-z0-9_]+$' + ### app_install() TODO: Write help install: diff --git a/yunohost_app.py b/yunohost_app.py index f7512047..ea267f91 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -126,13 +126,25 @@ def app_list(offset=None, limit=None, filter=None, raw=False): else: list_dict=[] - if not applists: app_fetchlist() + if not applists: + app_fetchlist() + applists = os.listdir(repo_path) for applist in applists: if '.json' in applist: with open(repo_path +'/'+ applist) as json_list: app_dict.update(json.loads(str(json_list.read()))) + for app in os.listdir(apps_setting_path): + if app not in app_dict: + # Look for forks + if '__' in app: + original_app = app[:app.index('__')] + if original_app in app_dict: + app_dict[app] = app_dict[original_app] + continue + app_dict[app] = { 'orphan': True } + if len(app_dict) > (0 + offset) and limit > 0: sorted_app_dict = {} for sorted_keys in sorted(app_dict.keys())[offset:]: @@ -142,7 +154,6 @@ def app_list(offset=None, limit=None, filter=None, raw=False): for app_id, app_info in sorted_app_dict.items(): if i < limit: if (filter and ((filter in app_id) or (filter in app_info['manifest']['name']))) or not filter: - #TODO: make _is_installed installed = _is_installed(app_id) if raw: @@ -173,10 +184,13 @@ def app_info(app, raw=False): """ try: - app_info = app_list(filter=app, limit=1, raw=True)[app] + app_info = app_list(filter=app, raw=True)[app] except YunoHostError: app_info = {} + with open(apps_setting_path + app +'/settings.yml') as f: + app_info['settings'] = yaml.load(f) + if raw: return app_info else: @@ -187,13 +201,14 @@ def app_info(app, raw=False): } -def app_map(app=None, raw=False): +def app_map(app=None, raw=False, user=None): """ List apps by domain Keyword argument: app -- Specific app to map raw -- Return complete dict + user -- Only accessible app for user """ @@ -203,6 +218,12 @@ def app_map(app=None, raw=False): if app and (app != app_id): continue + if user is not None: + app_dict = app_info(app=app_id, raw=True) + if ('mode' not in app_dict['settings']) or ('mode' in app_dict['settings'] and app_dict['settings']['mode'] == 'private'): + if 'allowed_users' in app_dict['settings'] and user not in app_dict['settings']['allowed_users'].split(','): + continue + with open(apps_setting_path + app_id +'/settings.yml') as f: app_settings = yaml.load(f) diff --git a/yunohost_domain.py b/yunohost_domain.py index b44edcbe..fb4a313f 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -31,6 +31,7 @@ import shutil import json from urllib import urlopen from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args +#from yunohost_app import app_list, app_info, app_map def domain_list(filter=None, limit=None, offset=None): @@ -272,6 +273,28 @@ def domain_ssowatconf(): domains = domain_list()['Domains'] + #apps = {} + #for app, v in app_list(raw=True): + # app_settings = app_info(raw=True, app=app)['settings'] + # if 'domain' in app_settings: + # if 'path' not in app_settings: + # app_settings['path'] = '/' + # if 'mode' not in app_settings: + # app_settings['mode'] = 'private' + # if 'allowed_users' not in app_settings: + # app_settings['allowed_users'] = '' + + # apps[app] = { + # 'domain': app_settings['domain'], + # 'path': app_settings['path'], + # 'mode': app_settings['mode'], + # 'allowed_users': app_settings['allowed_users'] + # } + + #users = {} + #for user, v in user_list()['Users']: + # users[user] = app_map(user=user) + conf_dict = { 'portal_domain': main_domain, 'portal_path': '/ynhsso/', @@ -285,7 +308,9 @@ def domain_ssowatconf(): }, 'domains': domains, 'skipped_urls': ['https://'+ main_domain +'/ynhadmin'], - 'unprotected_urls': [] + 'unprotected_urls': [], + # 'apps': apps, + # 'users': users } with open('/etc/ssowat/conf.json', 'wb') as f: