From b5506c29a6d3c2f5af4f7d515780fa1723f49602 Mon Sep 17 00:00:00 2001 From: Taimoor Ahmed Date: Mon, 5 Jun 2023 01:19:04 +0500 Subject: [PATCH 1/5] Add Badgr Improvement - EDLY-5526 --- cms/envs/common.py | 2 +- lms/djangoapps/badges/api/serializers.py | 2 +- lms/envs/common.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 3ed81954531c..47e4946c5eff 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -779,7 +779,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', + 'BADGR_ISSUER_SLUG', 'ENABLE_OPENBADGES', ] # CORS CONFIG diff --git a/lms/djangoapps/badges/api/serializers.py b/lms/djangoapps/badges/api/serializers.py index 8189c7459d3b..33aab0c002fe 100644 --- a/lms/djangoapps/badges/api/serializers.py +++ b/lms/djangoapps/badges/api/serializers.py @@ -16,7 +16,7 @@ class BadgeClassSerializer(serializers.ModelSerializer): class Meta(object): model = BadgeClass - fields = ('slug', 'issuing_component', 'display_name', 'course_id', 'description', 'criteria', 'image_url') + fields = ('slug', 'issuing_component', 'display_name', 'course_id', 'description', 'criteria', 'image_url', 'mode', 'badgr_server_slug') class BadgeAssertionSerializer(serializers.ModelSerializer): diff --git a/lms/envs/common.py b/lms/envs/common.py index 9f51d57cccd2..ede8c5d087f8 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1686,7 +1686,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', + 'BADGR_ISSUER_SLUG', 'ENABLE_OPENBADGES', ] ENABLE_SUBSCRIPTIONS_ON_RUNTIME_SWITCH = 'enable_subscriptions' From ad9fe2ce12d841a35c5b92f97412df5f17bd1057 Mon Sep 17 00:00:00 2001 From: Taimoor Ahmed Date: Mon, 5 Jun 2023 01:19:04 +0500 Subject: [PATCH 2/5] Add Badgr Improvement - EDLY-5526 --- cms/envs/common.py | 2 +- lms/djangoapps/badges/api/serializers.py | 2 +- lms/envs/common.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index bbe325805161..5a538e1547d9 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -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', + 'BADGR_ISSUER_SLUG', 'ENABLE_OPENBADGES', ] # CORS CONFIG diff --git a/lms/djangoapps/badges/api/serializers.py b/lms/djangoapps/badges/api/serializers.py index 8189c7459d3b..33aab0c002fe 100644 --- a/lms/djangoapps/badges/api/serializers.py +++ b/lms/djangoapps/badges/api/serializers.py @@ -16,7 +16,7 @@ class BadgeClassSerializer(serializers.ModelSerializer): class Meta(object): model = BadgeClass - fields = ('slug', 'issuing_component', 'display_name', 'course_id', 'description', 'criteria', 'image_url') + fields = ('slug', 'issuing_component', 'display_name', 'course_id', 'description', 'criteria', 'image_url', 'mode', 'badgr_server_slug') class BadgeAssertionSerializer(serializers.ModelSerializer): diff --git a/lms/envs/common.py b/lms/envs/common.py index 5ce6f07e55ef..92abafe79183 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', + 'BADGR_ISSUER_SLUG', 'ENABLE_OPENBADGES', ] ENABLE_SUBSCRIPTIONS_ON_RUNTIME_SWITCH = 'enable_subscriptions' From 9e473976357ad68206c7c9baa3674c1d132cf116 Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Date: Wed, 16 Aug 2023 17:40:30 +0500 Subject: [PATCH 3/5] fix: disable default badge creation --- lms/djangoapps/badges/events/course_complete.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/badges/events/course_complete.py b/lms/djangoapps/badges/events/course_complete.py index 9b2b01adbd30..5a0bbafe1c52 100644 --- a/lms/djangoapps/badges/events/course_complete.py +++ b/lms/djangoapps/badges/events/course_complete.py @@ -103,7 +103,8 @@ def get_completion_badge(course_id, user): course_id=course_id, mode=mode, display_name=course.display_name, - image_file_handle=CourseCompleteImageConfiguration.image_for_mode(mode) + image_file_handle=CourseCompleteImageConfiguration.image_for_mode(mode), + create=False ) From f85593305a84fd9dae0ac53de81003aa3beced74 Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Date: Wed, 16 Aug 2023 19:45:45 +0500 Subject: [PATCH 4/5] fix: Handled NoneType error in get_completion_badge() function --- lms/djangoapps/certificates/views/webview.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/certificates/views/webview.py b/lms/djangoapps/certificates/views/webview.py index bc7322158841..372dd9f5ab90 100644 --- a/lms/djangoapps/certificates/views/webview.py +++ b/lms/djangoapps/certificates/views/webview.py @@ -420,7 +420,12 @@ def _update_badge_context(context, course, user): """ badge = None if badges_enabled() and course.issue_badges: - badges = get_completion_badge(course.location.course_key, user).get_for_user(user) + completion_badge = get_completion_badge(course.location.course_key, user) + if completion_badge is not None: + badges = completion_badge.get_for_user(user) + else: + badges = None + if badges: badge = badges[0] context['badge'] = badge From aefd959ce991c2b547c73d0ced36f9df99aa99d3 Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Date: Thu, 17 Aug 2023 00:51:53 +0500 Subject: [PATCH 5/5] fix: Improve code quality --- lms/djangoapps/badges/api/serializers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/badges/api/serializers.py b/lms/djangoapps/badges/api/serializers.py index 33aab0c002fe..ad6185f86711 100644 --- a/lms/djangoapps/badges/api/serializers.py +++ b/lms/djangoapps/badges/api/serializers.py @@ -16,7 +16,8 @@ class BadgeClassSerializer(serializers.ModelSerializer): class Meta(object): model = BadgeClass - fields = ('slug', 'issuing_component', 'display_name', 'course_id', 'description', 'criteria', 'image_url', 'mode', 'badgr_server_slug') + fields = ('slug', 'issuing_component', 'display_name', 'course_id', 'description', 'criteria', 'image_url', + 'mode', 'badgr_server_slug') class BadgeAssertionSerializer(serializers.ModelSerializer):