[mod] improve error message when apps are still installed on a domain

This commit is contained in:
Laurent Peuch 2020-05-06 20:20:38 +02:00
parent a11654e0cf
commit 9e86014636
2 changed files with 10 additions and 4 deletions

View file

@ -271,7 +271,7 @@
"domain_dyndns_root_unknown": "Unknown DynDNS root domain", "domain_dyndns_root_unknown": "Unknown DynDNS root domain",
"domain_exists": "The domain already exists", "domain_exists": "The domain already exists",
"domain_hostname_failed": "Could not set new hostname. This might cause an issue later (it might be fine).", "domain_hostname_failed": "Could not set new hostname. This might cause an issue later (it might be fine).",
"domain_uninstall_app_first": "One or more apps are installed on this domain. Please uninstall them before proceeding to domain removal", "domain_uninstall_app_first": "Those applications are still installed on your domain: {apps}. Please uninstall them before proceeding to domain removal",
"domain_unknown": "Unknown domain", "domain_unknown": "Unknown domain",
"domains_available": "Available domains:", "domains_available": "Available domains:",
"done": "Done", "done": "Done",

View file

@ -179,9 +179,15 @@ def domain_remove(operation_logger, domain, force=False):
raise YunohostError('domain_cannot_remove_main_add_new_one', domain=domain) raise YunohostError('domain_cannot_remove_main_add_new_one', domain=domain)
# Check if apps are installed on the domain # Check if apps are installed on the domain
app_settings = [_get_app_settings(app) for app in _installed_apps()] apps_on_that_domain = []
if any("domain" in s and s["domain"] == domain for s in app_settings):
raise YunohostError('domain_uninstall_app_first') for app in _installed_apps():
settings = _get_app_settings(app)
if settings.get("domain") == domain:
apps_on_that_domain.append("%s (on https://%s%s)" % (app, domain, settings.get("path")))
if apps_on_that_domain:
raise YunohostError('domain_uninstall_app_first', apps=", ".join(apps_on_that_domain))
operation_logger.start() operation_logger.start()
ldap = _get_ldap_interface() ldap = _get_ldap_interface()