diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 0e4a473b4..4ecdc0db6 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -90,7 +90,7 @@ def app_list(filter=None, raw=False, installed=False, with_backup=False): app_dict = _load_apps_catalog() # Get app list from the app settings directory - for app in os.listdir(APPS_SETTING_PATH): + for app in _installed_apps(): if app not in app_dict: # Handle multi-instance case like wordpress__2 if '__' in app: @@ -452,19 +452,12 @@ def app_upgrade(app=[], url=None, file=None): from yunohost.hook import hook_add, hook_remove, hook_exec, hook_callback from yunohost.permission import permission_sync_to_user - try: - app_list() - except YunohostError: - raise YunohostError('apps_already_up_to_date') - - not_upgraded_apps = [] - apps = app # If no app is specified, upgrade all apps if not apps: # FIXME : not sure what's supposed to happen if there is a url and a file but no apps... if not url and not file: - apps = [app_["id"] for app_ in app_list(installed=True)["apps"]] + apps = _installed_apps() elif not isinstance(app, list): apps = [app] @@ -668,7 +661,10 @@ def app_install(operation_logger, app, label=None, args=None, no_remove_on_failu # If we got an url like "https://github.com/foo/bar_ynh, we want to # extract "bar" and test if we know this app elif ('http://' in app) or ('https://' in app): - app_name_to_test = app.strip("/").split("/")[-1].replace("_ynh","") + app_name_to_test = app.strip("/").split("/")[-1].replace("_ynh", "") + else: + # FIXME : watdo if '@' in app ? + app_name_to_test = None if app_name_to_test in raw_app_list: @@ -1216,8 +1212,7 @@ def app_register_url(app, domain, path): # We cannot change the url of an app already installed simply by changing # the settings... - installed = app in app_list(installed=True, raw=True).keys() - if installed: + if _is_installed(app): settings = _get_app_settings(app) if "path" in settings.keys() and "domain" in settings.keys(): raise YunohostError('app_already_installed_cant_change_url') @@ -1263,19 +1258,13 @@ def app_ssowatconf(): redirected_regex = {main_domain + '/yunohost[\/]?$': 'https://' + main_domain + '/yunohost/sso/'} redirected_urls = {} - try: - apps_list = app_list(installed=True)['apps'] - except Exception as e: - logger.debug("cannot get installed app list because %s", e) - apps_list = [] - def _get_setting(settings, name): s = settings.get(name, None) return s.split(',') if s else [] - for app in apps_list: + for app in _installed_apps(): - app_settings = read_yaml(APPS_SETTING_PATH + app['id'] + '/settings.yml') + app_settings = read_yaml(APPS_SETTING_PATH + app + '/settings.yml') if 'domain' not in app_settings: continue @@ -1622,8 +1611,7 @@ def _get_all_installed_apps_id(): * ...' """ - all_apps_ids = [x["id"] for x in app_list(installed=True)["apps"]] - all_apps_ids = sorted(all_apps_ids) + all_apps_ids = sorted(_installed_apps()) all_apps_ids_formatted = "\n * ".join(all_apps_ids) all_apps_ids_formatted = "\n * " + all_apps_ids_formatted @@ -2269,6 +2257,8 @@ def _is_installed(app): """ return os.path.isdir(APPS_SETTING_PATH + app) +def _installed_apps(): + return os.listdir(APPS_SETTING_PATH) def _value_for_locale(values): """ diff --git a/src/yunohost/data_migrations/0011_setup_group_permission.py b/src/yunohost/data_migrations/0011_setup_group_permission.py index c80686344..e054915cf 100644 --- a/src/yunohost/data_migrations/0011_setup_group_permission.py +++ b/src/yunohost/data_migrations/0011_setup_group_permission.py @@ -8,7 +8,7 @@ from moulinette.utils.filesystem import read_yaml from yunohost.tools import Migration from yunohost.user import user_list, user_group_create, user_group_update -from yunohost.app import app_setting, app_list +from yunohost.app import app_setting, _installed_apps from yunohost.regenconf import regen_conf, BACKUP_CONF_DIR from yunohost.permission import permission_create, user_permission_update, permission_sync_to_user @@ -96,13 +96,16 @@ class MyMigration(Migration): def migrate_app_permission(self, app=None): logger.info(m18n.n("migration_0011_migrate_permission")) - if app: - apps = app_list(installed=True, filter=app)['apps'] - else: - apps = app_list(installed=True)['apps'] + apps = _installed_apps() - for app_info in apps: - app = app_info['id'] + if app: + if app not in apps: + logger.error("Can't migrate permission for app %s because it ain't installed..." % app) + apps = [] + else: + apps = [app] + + for app in apps: permission = app_setting(app, 'allowed_users') path = app_setting(app, 'path') domain = app_setting(app, 'domain') diff --git a/src/yunohost/tests/test_permission.py b/src/yunohost/tests/test_permission.py index b3fa9fefb..6d194d520 100644 --- a/src/yunohost/tests/test_permission.py +++ b/src/yunohost/tests/test_permission.py @@ -3,7 +3,7 @@ import pytest from conftest import message, raiseYunohostError -from yunohost.app import app_install, app_remove, app_change_url, app_list, app_map +from yunohost.app import app_install, app_remove, app_change_url, app_list, app_map, _installed_apps from yunohost.user import user_list, user_create, user_delete, \ user_group_list, user_group_delete from yunohost.permission import user_permission_update, user_permission_list, user_permission_reset, \ @@ -163,9 +163,7 @@ def check_permission_for_apps(): app_perms_prefix = set(p.split(".")[0] for p in app_perms) - installed_apps = {app['id'] for app in app_list(installed=True)['apps']} - - assert installed_apps == app_perms_prefix + assert set(_installed_apps()) == app_perms_prefix def can_access_webpage(webpath, logged_as=None):