Merge pull request #27950 from bitmakerla/alfredchavez/redirect-to-contact-page-if-zendesk-url-not-defined

feat: redirect to 'contact' page if zendesk url is not defined
This commit is contained in:
Syed Muhammad Dawoud Sheraz Ali
2021-06-21 21:13:55 +05:00
committed by GitHub
2 changed files with 18 additions and 0 deletions

View File

@@ -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
@@ -66,11 +67,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
@@ -79,6 +83,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

View File

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