Skip to content

Commit

Permalink
Add Contact Us form customization options (openedx#163)
Browse files Browse the repository at this point in the history
* Add Contact Us form customization options

This commit adds personalization options for the Contact Us links on
edx-platform's
page.
To allow for this customization, two SiteConfiguration variables were
added:
* CONTACT_US_ENABLE: Switch to enable/disable the Contact Us page.
Setting this to
False will disable the contact page and the links on the footer will
disappear.

* CONTACT_US_CUSTOM_LINK: If the contact page is enabled, this setting
allows to set
a custom URL for the Contact Us links on edx-platform. If this setting
is not set,
the platform will use the default contact form.

* Apply suggestions from code review

Co-Authored-By: xitij2000 <[email protected]>
  • Loading branch information
xitij2000 authored Apr 22, 2019
1 parent 6639bf8 commit 43440bc
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 22 deletions.
101 changes: 79 additions & 22 deletions lms/djangoapps/branding/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,50 +170,107 @@ def _footer_social_links():
return links


def _footer_connect_links():
def _build_support_form_url(full_path=False):
"""
Return the support form path
Returns url of support form, which can have 3 possible values:
- '' if the contact form is disabled (by setting SiteConfiguration
`CONTACT_US_ENABLE = False`)
- The normal edx support form path using reverse("support:contact_us") if
`CONTACT_US_ENABLE = True` and a custom link isn't set on
CONTACT_US_CUSTOM_LINK. There's the optional parameter `full_path`, that
if set to True will append the LMS base url to the relative path before
returning.
- CONTACT_US_CUSTOM_LINK if the the user has set a custom URL redirect
for support forms (by setting `CONTACT_US_ENABLE = True` and
`CONTACT_US_CUSTOM_LINK = http://some.url/for/contact`).
If this is set, the returned link is the content of
CONTACT_US_CUSTOM_LINK and the `full_path` variable is ignored since this
is a path outside the LMS
Parameters:
- full_path: bool. Appends base_url to returned value if
`CONTACT_US_ENABLE = True`and no link is set on
`CONTACT_US_CUSTOM_LINK`
Returns: string
"""
contact_us_page = ''

if configuration_helpers.get_value('CONTACT_US_ENABLE', True):
# Gets custom url ad check if it's enabled
contact_us_page = configuration_helpers.get_value('CONTACT_US_CUSTOM_LINK', '')

# If no custom link is set, get default support form using reverse
if not contact_us_page:
contact_us_page = reverse("support:contact_us")

# Prepend with lms base_url if specified by `full_path`
if full_path:
contact_us_page = '{}{}'.format(settings.LMS_ROOT_URL, contact_us_page)

return contact_us_page


def _footer_connect_links(language=settings.LANGUAGE_CODE):
"""Return the connect links to display in the footer. """
links = [
("blog", (marketing_link("BLOG"), _("Blog"))),
("contact", (_build_support_form_url(full_path=True), _("Contact Us"))),
("help-center", (settings.SUPPORT_SITE_LINK, _("Help Center"))),
]

if language == settings.LANGUAGE_CODE:
links.append(("media_kit", (marketing_link("MEDIA_KIT"), _("Media Kit"))))
links.append(("donate", (marketing_link("DONATE"), _("Donate"))))

return [
{
"name": link_name,
"title": link_title,
"url": link_url,
}
for link_name, link_url, link_title in [
("blog", marketing_link("BLOG"), _("Blog")),
("contact", _build_support_form_url(), _("Contact Us")),
("help-center", settings.SUPPORT_SITE_LINK, _("Help Center")),
("media_kit", marketing_link("MEDIA_KIT"), _("Media Kit")),
("donate", marketing_link("DONATE"), _("Donate")),
]
for link_name, (link_url, link_title) in links
if link_url and link_url != "#"
]


def _build_support_form_url():
return '{base_url}/support/contact_us'.format(base_url=settings.LMS_ROOT_URL)
def _find_position_of_link(links, key):
"Returns position of the link to be inserted"
for link in links:
if link[0] == key:
return links.index(link) + 1


def _footer_navigation_links():
def _footer_navigation_links(language=settings.LANGUAGE_CODE):
"""Return the navigation links to display in the footer. """
platform_name = configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME)
links = [
("about", (marketing_link("ABOUT"), _("About"))),
("enterprise", (marketing_link("ENTERPRISE"),
_("{platform_name} for Business").format(platform_name=platform_name))),
("blog", (marketing_link("BLOG"), _("Blog"))),
("help-center", (settings.SUPPORT_SITE_LINK, _("Help Center"))),
("contact", (_build_support_form_url(), _("Contact"))),
("careers", (marketing_link("CAREERS"), _("Careers"))),
("donate", (marketing_link("DONATE"), _("Donate"))),
]

