From fd90d494385c9a47bbf663944d2770250f03e3a2 Mon Sep 17 00:00:00 2001 From: Elias Showk Date: Fri, 23 Feb 2018 17:11:12 +0100 Subject: [PATCH] authentic agent : refactored hobo_deploy command to get username/email/first_name/last_name from hobo.json to create super-users for authentic (#21888) --- .../authentic2/management/commands/hobo_deploy.py | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hobo/agent/authentic2/management/commands/hobo_deploy.py b/hobo/agent/authentic2/management/commands/hobo_deploy.py index f0e6030..05f80ee 100644 --- a/hobo/agent/authentic2/management/commands/hobo_deploy.py +++ b/hobo/agent/authentic2/management/commands/hobo_deploy.py @@ -38,25 +38,24 @@ class Command(hobo_deploy.Command): # Activate default translation activate(settings.LANGUAGE_CODE) - # create hobo users in authentic to bootstrap (don't update them, - # hobo is not a provisioning system) + # create hobo super-users in authentic to bootstrap for user_dict in hobo_environment.get('users'): - user, created = get_user_model().objects.get_or_create( - username=user_dict.get('username')) + # without username, we put default values + username = user_dict.get('username', 'admin') + email = user_dict.get('email', 'admin@entrouvert.org') + # get_or_create is used bootstrap hobo from a hobo.json config + user, created = get_user_model().objects.get_or_create(username=username) if created: for key, value in user_dict.items(): setattr(user, key, value) + # to comply with some SP + if not user.first_name: + user.first_name = username + if not user.last_name: + user.last_name = username + user.is_staff = True user.is_superuser = True - try: - admin_name, admin_email = settings.ADMINS[0] - except (IndexError, ValueError): - admin_name, admin_email = ('Super Publik', 'admin@entrouvert.org') - if not user.email: - user.email = admin_email - if not user.first_name and not user.last_name: - # give a name as it's required by some SP - user.first_name = admin_name user.save() # create/update user attributes -- 2.16.1