diff --git a/cms/envs/common.py b/cms/envs/common.py index 5a538e1547d9..318d12a31497 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -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' ] @@ -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 diff --git a/lms/djangoapps/badges/backends/badgr.py b/lms/djangoapps/badges/backends/badgr.py index 6e6da6c1275d..46480cee1858 100644 --- a/lms/djangoapps/badges/backends/badgr.py +++ b/lms/djangoapps/badges/backends/badgr.py @@ -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): diff --git a/lms/djangoapps/badges/events/course_complete.py b/lms/djangoapps/badges/events/course_complete.py index 5a0bbafe1c52..2d1049049177 100644 --- a/lms/djangoapps/badges/events/course_complete.py +++ b/lms/djangoapps/badges/events/course_complete.py @@ -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 diff --git a/lms/djangoapps/certificates/views/webview.py b/lms/djangoapps/certificates/views/webview.py index 372dd9f5ab90..fac41396c68d 100644 --- a/lms/djangoapps/certificates/views/webview.py +++ b/lms/djangoapps/certificates/views/webview.py @@ -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: diff --git a/lms/envs/common.py b/lms/envs/common.py index 92abafe79183..89503ec25d6d 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -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'