From 78a2d012bb6926185d047f452712bb073c34fd4c Mon Sep 17 00:00:00 2001 From: ekhae Date: Fri, 16 Aug 2019 17:59:22 +0000 Subject: [PATCH] UX improved about mail and domains --- data/actionsmap/yunohost.yml | 31 +++++++++++++------------------ locales/en.json | 1 + src/yunohost/user.py | 22 +++++++++++++++++----- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index d61538c5c..13a3cfaaf 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -97,15 +97,6 @@ user: pattern: &pattern_lastname - !!str ^([^\W\d_]{2,30}[ ,.'-]{0,3})+$ - "pattern_lastname" - -m: - full: --mail - help: Main unique email address - extra: - ask: ask_email - required: True - pattern: &pattern_email - - !!str ^[\w.-]+@([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,})$ - - "pattern_email" -p: full: --password help: User password @@ -116,6 +107,13 @@ user: - !!str ^.{3,}$ - "pattern_password" comment: good_practices_about_user_password + -d: + full: --domain + help: Domain for email and xmpp + extra: + pattern: &pattern_domain + - !!str ^([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,})$ + - "pattern_domain" -q: full: --mailbox-quota help: Mailbox size quota @@ -157,7 +155,9 @@ user: -m: full: --mail extra: - pattern: *pattern_email + pattern: &pattern_email + - !!str ^[\w.-]+@([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,})$ + - "pattern_email" -p: full: --change-password help: New password to set @@ -419,9 +419,7 @@ domain: domain: help: Domain name to add extra: - pattern: &pattern_domain - - !!str ^([^\W_A-Z]+([-]*[^\W_A-Z]+)*\.)+([^\W\d_]{2,})$ - - "pattern_domain" + pattern: *pattern_domain -d: full: --dyndns help: Subscribe to the DynDNS service @@ -1340,7 +1338,7 @@ dyndns: tools: category_help: Specific tools actions: - + ### tools_adminpw() adminpw: action_help: Change password of admin and root users @@ -1368,9 +1366,6 @@ tools: postinstall: action_help: YunoHost post-install api: POST /postinstall - configuration: - # We need to be able to run the postinstall without being authenticated, otherwise we can't run the postinstall - authenticate: false arguments: -d: full: --domain @@ -1378,7 +1373,7 @@ tools: extra: ask: ask_main_domain pattern: *pattern_domain - required: True + required: False -p: full: --password help: YunoHost admin password diff --git a/locales/en.json b/locales/en.json index 83cc84442..afc9db13a 100644 --- a/locales/en.json +++ b/locales/en.json @@ -60,6 +60,7 @@ "apps_catalog_failed_to_download": "Unable to download the {apps_catalog} app catalog: {error}", "apps_catalog_obsolete_cache": "The app catalog cache is empty or obsolete.", "apps_catalog_update_success": "The application catalog has been updated!", + "ask_domain": "Choose a domain", "ask_email": "E-mail address", "ask_firstname": "First name", "ask_lastname": "Last name", diff --git a/src/yunohost/user.py b/src/yunohost/user.py index d19da177c..bd8252d0e 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -105,7 +105,7 @@ def user_list(fields=None): @is_unit_operation([('username', 'user')]) -def user_create(operation_logger, username, firstname, lastname, mail, password, +def user_create(operation_logger, username, firstname, lastname, domain, password, mailbox_quota="0"): """ Create user @@ -126,7 +126,22 @@ def user_create(operation_logger, username, firstname, lastname, mail, password, # Ensure sufficiently complex password assert_password_is_strong_enough("user", password) + from moulinette import msignals, msettings, m18n + from yunohost.domain import domain_list + if domain is None: + if msettings.get('interface') == 'api': + raise YunohostError('Invalide usage, specify domain argument') + else: + # On affiche les differents domaines possibles + for domain_checked in domain_list()['domains'] : + msignals.display("- {}".format(domain_checked)) + domain = msignals.prompt(m18n.n('ask_domain')) + # Check that the domain exists + if domain not in domain_list()['domains']: + raise YunohostError('domain_unknown', domain) + + mail=username+'@'+ domain ldap = _get_ldap_interface() if username in user_list()["users"]: @@ -158,10 +173,6 @@ def user_create(operation_logger, username, firstname, lastname, mail, password, if mail in aliases: raise YunohostError('mail_unavailable') - # Check that the mail domain exists - if mail.split("@")[1] not in domain_list()['domains']: - raise YunohostError('mail_domain_unknown', domain=mail.split("@")[1]) - operation_logger.start() # Get random UID/GID @@ -176,6 +187,7 @@ def user_create(operation_logger, username, firstname, lastname, mail, password, # Adapt values for LDAP fullname = '%s %s' % (firstname, lastname) + attr_dict = { 'objectClass': ['mailAccount', 'inetOrgPerson', 'posixAccount', 'userPermissionYnh'], 'givenName': [firstname],