From c6caa6be78cc8f94088af3a24f9d53a1a0d1be2a Mon Sep 17 00:00:00 2001 From: eric-intuitem <71850047+eric-intuitem@users.noreply.github.com> Date: Thu, 22 Feb 2024 19:27:36 +0100 Subject: [PATCH] Update models.py avoid sending mail when password provided for superuser creation. Improve logs. --- backend/iam/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/iam/models.py b/backend/iam/models.py index 75f2b10bb..c49bdbf83 100644 --- a/backend/iam/models.py +++ b/backend/iam/models.py @@ -232,6 +232,7 @@ def _create_user(self, email, password, mailing=True, **extra_fields): subject=_("Welcome to Ciso Assistant!"), ) except Exception as exception: + print(f"sending email to {email} failed") raise exception return user @@ -247,14 +248,13 @@ def create_superuser(self, email, password=None, **extra_fields): extra_fields.setdefault("is_superuser", True) if extra_fields.get("is_superuser") is not True: raise ValueError("Superuser must have is_superuser=True.") - if not (EMAIL_HOST or EMAIL_HOST_RESCUE): - extra_fields.setdefault("mailing", False) + extra_fields.setdefault("mailing", not(password) and (EMAIL_HOST or EMAIL_HOST_RESCUE)) superuser = self._create_user(email, password, **extra_fields) # when possible, add superuser to admin group try: UserGroup.objects.get(name="BI-UG-ADM").user_set.add(superuser) except ObjectDoesNotExist: - pass + print("cannot add superuser to admin group - will be done on next startup") return superuser