Commit 293bd30a by Nate Hardison Committed by Joe Blaylock

Use chat settings when deciding whether to render

Only render the chat widget if both the site has enabled it in the
`MITX_FEATURES` and if the course has enabled it. In addition, fail
gracefully with a log warning if the `JABBER_DOMAIN` is not set, and
do not try to render the widget. However, do go ahead and render the
rest of the courseware.
parent 3aec9fdb
......@@ -240,21 +240,27 @@ def chat_settings(course, user):
Returns a dict containing the settings required to connect to a
Jabber chat server and room.
"""
domain = getattr(settings, "JABBER_DOMAIN", None)
if domain is None:
log.warning('You must set JABBER_DOMAIN in the settings to '
'enable the chat widget')
return None
return {
'domain': settings.JABBER_DOMAIN,
'domain': domain,
# Jabber doesn't like slashes, so replace with dashes
'room': "{ID}_class".format(ID=course.id.replace('/', '-')),
'username': "{USER}@{DOMAIN}".format(
USER=user.username, DOMAIN=settings.JABBER_DOMAIN
USER=user.username, DOMAIN=domain
),
# TODO: clearly this needs to be something other than the username
# should also be something that's not necessarily tied to a
# particular course
'password': "{USER}@{DOMAIN}".format(
USER=user.username, DOMAIN=settings.JABBER_DOMAIN
USER=user.username, DOMAIN=domain
),
}
......@@ -323,8 +329,17 @@ def index(request, course_id, chapter=None, section=None,
'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:server@content-qa.mitx.mit.edu/xqa')
}
if course.show_chat:
# Only show the chat if it's enabled by the course and in the
# settings.
show_chat = course.show_chat and settings.MITX_FEATURES['ENABLE_CHAT']
if show_chat:
context['chat'] = chat_settings(course, user)
# If we couldn't load the chat settings, then don't show
# the widget in the courseware.
if context['chat'] is None:
show_chat = False
context['show_chat'] = show_chat
chapter_descriptor = course.get_child_by(lambda m: m.url_name == chapter)
if chapter_descriptor is not None:
......
......@@ -6,7 +6,7 @@
<%block name="headextra">
<%static:css group='course'/>
<%include file="../discussion/_js_head_dependencies.html" />
% if course.show_chat:
% if show_chat:
<link rel="stylesheet" href="${static.url('css/vendor/ui-lightness/jquery-ui-1.8.22.custom.css')}" />
## It'd be better to have this in a place like lms/css/vendor/candy,
## but the candy_res/ folder contains images and other junk, and it
......@@ -115,7 +115,7 @@
</script>
% endif
% if course.show_chat:
% if show_chat:
<script type="text/javascript" src="${static.url('js/vendor/candy_libs/libs.min.js')}"></script>
<script type="text/javascript" src="${static.url('js/vendor/candy.min.js')}"></script>
......@@ -189,7 +189,7 @@
</div>
</section>
% if course.show_chat:
% if show_chat:
<div id="chat-wrapper">
<div id="chat-toggle" class="closed">
<span id="chat-open">Open Chat <em class="icon-chevron-up"></em></span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment