From 495d1cc86cf9454a66b54dfb5bf9915e39f9e0e1 Mon Sep 17 00:00:00 2001 From: SaadYousaf Date: Tue, 16 Aug 2022 14:51:39 +0500 Subject: [PATCH] fix: add is_group_ta and has_moderations_privileges to course settings API --- lms/djangoapps/discussion/rest_api/api.py | 4 +++- lms/djangoapps/discussion/rest_api/tests/test_api.py | 5 +++-- lms/djangoapps/discussion/rest_api/tests/test_views.py | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/api.py b/lms/djangoapps/discussion/rest_api/api.py index d249f60df4..8ebaa9bfce 100644 --- a/lms/djangoapps/discussion/rest_api/api.py +++ b/lms/djangoapps/discussion/rest_api/api.py @@ -48,6 +48,7 @@ from openedx.core.djangoapps.django_comment_common.comment_client.utils import C from openedx.core.djangoapps.django_comment_common.models import ( FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, + FORUM_ROLE_GROUP_MODERATOR, FORUM_ROLE_MODERATOR, CourseDiscussionSettings, Role, @@ -322,11 +323,12 @@ def get_course(request, course_key): "allow_anonymous": course.allow_anonymous, "allow_anonymous_to_peers": course.allow_anonymous_to_peers, "user_roles": user_roles, - "user_is_privileged": bool(user_roles & { + "has_moderation_privileges": bool(user_roles & { FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA, }), + "is_group_ta": bool(user_roles & {FORUM_ROLE_GROUP_MODERATOR}), "is_user_admin": request.user.is_staff, "provider": course_config.provider_type, "enable_in_context": course_config.enable_in_context, diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index 2973e3a207..22356283d9 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -199,7 +199,8 @@ class GetCourseTest(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase) 'enable_in_context': True, 'group_at_subsection': False, 'provider': 'legacy', - 'user_is_privileged': False, + 'has_moderation_privileges': False, + 'is_group_ta': False, 'is_user_admin': False, 'user_roles': {'Student'}, 'learners_tab_enabled': False, @@ -219,7 +220,7 @@ class GetCourseTest(ForumsEnableMixin, UrlResetMixin, SharedModuleStoreTestCase) """ _assign_role_to_user(user=self.user, course_id=self.course.id, role=role) course_meta = get_course(self.request, self.course.id) - assert course_meta["user_is_privileged"] + assert course_meta["has_moderation_privileges"] assert course_meta["user_roles"] == {FORUM_ROLE_STUDENT} | {role} @ddt.data(True, False) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_views.py b/lms/djangoapps/discussion/rest_api/tests/test_views.py index a6ceef848b..0ed789eff9 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_views.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_views.py @@ -520,7 +520,8 @@ class CourseViewTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): "provider": "legacy", "allow_anonymous": True, "allow_anonymous_to_peers": False, - "user_is_privileged": False, + "has_moderation_privileges": False, + "is_group_ta": False, 'is_user_admin': False, "user_roles": ["Student"], 'learners_tab_enabled': False,