From 1455542627118ffbedff1f7dc9d340ad5862e929 Mon Sep 17 00:00:00 2001 From: Alfred Chavez Date: Mon, 21 Jun 2021 09:06:26 -0500 Subject: [PATCH] feat: redirect to 'contact' page if zendesk url is not defined --- lms/djangoapps/support/tests/test_views.py | 12 ++++++++++++ lms/djangoapps/support/views/contact_us.py | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/lms/djangoapps/support/tests/test_views.py b/lms/djangoapps/support/tests/test_views.py index 684b760862..104d670015 100644 --- a/lms/djangoapps/support/tests/test_views.py +++ b/lms/djangoapps/support/tests/test_views.py @@ -15,6 +15,7 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imp from django.db.models import signals from django.http import HttpResponse from django.urls import reverse +from django.test.utils import override_settings from organizations.tests.factories import OrganizationFactory from pytz import UTC from social_django.models import UserSocialAuth @@ -65,11 +66,14 @@ class SupportViewManageUserTests(SupportViewTestCase): Base class for support view tests. """ + ZENDESK_URL = 'http://zendesk.example.com/' + def setUp(self): """Make the user support staff""" super().setUp() SupportStaffRole().add_users(self.user) + @override_settings(ZENDESK_URL=ZENDESK_URL) def test_get_contact_us(self): """ Tests Support View contact us Page @@ -78,6 +82,14 @@ class SupportViewManageUserTests(SupportViewTestCase): response = self.client.get(url) assert response.status_code == 200 + def test_get_contact_us_redirect_if_undefined_zendesk_url(self): + """ + Tests the Support contact us Page redirects if ZENDESK_URL setting is not defined + """ + url = reverse('support:contact_us') + response = self.client.get(url) + assert response.status_code == 302 + def test_get_password_assistance(self): """ Tests password assistance diff --git a/lms/djangoapps/support/views/contact_us.py b/lms/djangoapps/support/views/contact_us.py index 180276a400..4ba2d46634 100644 --- a/lms/djangoapps/support/views/contact_us.py +++ b/lms/djangoapps/support/views/contact_us.py @@ -5,6 +5,7 @@ Signle support contact view from django.conf import settings from django.http import Http404 +from django.shortcuts import redirect from django.views.generic import View from common.djangoapps.edxmako.shortcuts import render_to_response @@ -19,6 +20,11 @@ class ContactUsView(View): """ def get(self, request): # lint-amnesty, pylint: disable=missing-function-docstring + # If ZENDESK_URL is not defined, then it will redirect to the static contact page + # to avoid 500 error that arises due to missing Zendesk configuration + if not settings.ZENDESK_URL: + return redirect('contact') + if not configuration_helpers.get_value('CONTACT_US_PAGE', True): raise Http404