Implement Admin approval (#29)

This PR fixes #7

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#29
This commit is contained in:
2025-07-19 06:42:50 +12:00
parent 9323a9f7d7
commit 4fff78541b
4 changed files with 21 additions and 9 deletions

View File

@ -4,6 +4,7 @@ from typing import Union, List, Optional, Set, Dict
from django.contrib.auth import get_user_model
from django.db import transaction
from django.conf import settings as s
from epdb.models import User, Package, UserPackagePermission, GroupPackagePermission, Permission, Group, Setting, \
EPModel, UserSettingPermission, Rule, Pathway, Node, Edge
@ -12,11 +13,15 @@ logger = logging.getLogger(__name__)
class UserManager(object):
@staticmethod
def create_user(username, email, password):
def create_user(username, email, password, *args, **kwargs):
# avoid circular import :S
from .tasks import send_registration_mail
# TODO flip to False
u = get_user_model().objects.create_user(username, email, password, is_active=True)
is_active = not s.ADMIN_APPROVAL_REQUIRED
if 'is_active' in kwargs:
is_active = kwargs['is_active']
u = get_user_model().objects.create_user(username, email, password, is_active=is_active)
# Create package
package_name = f"{u.username}{'' if u.username[-1] in 'sxzß' else 's'} Package"