Commit 38e88e30 by John Eskew

Check for empty URL and api key before old analytics api call.

Encode course key as a URL parameter.
parent 37949e07
......@@ -25,6 +25,7 @@ from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbid
from django.utils.html import strip_tags
import string # pylint: disable=W0402
import random
import urllib
from util.json_request import JsonResponse
from instructor.views.instructor_task_helpers import extract_email_features, extract_task_features
......@@ -1791,13 +1792,15 @@ def proxy_legacy_analytics(request, course_id):
analytics_name = request.GET.get('aname')
# abort if misconfigured
if not (hasattr(settings, 'ANALYTICS_SERVER_URL') and hasattr(settings, 'ANALYTICS_API_KEY')):
if not (hasattr(settings, 'ANALYTICS_SERVER_URL') and
hasattr(settings, 'ANALYTICS_API_KEY') and
settings.ANALYTICS_SERVER_URL and settings.ANALYTICS_API_KEY):
return HttpResponse("Analytics service not configured.", status=501)
url = "{}get?aname={}&course_id={}&apikey={}".format(
settings.ANALYTICS_SERVER_URL,
analytics_name,
course_id.to_deprecated_string(),
urllib.quote(course_id.to_deprecated_string()),
settings.ANALYTICS_API_KEY,
)
......
......@@ -11,6 +11,7 @@ import logging
import os
import re
import requests
import urllib
from collections import defaultdict, OrderedDict
from markupsafe import escape
......@@ -910,7 +911,7 @@ def instructor_dashboard(request, course_id):
"""
url = settings.ANALYTICS_SERVER_URL + \
u"get?aname={}&course_id={}&apikey={}".format(
analytics_name, course_key.to_deprecated_string(), settings.ANALYTICS_API_KEY
analytics_name, urllib.quote(unicode(course_key)), settings.ANALYTICS_API_KEY
)
try:
res = requests.get(url)
......
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