Skip to content

Commit

Permalink
Merge pull request #223 from CUCWD/feature.nutmeg/figures
Browse files Browse the repository at this point in the history
Merge in prior release changes for figures analytics
  • Loading branch information
becdavid authored Jan 22, 2024
2 parents fb2b5f0 + 1eb03df commit 6b48f9f
Show file tree
Hide file tree
Showing 9 changed files with 417 additions and 19 deletions.
35 changes: 35 additions & 0 deletions common/djangoapps/student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import hashlib # lint-amnesty, pylint: disable=wrong-import-order
import json # lint-amnesty, pylint: disable=wrong-import-order
import logging # lint-amnesty, pylint: disable=wrong-import-order
import six # lint-amnesty, pylint: disable=wrong-import-order
import uuid # lint-amnesty, pylint: disable=wrong-import-order
from collections import defaultdict, namedtuple # lint-amnesty, pylint: disable=wrong-import-order
from datetime import date, datetime, timedelta # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -67,6 +68,10 @@
COURSE_UNENROLLMENT_COMPLETED,
)
from openedx_filters.learning.filters import CourseEnrollmentStarted, CourseUnenrollmentStarted

from organizations import api as organizations_api
from organizations.models import Organization, UserOrganizationMapping

import openedx.core.djangoapps.django_comment_common.comment_client as cc
from common.djangoapps.course_modes.models import CourseMode, get_cosmetic_verified_display_price
from common.djangoapps.student.emails import send_proctoring_requirements_email
Expand Down Expand Up @@ -1712,6 +1717,36 @@ def enroll(cls, user, course_key, mode=None, check_access=False, can_upgrade=Fal
)
)

# Mapping a user to an organization for Figures analytics.
organization_data = organizations_api.get_course_organizations(six.text_type(course_key))
if len(organization_data):
organization = Organization.objects.get(id=organization_data[0].get('id'))

try:
user_org = UserOrganizationMapping.objects.filter(
user=user,
organization=organization
).first()
if not user_org:
UserOrganizationMapping.objects.create(
user=user,
organization=organization,
is_active=True,
is_amc_admin=False
)
else:
# Enable `is_active` for the user_org record if it already exists in
# the database.
user_org.is_active = True
user_org.save()

except Exception as excep: # lint-amnesty, pylint: disable=broad-except
log.error("Could not create UserOrganizationMapping for org %s, user %s\n%s",
organization.name,
user.username,
excep
)

return enrollment

@classmethod
Expand Down
56 changes: 49 additions & 7 deletions lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,23 +638,65 @@
# Tests are not behind any proxies
CLOSEST_CLIENT_IP_FROM_HEADERS = []

#################### BigCommerce Settings #######################
#################### OpenBadges Settings #######################

FEATURES.update({
# FEATURES['ENABLE_OPENBADGES'] = True

# Enable BigCommerce feature.
'ENABLE_BIGCOMMERCE': True,
# Be sure to set up images for course modes using the BadgeImageConfiguration model in
# the certificates app.
# BADGR_API_VERSION = "v2"
# BADGR_API_TOKEN_EXPIRATION = 86400
# BADGR_API_TOKEN = "FymTGk7wQ3hR268JwS00ngkefdA0GR" # "0WVtn1RWangTSBqf5DDNvEdMTCvSL0"
# BADGR_API_REFRESH_TOKEN = "F0HDDPNHK1ZBnSVXpMYHslRiD6Qdir" # Ur7ZWamo8pwaPkK3dim124ak7c1YPG"

})
# BADGR_USERNAME = "[email protected]"
# BADGR_PASSWORD = "Ca2ves2018"
# BADGR_TOKENS_CACHE_KEY = "badgr_api_token_cache"
BADGR_API_TOKEN_CACHE = 'default'

# Do not add the trailing slash here.
# BADGR_BASE_URL = "https://api.badgr.io"
# BADGR_ISSUER_SLUG = "abcdefghijklmnopqrstuv" # This override defined in Site Configuration

# Number of seconds to wait on the badging server when contacting it before giving up.
# Already set in edx-platform/lms/envs/common.py
# BADGR_TIMEOUT = 10

# Only for v1 Badgr API
# BADGR_API_NOTIFICATIONS_ENABLED = True

# BADGR_PUBLIC_URL = "https://badgr.io"

# if FEATURES.get('ENABLE_OPENBADGES'):
# course_badges_templates_dir = OPENEDX_ROOT / 'features' / 'course_badges' / 'templates'
# if course_badges_templates_dir not in MAKO_TEMPLATE_DIRS_BASE:
# MAKO_TEMPLATE_DIRS_BASE.insert(0, course_badges_templates_dir)

# BADGR_ENABLE_NOTIFICATIONS = True

#################### BigCommerce Settings #######################

FEATURES['ENABLE_BIGCOMMERCE'] = True

if FEATURES.get('ENABLE_BIGCOMMERCE'):
BIGCOMMERCE_APP_ACCESS_TOKEN = "rg2zptq3s9x1nzh8sttgy8zcjgd9gyu"
BIGCOMMERCE_APP_CLIENT_ID = "6ms4rvrkhnv5m3h1o582mtqb7wzixyr"
BIGCOMMERCE_APP_CLIENT_SECRET = "385d434a82fe40cd838ad5891bdbc1548209547112f1e81c4b16bc2842d1a329"
BIGCOMMERCE_APP_STORE_HASH = "1nol3cto8"
BIGCOMMERCE_APP_STORE_URL = "https://educateworkforce-development.mybigcommerce.com"

