Skip to content

Commit

Permalink
Revert "Support different landing pages on the same webworker"
Browse files Browse the repository at this point in the history
  • Loading branch information
emord committed Jan 17, 2019
1 parent 8c0c415 commit ce6b6f1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 60 deletions.
21 changes: 7 additions & 14 deletions corehq/apps/hqwebapp/views.py
@@ -1,8 +1,6 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import functools
import json
import logging
import os
Expand All @@ -13,6 +11,7 @@
from datetime import datetime
from six.moves.urllib.parse import urlparse

import functools
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
Expand Down Expand Up @@ -339,7 +338,7 @@ def csrf_failure(request, reason=None, template_name="csrf_failure.html"):


@sensitive_post_parameters('auth-password')
def _login(req, domain_name):
def _login(req, domain_name, template_name):

if req.user.is_authenticated and req.method == "GET":
redirect_to = req.GET.get('next', '')
Expand All @@ -364,15 +363,9 @@ def _login(req, domain_name):
req.base_template = settings.BASE_TEMPLATE

context = {}
template_name = 'login_and_password/login.html'
custom_landing_page = settings.CUSTOM_LANDING_TEMPLATE
custom_landing_page = getattr(settings, 'CUSTOM_LANDING_TEMPLATE', False)
if custom_landing_page:
if isinstance(custom_landing_page, six.string_types):
template_name = custom_landing_page
else:
template_name = custom_landing_page.get(req.get_host())
if template_name is None:
template_name = custom_landing_page.get('default', template_name)
template_name = custom_landing_page
elif domain_name:
domain = Domain.get_by_name(domain_name)
req_params = req.GET if req.method == 'GET' else req.POST
Expand Down Expand Up @@ -416,11 +409,11 @@ def login(req):

req_params = req.GET if req.method == 'GET' else req.POST
domain = req_params.get('domain', None)
return _login(req, domain)
return _login(req, domain, "login_and_password/login.html")


@location_safe
def domain_login(req, domain):
def domain_login(req, domain, template_name="login_and_password/login.html"):
# This is a wrapper around the _login view which sets a different template
project = Domain.get_by_name(domain)
if not project:
Expand All @@ -430,7 +423,7 @@ def domain_login(req, domain):
# necessary domain contexts:
req.project = project

return _login(req, domain)
return _login(req, domain, template_name)


class HQLoginView(LoginView):
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/reports/dispatcher.py
Expand Up @@ -219,7 +219,7 @@ def navigation_sections(cls, request, domain):
and (show_in_navigation or show_in_dropdown)
):
report_contexts.append({
'url': report.get_url(domain=domain, request=request, relative=True),
'url': report.get_url(domain=domain, request=request),
'description': _(report.description),
'icon': report.icon,
'title': _(report.name),
Expand Down
32 changes: 7 additions & 25 deletions corehq/util/context_processors.py
Expand Up @@ -2,18 +2,16 @@
from __future__ import unicode_literals

import datetime

import six
from django.conf import settings
from django.http import Http404
from django.urls import resolve, reverse
from django.http import Http404
from django_prbac.utils import has_privilege
from ws4redis.context_processors import default

from corehq import privileges
from corehq.apps.accounting.models import BillingAccount
from corehq.apps.accounting.utils import domain_has_privilege
from corehq import privileges
from corehq.apps.hqwebapp.utils import get_environment_friendly_name
from corehq.apps.accounting.models import BillingAccount


COMMCARE = 'commcare'
COMMTRACK = 'commtrack'
Expand Down Expand Up @@ -153,28 +151,12 @@ def enterprise_mode(request):
def commcare_hq_names(request):
return {
'commcare_hq_names': {
'COMMCARE_NAME': _get_cc_name(request, 'COMMCARE_NAME'),
'COMMCARE_HQ_NAME': _get_cc_name(request, 'COMMCARE_HQ_NAME'),
},
'COMMCARE_NAME': settings.COMMCARE_NAME,
'COMMCARE_HQ_NAME': settings.COMMCARE_HQ_NAME
}
}


def _get_cc_name(request, var):
value = getattr(settings, var)
if isinstance(value, six.string_types):
return value
try:
host = request.get_host()
except KeyError:
# In reporting code we create an HttpRequest object inside python which
# does not have an HTTP_HOST attribute. Its unclear what host would be
# expected in that scenario, so we're showing the default.
# The true fix for this lies in removing fake requests from scheduled reports
host = 'default'

return value.get(host) or value.get('default')


def mobile_experience(request):
show_mobile_ux_warning = False
mobile_ux_cookie_name = ''
Expand Down
6 changes: 0 additions & 6 deletions custom/icds/tests/test_views.py
@@ -1,18 +1,12 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from django.test import TestCase
from django.test.utils import override_settings
from django.urls import reverse


class TestViews(TestCase):
@override_settings(CUSTOM_LANDING_TEMPLATE='icds/login.html')
def test_custom_login_old_format(self):
response = self.client.get(reverse("login"), follow=False)
self.assertEqual(response.status_code, 200)

@override_settings(CUSTOM_LANDING_TEMPLATE={"default": 'icds/login.html'})
def test_custom_login(self):
response = self.client.get(reverse("login"), follow=False)
self.assertEqual(response.status_code, 200)
18 changes: 4 additions & 14 deletions settings.py
Expand Up @@ -854,12 +854,10 @@

MOBILE_INTEGRATION_TEST_TOKEN = None

COMMCARE_HQ_NAME = {
"default": "CommCare HQ",
}
COMMCARE_NAME = {
"default": "CommCare",
}
# CommCare HQ - To indicate server
COMMCARE_HQ_NAME = "CommCare HQ"
# CommCare - To Indicate mobile
COMMCARE_NAME = "CommCare"

ENTERPRISE_MODE = False

Expand Down Expand Up @@ -892,14 +890,6 @@
UCR_COMPARISONS = {}

MAX_RULE_UPDATES_IN_ONE_RUN = 10000

# used for providing separate landing pages for different URLs
# default will be used if no hosts match
CUSTOM_LANDING_TEMPLATE = {
# "icds-cas.gov.in": 'icds/login.html',
# "default": 'login_and_password/login.html',
}

from env_settings import *

try:
Expand Down

0 comments on commit ce6b6f1

Please sign in to comment.