8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Factorisation

This commit is contained in:
Lev-Arcady Sellem 2018-03-25 19:24:48 +02:00
parent 3c9d4b0e6d
commit da50e66aa5

View file

@ -26,6 +26,7 @@ from django.db import transaction
from reversion import revisions as reversion from reversion import revisions as reversion
from users.models import User, ListShell from users.models import User, ListShell
from re2o.script_utils import get_user, get_system_user
class Command(BaseCommand): class Command(BaseCommand):
help = 'Change the default shell of a user' help = 'Change the default shell of a user'
@ -35,14 +36,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
def get_user(user_pseudo): current_username = get_system_user()
"""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_user = get_user(current_username) current_user = get_user(current_username)
target_username = options["target_username"] or current_username target_username = options["target_username"] or current_username