Skip to content

Commit

Permalink
fix: organisation integrity error during user registration
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedykori committed Aug 31, 2021
1 parent 9f94005 commit d7ec446
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@
ORGANISATION_EMAIL = env("ORGANISATION_EMAIL", default="info@savannahghi.org")
ORGANISATION_PHONE = env("ORGANISATION_PHONE", default="+254790360360")

# used by the user model to assign a default organisation to a user during creation
DEFAULT_ORG_ID = env("DEFAULT_ORG_ID", default="4181df12-ca96-4f28-b78b-8e8ad88b25df")

# BigAutoField needs migration of existing data and either changes to
# dependencies or overriding dependencies
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
Expand Down
7 changes: 3 additions & 4 deletions fahari/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField

DEFAULT_ORG_ID = "4181df12-ca96-4f28-b78b-8e8ad88b25df"
DEFAULT_ORG_CODE = 1


def default_organisation():
try:
from fahari.common.models import Organisation # intentional late imoort
from fahari.common.models import Organisation # intentional late import

org, _ = Organisation.objects.get_or_create(
code=DEFAULT_ORG_CODE,
id=DEFAULT_ORG_ID,
id=settings.DEFAULT_ORG_ID,
defaults={
"organisation_name": settings.ORGANISATION_NAME,
"email_address": settings.ORGANISATION_EMAIL,
Expand All @@ -28,7 +27,7 @@ def default_organisation():
return org.pk
except (ProgrammingError, Exception): # pragma: nocover
# this will occur during initial migrations on a clean db
return DEFAULT_ORG_ID
return settings.DEFAULT_ORG_ID


class User(AbstractUser):
Expand Down

0 comments on commit d7ec446

Please sign in to comment.