From bd72a59e1f62f85653422dbb2276d0d552903f7b Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 13:21:27 +0200 Subject: [PATCH 1/9] remove app settings after removing the app permissions --- src/yunohost/app.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 8d334677f..7ada46d0c 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1263,16 +1263,15 @@ def app_remove(operation_logger, app): else: logger.warning(m18n.n("app_not_properly_removed", app=app)) + # Remove all permission in LDAP + for permission_name in user_permission_list(apps=[app])["permissions"].keys(): + permission_delete(permission_name, force=True, sync_perm=False) + if os.path.exists(app_setting_path): shutil.rmtree(app_setting_path) shutil.rmtree("/tmp/yunohost_remove") hook_remove(app) - # Remove all permission in LDAP - for permission_name in user_permission_list()["permissions"].keys(): - if permission_name.startswith(app + "."): - permission_delete(permission_name, force=True, sync_perm=False) - permission_sync_to_user() _assert_system_is_sane_for_app(manifest, "post") From f6687e69f852b3586c620c217d11123c94ff61f6 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 13:22:07 +0200 Subject: [PATCH 2/9] user_permission_list: use the new apps arg when we can --- src/yunohost/app.py | 9 ++++----- src/yunohost/backup.py | 8 +++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 7ada46d0c..414035e77 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -324,9 +324,9 @@ def app_map(app=None, raw=False, user=None): app, ] else: - apps = os.listdir(APPS_SETTING_PATH) + apps = _installed_apps() - permissions = user_permission_list(full=True, absolute_urls=True)["permissions"] + permissions = user_permission_list(full=True, absolute_urls=True, apps=apps)["permissions"] for app_id in apps: app_settings = _get_app_settings(app_id) if not app_settings: @@ -1096,9 +1096,8 @@ def app_install( ) # Remove all permission in LDAP - for permission_name in user_permission_list()["permissions"].keys(): - if permission_name.startswith(app_instance_name + "."): - permission_delete(permission_name, force=True, sync_perm=False) + for permission_name in user_permission_list(apps=[app_instance_name])["permissions"].keys(): + permission_delete(permission_name, force=True, sync_perm=False) if remove_retcode != 0: msg = m18n.n("app_not_properly_removed", app=app_instance_name) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 5c83f6651..85487d07f 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -726,11 +726,10 @@ class BackupManager: # backup permissions logger.debug(m18n.n("backup_permission", app=app)) - permissions = user_permission_list(full=True)["permissions"] + permissions = user_permission_list(full=True, apps=[app])["permissions"] this_app_permissions = { name: infos for name, infos in permissions.items() - if name.startswith(app + ".") } write_to_yaml("%s/permissions.yml" % settings_dir, this_app_permissions) @@ -1547,9 +1546,8 @@ class RestoreManager: shutil.rmtree(app_settings_new_path, ignore_errors=True) # Remove all permission in LDAP for this app - for permission_name in user_permission_list()["permissions"].keys(): - if permission_name.startswith(app_instance_name + "."): - permission_delete(permission_name, force=True) + for permission_name in user_permission_list(apps=[app_instance_name])["permissions"].keys(): + permission_delete(permission_name, force=True) # TODO Cleaning app hooks From 4fa6a4cde2f64637ac6170eaa19c7241d460495d Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 14:05:16 +0200 Subject: [PATCH 3/9] trying to fix tests --- src/yunohost/permission.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/yunohost/permission.py b/src/yunohost/permission.py index 3ed9590d4..493f11953 100644 --- a/src/yunohost/permission.py +++ b/src/yunohost/permission.py @@ -89,10 +89,7 @@ def user_permission_list( name = infos["cn"][0] app = name.split(".")[0] - if app in SYSTEM_PERMS: - if ignore_system_perms: - continue - elif app not in apps: + if app in SYSTEM_PERMS and ignore_system_perms: continue perm = {} From 6745fce647df7e823fac4b5128a3ff54ab4b14e4 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 16:28:32 +0200 Subject: [PATCH 4/9] fix tests --- src/yunohost/app.py | 5 +++-- src/yunohost/backup.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 414035e77..a3c10df0b 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1096,8 +1096,9 @@ def app_install( ) # Remove all permission in LDAP - for permission_name in user_permission_list(apps=[app_instance_name])["permissions"].keys(): - permission_delete(permission_name, force=True, sync_perm=False) + for permission_name in user_permission_list()["permissions"].keys(): + if permission_name.startswith(app_instance_name + "."): + permission_delete(permission_name, force=True, sync_perm=False) if remove_retcode != 0: msg = m18n.n("app_not_properly_removed", app=app_instance_name) diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index 85487d07f..a17b752f6 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -1546,8 +1546,9 @@ class RestoreManager: shutil.rmtree(app_settings_new_path, ignore_errors=True) # Remove all permission in LDAP for this app - for permission_name in user_permission_list(apps=[app_instance_name])["permissions"].keys(): - permission_delete(permission_name, force=True) + for permission_name in user_permission_list()["permissions"].keys(): + if permission_name.startswith(app_instance_name + "."): + permission_delete(permission_name, force=True) # TODO Cleaning app hooks From ab834f1885e0ce96ee2d8fe520299b7253b790a9 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 16:43:53 +0200 Subject: [PATCH 5/9] fix clean in test_settings --- src/yunohost/tests/test_settings.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/yunohost/tests/test_settings.py b/src/yunohost/tests/test_settings.py index b402a9ef5..a393e83c6 100644 --- a/src/yunohost/tests/test_settings.py +++ b/src/yunohost/tests/test_settings.py @@ -1,5 +1,6 @@ import os import json +import glob import pytest from yunohost.utils.error import YunohostError @@ -28,6 +29,8 @@ def setup_function(function): def teardown_function(function): os.system("mv /etc/yunohost/settings.json.saved /etc/yunohost/settings.json") + for filename in glob.glob("/etc/yunohost/settings-*.json"): + os.remove(filename) def test_settings_get_bool(): From 42d671b7c0f9f5529a5a9f6a9ae507015bd51cae Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 18:17:57 +0200 Subject: [PATCH 6/9] fix pytest warnings --- pytest.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pytest.ini b/pytest.ini index 709e0e0b9..27d690435 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,12 +3,14 @@ addopts = -s -v norecursedirs = dist doc build .tox .eggs testpaths = tests/ markers = - with_system_archive_from_2p4 + with_system_archive_from_3p8 with_backup_recommended_app_installed clean_opt_dir - with_wordpress_archive_from_2p4 + with_wordpress_archive_from_3p8 with_legacy_app_installed with_backup_recommended_app_installed_with_ynh_restore with_permission_app_installed + other_domains + with_custom_domain filterwarnings = ignore::urllib3.exceptions.InsecureRequestWarning \ No newline at end of file From 8b360ac2e6e3fb3412cab7c370f9f4f2d2402013 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 13 Apr 2021 18:18:15 +0200 Subject: [PATCH 7/9] getargspec is deprecated in Python3 --- src/yunohost/log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yunohost/log.py b/src/yunohost/log.py index 9a3eb9fa6..f8215955f 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -340,9 +340,9 @@ def is_unit_operation( # Indeed, we use convention naming in this decorator and we need to # know name of each args (so we need to use kwargs instead of args) if len(args) > 0: - from inspect import getargspec + from inspect import signature - keys = getargspec(func).args + keys = list(signature(func).parameters.keys()) if "operation_logger" in keys: keys.remove("operation_logger") for k, arg in enumerate(args): From 7989271e749257639a35f3b055de4dbb8bfdf1ee Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 14 Apr 2021 20:16:58 +0200 Subject: [PATCH 8/9] user_permission_list: also support filtering for apps not installed or system perms --- src/yunohost/permission.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/yunohost/permission.py b/src/yunohost/permission.py index 493f11953..9fe6c4e4f 100644 --- a/src/yunohost/permission.py +++ b/src/yunohost/permission.py @@ -74,13 +74,12 @@ def user_permission_list( ) # Parse / organize information to be outputed - if apps: - ignore_system_perms = True - apps = apps if apps else sorted(_installed_apps()) + installed_apps = sorted(_installed_apps()) + apps = apps if apps else installed_apps apps_base_path = { app: app_setting(app, "domain") + app_setting(app, "path") for app in apps - if app_setting(app, "domain") and app_setting(app, "path") + if app in installed_apps and app_setting(app, "domain") and app_setting(app, "path") } permissions = {} @@ -89,7 +88,10 @@ def user_permission_list( name = infos["cn"][0] app = name.split(".")[0] - if app in SYSTEM_PERMS and ignore_system_perms: + if ignore_system_perms and app in SYSTEM_PERMS: + continue + + if app not in apps: continue perm = {} From 23e816deaa6b87456b9a5163b6d54d3d5a7391cb Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 14 Apr 2021 23:58:22 +0200 Subject: [PATCH 9/9] Only filter stuff if a filter is set... --- src/yunohost/permission.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/yunohost/permission.py b/src/yunohost/permission.py index 9fe6c4e4f..7d02a542f 100644 --- a/src/yunohost/permission.py +++ b/src/yunohost/permission.py @@ -75,7 +75,8 @@ def user_permission_list( # Parse / organize information to be outputed installed_apps = sorted(_installed_apps()) - apps = apps if apps else installed_apps + filter_ = apps + apps = filter_ if filter_ else installed_apps apps_base_path = { app: app_setting(app, "domain") + app_setting(app, "path") for app in apps @@ -90,8 +91,7 @@ def user_permission_list( if ignore_system_perms and app in SYSTEM_PERMS: continue - - if app not in apps: + if filter_ and app not in apps: continue perm = {}