From 4d2c6bfb6486221a53c1a2bb9ec9e2a7bb6b855d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Tue, 22 Jul 2014 16:10:19 +0200 Subject: [PATCH] [fix] Add domain only if needed on main domain change #19 --- locales/en.json | 1 + locales/fr.json | 1 + tools.py | 9 ++++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/locales/en.json b/locales/en.json index 5355bb80b..c3a534d2c 100644 --- a/locales/en.json +++ b/locales/en.json @@ -112,6 +112,7 @@ "password_too_short" : "Password is too short", "admin_password_change_failed" : "Unable to change password", "admin_password_changed" : "Administration password successfully changed", + "new_domain_required" : "You must provide the new main domain", "maindomain_change_failed" : "Unable to change main domain", "maindomain_changed" : "Main domain successfully changed", "yunohost_installing" : "Installing YunoHost...", diff --git a/locales/fr.json b/locales/fr.json index 678894a7d..1fedb512d 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -112,6 +112,7 @@ "password_too_short" : "Le mot de passe est trop court", "admin_password_change_failed" : "Impossible de modifier le mot de passe d'administration", "admin_password_changed" : "Mot de passe d'administration modifié avec succès", + "new_domain_required" : "Vous devez spécifier le nouveau domaine principal", "maindomain_change_failed" : "Impossible de modifier le domaine principal", "maindomain_changed" : "Domaine principal modifié avec succès", "yunohost_installing" : "Installation de YunoHost...", diff --git a/tools.py b/tools.py index c94e1017a..f7a7fcdc6 100644 --- a/tools.py +++ b/tools.py @@ -107,7 +107,7 @@ def tools_maindomain(auth, old_domain=None, new_domain=None, dyndns=False): old_domain """ - from yunohost.domain import domain_add + from yunohost.domain import domain_add, domain_list from yunohost.dyndns import dyndns_subscribe if not old_domain: @@ -117,6 +117,11 @@ def tools_maindomain(auth, old_domain=None, new_domain=None, dyndns=False): if not new_domain: return { 'current_main_domain': old_domain } + if not new_domain: + raise MoulinetteError(errno.EINVAL, m18n.n('new_domain_required')) + if new_domain not in domain_list(auth)['domains']: + domain_add(auth, new_domain, main=True) + config_files = [ '/etc/postfix/main.cf', '/etc/metronome/metronome.cfg.lua', @@ -140,8 +145,6 @@ def tools_maindomain(auth, old_domain=None, new_domain=None, dyndns=False): for line in lines: sources.write(re.sub(r''+ old_domain +'', new_domain, line)) - domain_add(auth, new_domain, main=True) - os.system('rm /etc/ssl/private/yunohost_key.pem') os.system('rm /etc/ssl/certs/yunohost_crt.pem')