INSTALLED_APPS.append('bigcommerce')

#################### OpenBadges Settings #######################
INSTALLED_APPS.append('social_auth_backend_bigcommerce')

BADGR_API_TOKEN_CACHE = 'default'
##### Third-party auth options
# Order of AUTHENTICATION_BACKENDS matters. See https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#specifying-authentication-backends # lint-amnesty, pylint: disable=line-too-long
################################################
if FEATURES.get('ENABLE_THIRD_PARTY_AUTH'):
tmp_backends = [
'social_auth_backend_bigcommerce.backend.BigCommerceCustomerDefaultAuth',
'social_auth_backend_bigcommerce.backend.BigCommerceCustomerTrustworksAuth',
]

AUTHENTICATION_BACKENDS = list(tmp_backends) + list(AUTHENTICATION_BACKENDS)
del tmp_backends
4 changes: 3 additions & 1 deletion requirements/edx/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ edx-drf-extensions
edx-enterprise
edx-milestones
edx-name-affirmation
edx-organizations
# edx-organizations # Using our own CUCWD verison for EducateWorkforce
edx-proctoring>=2.0.1
edx-proctoring-proctortrack==1.0.5 # Intentionally and permanently pinned to ensure code changes are reviewed
edx-rest-api-client
Expand Down Expand Up @@ -174,3 +174,5 @@ xblock-utils # Provides utilities used by the Discussion
xss-utils # https://github.com/edx/edx-platform/pull/20633 Fix XSS via Translations
enmerkar-underscore # Implements a underscore extractor for django-babel.
xblock-drag-and-drop-v2 # Drag and Drop XBlock

-r private.txt # Include our EducateWorkforce specific packages
11 changes: 10 additions & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ edx-opaque-keys[django]==2.3.0
# openedx-events
# ora2
# xmodule
edx-organizations==6.11.1
# Using our own CUCWD verison for EducateWorkforce
# edx-organizations==6.10.0
# via -r requirements/edx/base.in
edx-proctoring==4.10.2
# via
Expand Down Expand Up @@ -1142,3 +1143,11 @@ zipp==3.8.0

# The following packages are considered to be unsafe in a requirements file:
# setuptools

# EducateWorkforce specific packages. This was manually added because `make upgrade` was causing a lot of packages to update. This limits the Python package changes for the release.
-e git+https://github.com/CUCWD/[email protected]#egg=bigcommerce==0.22.2
# via -r ./requirements/edx/private.txt
-e git+https://github.com/CUCWD/[email protected]#egg=edx-organizations==6.10.0-cucwd-maple.1
# via -r ./requirements/edx/private.txt
-e git+https://github.com/CUCWD/[email protected]#egg=social-auth-backend-bigcommerce==0.1.0-maple.1
# via -r ./requirements/edx/private.txt
2 changes: 2 additions & 0 deletions requirements/edx/development.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ mypy # static type checking
pywatchman # More efficient checking for runserver reload trigger events
sphinxcontrib-openapi[markdown]==0.6.0 # OpenAPI (fka Swagger) spec renderer for Sphinx; pinned because 0.70 requires Python >=3.6
vulture # Detects possible dead/unused code, used in scripts/find-dead-code.sh

-r private.txt # Include our EducateWorkforce specific packages
13 changes: 8 additions & 5 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ edx-opaque-keys[django]==2.3.0
# openedx-events
# ora2
# xmodule
edx-organizations==6.11.1
# Using our own CUCWD verison for EducateWorkforce
# edx-organizations==6.10.0
# via -r requirements/edx/testing.txt
edx-proctoring==4.10.2
# via
Expand Down Expand Up @@ -1649,7 +1650,9 @@ zipp==3.8.0
# setuptools

# EducateWorkforce specific packages. This was manually added because `make upgrade` was causing a lot of packages to update. This limits the Python package changes for the release.
-e git+https://github.com/CUCWD/[email protected]#egg=bigcommerce==0.22.2
# via -r ./requirements/edx/private.in
-e git+https://github.com/CUCWD/[email protected]#egg=social-auth-backend-bigcommerce==0.1.0-maple.1
# via -r ./requirements/edx/private.in
-e git+https://github.com/CUCWD/[email protected]#egg=bigcommerce==0.22.2
# via -r ./requirements/edx/private.txt
-e git+https://github.com/CUCWD/[email protected]#egg=edx-organizations==6.11.1
# via -r ./requirements/edx/private.txt
-e git+https://github.com/CUCWD/[email protected]#egg=social-auth-backend-bigcommerce==0.1.0-maple.1
# via -r ./requirements/edx/private.txt
2 changes: 2 additions & 0 deletions requirements/edx/private.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
-e git+https://github.com/CUCWD/[email protected]#egg=bigcommerce==0.22.2
-e git+https://github.com/CUCWD/[email protected]#egg=social-auth-backend-bigcommerce==0.1.0-maple.1

# Organizations (reworked for Figures)
-e git+https://github.com/CUCWD/[email protected]#egg=edx-organizations==6.10.0-cucwd-maple.1
Loading

0 comments on commit 6b48f9f

Please sign in to comment.