From 17ce7bd95c097f8fceeee6f35873c89cd4b4b91c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 26 Oct 2019 17:35:00 +0200 Subject: [PATCH] Rework depreciation warning about legacy permission stuff --- data/helpers.d/setting | 4 ++-- src/yunohost/app.py | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/data/helpers.d/setting b/data/helpers.d/setting index fd2824997..d905b61dd 100644 --- a/data/helpers.d/setting +++ b/data/helpers.d/setting @@ -176,8 +176,8 @@ else: elif action == "set": if key in ['redirected_urls', 'redirected_regex']: value = yaml.load(value) - if key in ["unprotected_uris", "unprotected_regex", "protected_uris", "protected_regex"]: - sys.stderr.write("/!\\ Packagers! This app is using the legacy permission system. Please delete these legacy settings and use the new helpers 'ynh_permission_{create,urls,update,delete}' and the 'visitors' group to manage public/private access.\n") + if any(key.startswith(word+"_") for word in ["unprotected", "protected", "skipped"]): + sys.stderr.write("/!\\ Packagers! This app is still using the skipped/protected/unprotected_uris/regex settings which are now obsolete and deprecated... Instead, you should use the new helpers 'ynh_permission_{create,urls,update,delete}' and the 'visitors' group to initialize the public/private access. Check out the documentation at the bottom of yunohost.org/groups_and_permissions to learn how to use the new permission mechanism.\n") settings[key] = value else: raise ValueError("action should either be get, set or delete") diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 5cf812871..b1ad0f40c 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1341,17 +1341,18 @@ def app_setting(app, key, value=None, delete=False): except Exception as e: logger.debug("cannot get app setting '%s' for '%s' (%s)", key, app, e) return None + + if delete and key in app_settings: + del app_settings[key] else: - if delete and key in app_settings: - del app_settings[key] - else: - # FIXME: Allow multiple values for some keys? - if key in ['redirected_urls', 'redirected_regex']: - value = yaml.load(value) - if key in ["unprotected_uris", "unprotected_regex", "protected_uris", "protected_regex"]: - logger.warning("/!\ Packagers ! This app is using the legacy permission system. Please delete these legacy settings and use the new helpers ynh_permission_{create,url,update,delete} and the 'visitors' group to manage public/private access.") - app_settings[key] = value - _set_app_settings(app, app_settings) + # FIXME: Allow multiple values for some keys? + if key in ['redirected_urls', 'redirected_regex']: + value = yaml.load(value) + if any(key.startswith(word+"_") for word in ["unprotected", "protected", "skipped"]): + logger.warning("/!\\ Packagers! This app is still using the skipped/protected/unprotected_uris/regex settings which are now obsolete and deprecated... Instead, you should use the new helpers 'ynh_permission_{create,urls,update,delete}' and the 'visitors' group to initialize the public/private access. Check out the documentation at the bottom of yunohost.org/groups_and_permissions to learn how to use the new permission mechanism.") + + app_settings[key] = value + _set_app_settings(app, app_settings) def app_checkport(port):