Add a command to import a user from LDAP
This commit is contained in:
parent
76ffb649a3
commit
e19df73642
18
tasks/management/commands/import_ldap_user.py
Normal file
18
tasks/management/commands/import_ldap_user.py
Normal file
@ -0,0 +1,18 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from django_auth_ldap.backend import LDAPBackend
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Import a user from LDAP by username'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('username', type=str)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
username = options['username']
|
||||
user = LDAPBackend().populate_user(username)
|
||||
if user is None:
|
||||
raise Exception(f"No user named {username}")
|
||||
else:
|
||||
print("Imported user:", user)
|
Loading…
Reference in New Issue
Block a user