From cdcd967eb1f3fdd7c1e5bdfb13171b85a59298ba Mon Sep 17 00:00:00 2001 From: axolotle Date: Wed, 23 Nov 2022 16:02:15 +0100 Subject: [PATCH] app: add notifications helpers --- locales/en.json | 1 + src/app.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/locales/en.json b/locales/en.json index c39687fbe..aac3bf69e 100644 --- a/locales/en.json +++ b/locales/en.json @@ -166,6 +166,7 @@ "confirm_app_install_thirdparty": "DANGER! This app is not part of YunoHost's app catalog. Installing third-party apps may compromise the integrity and security of your system. You should probably NOT install it unless you know what you are doing. NO SUPPORT will be provided if this app doesn't work or breaks your system... If you are willing to take that risk anyway, type '{answers}'", "confirm_app_install_warning": "Warning: This app may work, but is not well-integrated into YunoHost. Some features such as single sign-on and backup/restore might not be available. Install anyway? [{answers}] ", "confirm_app_insufficient_ram": "DANGER! This app requires {required} RAM to install/upgrade but only {current} is available right now. Even if this app could run, its installation/upgrade process requires a large amount of RAM so your server may freeze and fail miserably. If you are willing to take that risk anyway, type '{answers}'", + "confirm_notifications_read": "WARNING: You should check the app notifications above before continuing, there might be important stuff to know. [{answers}]", "custom_app_url_required": "You must provide a URL to upgrade your custom app {app}", "danger": "Danger:", "diagnosis_apps_allgood": "All installed apps respect basic packaging practices", diff --git a/src/app.py b/src/app.py index 2974a69d8..fac0bd484 100644 --- a/src/app.py +++ b/src/app.py @@ -2799,6 +2799,29 @@ def _assert_system_is_sane_for_app(manifest, when): raise YunohostError("this_action_broke_dpkg") +def _filter_and_hydrate_notifications(notifications, current_version=None, data={}): + return { + # Should we render the markdown maybe? idk + name: _hydrate_app_template(_value_for_locale(content_per_lang), data) + for name, content_per_lang in notifications.items() + if current_version is None + or name == "main" + or version.parse(name) > current_version + } + + +def _display_notifications(notifications, force=False): + if not notifications: + return + + for name, content in notifications.items(): + print(f"========== {name}") + print(content) + print("==========") + + _ask_confirmation("confirm_notifications_read", kind="simple", force=force) + + # FIXME: move this to Moulinette def _ask_confirmation( question: str,