From f7df694c5f9bb02dbda699effa5c176410125eea Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Mon, 28 Feb 2022 11:53:28 +0530 Subject: [PATCH] feat: add provider info to the discussion configuration API (#29864) The new discusions MFE needs to know which provider is in use (legacy or new) to deliver the expected experience. This adds the provider name and other relevant configuration to the discussion configuraiton API. --- lms/djangoapps/discussion/rest_api/api.py | 7 ++++++- lms/djangoapps/discussion/rest_api/serializers.py | 13 +++++++++++-- .../discussion/rest_api/tests/test_api.py | 3 +++ .../discussion/rest_api/tests/test_views.py | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/api.py b/lms/djangoapps/discussion/rest_api/api.py index f3ecab0eb4..9162ed4de8 100644 --- a/lms/djangoapps/discussion/rest_api/api.py +++ b/lms/djangoapps/discussion/rest_api/api.py @@ -278,6 +278,8 @@ def get_course(request, course_key): course = _get_course(course_key, request.user) user_roles = get_user_role_names(request.user, course_key) + course_config = DiscussionsConfiguration.get(course_key) + return { "id": str(course_key), "blackouts": [ @@ -299,7 +301,10 @@ def get_course(request, course_key): FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA, - }) + }), + "provider": course_config.provider_type, + "enable_in_context": course_config.enable_in_context, + "group_at_subsection": course_config.plugin_configuration.get("group_at_subsection", False), } diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index b53a35db8d..21b03d69d6 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -739,10 +739,10 @@ class CourseMetadataSerailizer(serializers.Serializer): ) topics_url = serializers.URLField(help_text="The URL of the topic listing for the course.") allow_anonymous = serializers.BooleanField( - help_text="A boolean which indicating whether anonymous posts are allowed or not.", + help_text="A boolean indicating whether anonymous posts are allowed or not.", ) allow_anonymous_to_peers = serializers.BooleanField( - help_text="A boolean which indicating whether posts anonymous to peers are allowed or not.", + help_text="A boolean indicating whether posts anonymous to peers are allowed or not.", ) user_roles = serializers.ListField( child=serializers.CharField(), @@ -751,3 +751,12 @@ class CourseMetadataSerailizer(serializers.Serializer): user_is_privileged = serializers.BooleanField( help_text="A boolean indicating if the current user has a privileged role", ) + provider = serializers.CharField( + help_text="The discussion provider used by this course", + ) + enable_in_context = serializers.BooleanField( + help_text="A boolean indicating whether in-context discussion is enabled for the course", + ) + group_at_subsection = serializers.BooleanField( + help_text="A boolean indicating whether discussions should be grouped at subsection", + ) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index 413d217489..e8f7443cf9 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -191,6 +191,9 @@ class GetCourseTest(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase) 'topics_url': 'http://testserver/api/discussion/v1/course_topics/course-v1:x+y+z', 'allow_anonymous': True, 'allow_anonymous_to_peers': False, + 'enable_in_context': True, + 'group_at_subsection': False, + 'provider': 'legacy', 'user_is_privileged': False, 'user_roles': {'Student'}, } diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index ce7aac8671..e2acee8cc6 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -512,6 +512,9 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): "http://testserver/api/discussion/v1/threads/?course_id=course-v1%3Ax%2By%2Bz&following=True" ), "topics_url": "http://testserver/api/discussion/v1/course_topics/course-v1:x+y+z", + 'enable_in_context': True, + 'group_at_subsection': False, + 'provider': 'legacy', "allow_anonymous": True, "allow_anonymous_to_peers": False, 'user_is_privileged': False,