Skip to content

Commit

Permalink
Merge pull request #409 from edly-io/farhan/badgr_debug
Browse files Browse the repository at this point in the history
Badgr Flow on Panel FE
  • Loading branch information
mfarhan943 authored Aug 22, 2023
2 parents 4dd60f7 + 99b1a8c commit 0fe52f9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
4 changes: 2 additions & 2 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@

ALLOWED_SITE_CONFIGURATIONS_OVERRIDE = [
'BRANDING', 'COLORS', 'ALLOW_PUBLIC_ACCOUNT_CREATION', 'REGISTRATION_EXTRA_FIELDS',
'EMAILS_CONFIG', 'DJANGO_SETTINGS_OVERRIDE', 'GTM_ID', 'GA_ID', 'MOBILE_ENABLED',
'EMAILS_CONFIG', 'DJANGO_SETTINGS_OVERRIDE', 'GTM_ID', 'GA_ID', 'MOBILE_ENABLED',
'MOBILE_APP_CONFIG'
]

Expand All @@ -780,7 +780,7 @@
'DEFAULT_FROM_EMAIL', 'BULK_EMAIL_DEFAULT_FROM_EMAIL',
'FEATURES', 'MKTG_URLS', 'MARKETING_SITE_ROOT',
'CORS_ORIGIN_WHITELIST', 'CURRENT_PLAN', 'LMS_SEGMENT_KEY', 'CMS_SEGMENT_KEY', 'BADGR_USERNAME', 'BADGR_PASSWORD',
'BADGR_ISSUER_SLUG', 'ENABLE_OPENBADGES',
'BADGR_ISSUER_SLUG', 'BADGR_FLAG'
]

# CORS CONFIG
Expand Down
23 changes: 1 addition & 22 deletions lms/djangoapps/badges/backends/badgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,28 +276,7 @@ def _get_access_token(self):
token is cached but expired, renew it. If all fails or a token has
not yet been cached, create a new one.
"""
tokens = {}
cached_response = TieredCache.get_cached_response(
settings.BADGR_TOKENS_CACHE_KEY)
if cached_response.is_found:
cached_tokens = cached_response.value
# add a 5 seconds buffer to the cutoff timestamp to make sure
# the token will not expire while in use
expiry_cutoff = (
datetime.datetime.utcnow() + datetime.timedelta(seconds=5))
if cached_tokens.get('expires_at') > expiry_cutoff:
tokens = cached_tokens
else:
# renew the tokens with the cached `refresh_token`
refresh_token = self._decrypt_token(cached_tokens.get(
'refresh_token'))
tokens = self._get_and_cache_oauth_tokens(
refresh_token=refresh_token)

# if no tokens are cached or something went wrong with
# retreiving/renewing them, go and create new tokens
if not tokens:
tokens = self._get_and_cache_oauth_tokens()
tokens = self._get_and_cache_oauth_tokens()
return self._decrypt_token(tokens.get('access_token'))

def _get_headers(self):
Expand Down
5 changes: 5 additions & 0 deletions lms/djangoapps/badges/events/course_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ def course_badge_check(user, course_key):
badgr_slug = get_value_from_django_settings_override('BADGR_ISSUER_SLUG', None, site)
badgr_username = get_value_from_django_settings_override('BADGR_USERNAME', None, site)
badgr_password = get_value_from_django_settings_override('BADGR_PASSWORD', None, site)
badgr_flag = get_value_from_django_settings_override('BADGR_FLAG', False, site)
badge_class = get_completion_badge(course_key, user)

if not badgr_flag:
return

if not badge_class:
# We're not configured to make a badge for this course mode.
return
Expand Down
11 changes: 11 additions & 0 deletions lms/djangoapps/certificates/views/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,18 @@ def _update_badge_context(context, course, user):
"""
Updates context with badge info.
"""
from figures.sites import get_site_for_course
from openedx.features.edly.utils import get_value_from_django_settings_override

badge = None
course_key = course.location.course_key
site = get_site_for_course(course_key)
badgr_flag = get_value_from_django_settings_override('BADGR_FLAG', False, site)

if not badgr_flag:
context['badge'] = badge
return

if badges_enabled() and course.issue_badges:
completion_badge = get_completion_badge(course.location.course_key, user)
if completion_badge is not None:
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
'REGISTRATION_EXTRA_FIELDS',
'CSRF_TRUSTED_ORIGINS', 'CORS_ORIGIN_WHITELIST', 'CURRENT_PLAN',
'LMS_SEGMENT_KEY', 'CMS_SEGMENT_KEY', 'BADGR_USERNAME', 'BADGR_PASSWORD',
'BADGR_ISSUER_SLUG', 'ENABLE_OPENBADGES',
'BADGR_ISSUER_SLUG', 'BADGR_FLAG'
]

ENABLE_SUBSCRIPTIONS_ON_RUNTIME_SWITCH = 'enable_subscriptions'
Expand Down

0 comments on commit 0fe52f9

Please sign in to comment.