if language == settings.LANGUAGE_CODE:
position = _find_position_of_link(links, 'blog')
links.insert(position, ("news", (marketing_link("NEWS"), _("News"))))

return [
{
"name": link_name,
"title": link_title,
"url": link_url,
}
for link_name, link_url, link_title in [
("about", marketing_link("ABOUT"), _("About")),
("enterprise", marketing_link("ENTERPRISE"),
_("{platform_name} for Business").format(platform_name=platform_name)),
("blog", marketing_link("BLOG"), _("Blog")),
("news", marketing_link("NEWS"), _("News")),
("help-center", settings.SUPPORT_SITE_LINK, _("Help Center")),
("contact", reverse("support:contact_us"), _("Contact")),
("careers", marketing_link("CAREERS"), _("Careers")),
("donate", marketing_link("DONATE"), _("Donate")),
]
for link_name, (link_url, link_title) in links
if link_url and link_url != "#"
]

Expand Down
40 changes: 40 additions & 0 deletions lms/djangoapps/branding/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
from branding.api import get_footer, get_home_url, get_logo_url
from edxmako.shortcuts import marketing_link

from openedx.core.djangoapps.site_configuration.tests.test_util import (
with_site_configuration,
)

test_config_disabled_contact_us = { # pylint: disable=invalid-name
"CONTACT_US_ENABLE": False,
}

test_config_custom_url_contact_us = { # pylint: disable=invalid-name
"CONTACT_US_ENABLE": True,
"CONTACT_US_CUSTOM_LINK": "https://open.edx.org/",
}


class TestHeader(TestCase):
"""Test API end-point for retrieving the header. """
Expand Down Expand Up @@ -151,3 +164,30 @@ def test_get_footer(self):
},
}
self.assertEqual(actual_footer, expected_footer)

@with_site_configuration(configuration=test_config_disabled_contact_us)
def test_get_footer_disabled_contact_form(self):
"""
Test retrieving the footer with disabled contact form.
"""
actual_footer = get_footer(is_secure=True)
self.assertEqual(any(l['name'] == 'contact' for l in actual_footer['connect_links']), False)
self.assertEqual(any(l['name'] == 'contact' for l in actual_footer['navigation_links']), False)

@with_site_configuration(configuration=test_config_custom_url_contact_us)
def test_get_footer_custom_contact_url(self):
"""
Test retrieving the footer with custom contact form url.
"""
actual_footer = get_footer(is_secure=True)
contact_us_link = [l for l in actual_footer['connect_links'] if l['name'] == 'contact'][0]
self.assertEqual(
contact_us_link['url'],
test_config_custom_url_contact_us['CONTACT_US_CUSTOM_LINK']
)

navigation_link_contact_us = [l for l in actual_footer['navigation_links'] if l['name'] == 'contact'][0]
self.assertEqual(
navigation_link_contact_us['url'],
test_config_custom_url_contact_us['CONTACT_US_CUSTOM_LINK']
)
4 changes: 4 additions & 0 deletions lms/djangoapps/support/views/contact_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Signle support contact view
"""
from django.conf import settings
from django.http import Http404
from django.views.generic import View
from edxmako.shortcuts import render_to_response
from student.models import CourseEnrollment
Expand All @@ -16,6 +17,9 @@ class ContactUsView(View):
"""

def get(self, request):
if not configuration_helpers.get_value('CONTACT_US_ENABLE', True):
raise Http404

context = {
'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME),
'support_email': configuration_helpers.get_value('CONTACT_EMAIL', settings.CONTACT_EMAIL),
Expand Down

0 comments on commit 43440bc

Please sign in to comment.