Skip to content

Commit

Permalink
Merge pull request #4603 from kobotoolbox/2-023-21-domain-transfer
Browse files Browse the repository at this point in the history
Add support for old KoBoCAT domain name
  • Loading branch information
jnm committed Aug 30, 2023
2 parents 8e7f331 + a3bda92 commit 78ddfe0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions kobo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,12 @@ def __init__(self, *args, **kwargs):

# replace this with the pointer to the kobocat server, if it exists
KOBOCAT_URL = os.environ.get('KOBOCAT_URL', 'http://kobocat')

# In case server must serve two KoBoCAT domain names (e.g. during a
# domain name transfer), `settings.KOBOCAT_OLD_URL` adds support for
# the domain name.
KOBOCAT_OLD_URL = os.environ.get('KOBOCAT_OLD_URL')

KOBOCAT_INTERNAL_URL = os.environ.get('KOBOCAT_INTERNAL_URL',
'http://kobocat')

Expand Down
1 change: 0 additions & 1 deletion kpi/deployment_backends/kc_access/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.db.models import Model
from kobo_service_account.utils import get_request_headers
from rest_framework.authtoken.models import Token
from rest_framework import status

from kpi.exceptions import KobocatProfileException
from kpi.utils.log import logging
Expand Down
7 changes: 6 additions & 1 deletion kpi/deployment_backends/kobocat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,13 @@ def external_to_internal_url(url):
`settings.KOBOCAT_INTERNAL_URL` when it appears at the beginning of
`url`
"""
kobocat_url = settings.KOBOCAT_URL
# If old domain name is detected, use it for search&replace below
if settings.KOBOCAT_OLD_URL and settings.KOBOCAT_OLD_URL in url:
kobocat_url = settings.KOBOCAT_OLD_URL

return re.sub(
pattern='^{}'.format(re.escape(settings.KOBOCAT_URL)),
pattern='^{}'.format(re.escape(kobocat_url)),
repl=settings.KOBOCAT_INTERNAL_URL,
string=url
)
Expand Down

0 comments on commit 78ddfe0

Please sign in to comment.