Skip to content

Commit

Permalink
Update models.py
Browse files Browse the repository at this point in the history
avoid sending mail when password provided for superuser creation.
Improve logs.
  • Loading branch information
eric-intuitem committed Feb 22, 2024
1 parent 226ac96 commit c6caa6b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/iam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down

0 comments on commit c6caa6b

Please sign in to comment.