Skip to content

Commit

Permalink
Merge pull request #324 from ucsd-ets/release-candidate
Browse files Browse the repository at this point in the history
Release- 2020.03.11 [Prod]
  • Loading branch information
tehreem-sadat authored Mar 13, 2020
2 parents c62cdb0 + 0c8224c commit 831b78d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,4 +1571,5 @@

############## UCSD Features #########################

GOOGLE_ANALYTICS_EVENTS_COOKIE_NAME = 'ga_events'
FEATURES['DISABLE_REFUND_FAILURE_NOTIFICATION'] = True
3 changes: 2 additions & 1 deletion common/djangoapps/student/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,11 @@ def student_dashboard(request):

# Display activation message
activate_account_message = ''
activation_email_support_link = 'http://edtech.ucsd.edu/uc-san-diego-online-help'
if not user.is_active:
activate_account_message = Text(_(
"Check your {email_start}{email}{email_end} inbox for an account activation link from {platform_name}. "
"If you need help, contact <a href='https://edtech.ucsd.edu/uc-san-diego-online-help'> {platform_name} Support</a>."
"If you need help, visit the {link_start}{platform_name} Help Center{link_end}."
)).format(
platform_name=platform_name,
email_start=HTML("<strong>"),
Expand Down
27 changes: 25 additions & 2 deletions common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
from openedx.core.djangoapps.catalog.utils import get_programs_with_type
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.embargo import api as embargo_api
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from openedx.core.djangoapps.oauth_dispatch.api import destroy_oauth_tokens
Expand All @@ -66,6 +67,7 @@
from openedx.features.ucsd_features.ecommerce.EcommerceClient import EcommerceRestAPIClient
from openedx.features.ucsd_features.ecommerce.tasks import assign_course_voucher_to_user
from openedx.features.ucsd_features.ecommerce.constants import IS_DISCOUNT_AVAILABLE_QUERY_PARAM
from openedx.features.ucsd_features.utils import add_to_ga_events_cookie

from openedx.core.djangolib.markup import HTML, Text
from openedx.features.journals.api import get_journals_context
Expand Down Expand Up @@ -415,6 +417,9 @@ def change_enrollment(request, check_access=True):
# then send the user to the choose your track page.
# (In the case of no-id-professional/professional ed, this will redirect to a page that
# funnels users directly into the verification / payment flow)

response = HttpResponse()

if CourseMode.has_verified_mode(available_modes) or CourseMode.has_professional_mode(available_modes):
# [UCSD_CUSTOM] Enable geographic country based discounts on course enrollments
redirect_url = reverse("course_modes_choose", kwargs={'course_id': text_type(course_id)})
Expand Down Expand Up @@ -450,10 +455,28 @@ def change_enrollment(request, check_access=True):
error=ex.message
))

return HttpResponse(redirect_url)
response = HttpResponse(redirect_url)

if hasattr(settings, 'GOOGLE_ANALYTICS_ACCOUNT'):
domain = getattr(settings, 'BASE_COOKIE_DOMAIN')
event_action = 'enrollment'

try:
course_overview = CourseOverview.get_from_id(course_id)
course_title = course_overview.display_name
except CourseOverview.DoesNotExist:
log.exception('CourseOverview object not found for key: {}'.format(course_id))
course_title = str(course_id)

ga_event = {
'event_category': 'course_audit',
'event_label': course_title,
'value': str(course_id)
}
add_to_ga_events_cookie(request, response, 'enroll', ga_event, domain=domain)

# Otherwise, there is only one mode available (the default)
return HttpResponse()
return response
elif action == "unenroll":
enrollment = CourseEnrollment.get_enrollment(user, course_id)
if not enrollment:
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3487,7 +3487,7 @@ def _make_locale_paths(settings):


############## UCSD Features #########################

GOOGLE_ANALYTICS_EVENTS_COOKIE_NAME = 'ga_events'
FEATURES['AUTOMATIC_PERMANENT_ACCOUNT_VERIFICATION'] = True
FEATURES['DISABLE_REFUND_FAILURE_NOTIFICATION'] = True
FEATURES['ENABLE_GEOGRAPHIC_DISCOUNTS'] = True
Expand Down
34 changes: 34 additions & 0 deletions openedx/features/ucsd_features/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import json
import logging

Expand Down Expand Up @@ -92,3 +93,36 @@ def get_course_name(custom_fields):
except InvalidKeyError:
return None
return course_name


def add_to_ga_events_cookie(request, response, event_name, event_data, **cookie_options):
"""
Adds the provided event_data to a cookie whose name is configured through GOOGLE_ANALYTICS_EVENTS_COOKIE_NAME
settings variable. If there is already a cookie with this name, append the event to `events` list in that cookie.
Otherwise, make a new cookie.
Arguments:
request: Request object from which we can get the already set cookie
response: Response object using which the cookie will be set
event_name: the will be used as event action when emitting GA event from browser
event_data: event data that will be emitted
**cookie_options: Any other options that can be used while setting the cookie, e.g. domain of the cookie
"""
cookie_name = settings.GOOGLE_ANALYTICS_EVENTS_COOKIE_NAME

ga_events_cookie = request.COOKIES.get(cookie_name)

if ga_events_cookie:
decoded_cookie = base64.b64decode(ga_events_cookie)
events_data = json.loads(decoded_cookie)
else:
events_data = {}

events_data['events'] = events_data.get('events') or []
events_data['events'].append({
'event_name': event_name,
'event_data': event_data
})
encoded_cookie = base64.b64encode(json.dumps(events_data))
response.set_cookie(cookie_name, encoded_cookie, **cookie_options)

0 comments on commit 831b78d

Please sign in to comment.