From da50e66aa534e6bc819d62410ee668673144e9b6 Mon Sep 17 00:00:00 2001 From: Lev-Arcady Sellem Date: Sun, 25 Mar 2018 19:24:48 +0200 Subject: [PATCH] Factorisation --- users/management/commands/chsh.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/users/management/commands/chsh.py b/users/management/commands/chsh.py index df4d6c0d..6c5b06f7 100644 --- a/users/management/commands/chsh.py +++ b/users/management/commands/chsh.py @@ -26,6 +26,7 @@ from django.db import transaction from reversion import revisions as reversion from users.models import User, ListShell +from re2o.script_utils import get_user, get_system_user class Command(BaseCommand): help = 'Change the default shell of a user' @@ -35,14 +36,7 @@ class Command(BaseCommand): def handle(self, *args, **options): - def get_user(user_pseudo): - """Return the user queried by pseudo, and exit the script if not found.""" - user = User.objects.filter(pseudo=user_pseudo) - if not user: - raise CommandError("Utilisateur invalide") - return user[0] - - current_username = pwd.getpwuid(int(os.getenv("SUDO_UID") or os.getuid())).pw_name + current_username = get_system_user() current_user = get_user(current_username) target_username = options["target_username"] or current_username