Merge branch 'dev' into plugins-browsertrix

This commit is contained in:
Nick Sweeting 2024-01-24 12:34:41 -08:00 committed by GitHub
commit 4aee3b590e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 128 additions and 12 deletions

View file

@ -8,3 +8,8 @@ class CoreAppConfig(AppConfig):
# WIP: broken by Django 3.1.2 -> 4.0 migration
default_auto_field = 'django.db.models.UUIDField'
def ready(self):
from .auth import register_signals
register_signals()

13
archivebox/core/auth.py Normal file
View file

@ -0,0 +1,13 @@
import os
from django.conf import settings
from ..config import (
LDAP
)
def register_signals():
if LDAP:
import django_auth_ldap.backend
from .auth_ldap import create_user
django_auth_ldap.backend.populate_user.connect(create_user)

View file

@ -0,0 +1,12 @@
from django.conf import settings
from ..config import (
LDAP_CREATE_SUPERUSER
)
def create_user(sender, user=None, ldap_user=None, **kwargs):
if not user.id and LDAP_CREATE_SUPERUSER:
user.is_superuser = True
user.is_staff = True
print(f'[!] WARNING: Creating new user {user} based on LDAP user {ldap_user} (is_staff={user.is_staff}, is_superuser={user.is_superuser})')