From aac430da348d04423267322ca0fc6d61df2aff15 Mon Sep 17 00:00:00 2001 From: rabiaiftikhar Date: Tue, 9 Oct 2018 15:17:55 +0500 Subject: [PATCH] EDUCATOR-3213 make Global EdX Staff able to view all forum posts --- common/djangoapps/django_comment_common/models.py | 8 ++++++++ common/djangoapps/django_comment_common/utils.py | 5 +++-- lms/djangoapps/discussion/tests/test_views.py | 11 +++++++++++ openedx/core/djangoapps/util/testing.py | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/django_comment_common/models.py b/common/djangoapps/django_comment_common/models.py index cbe7c38e08..761ea57c76 100644 --- a/common/djangoapps/django_comment_common/models.py +++ b/common/djangoapps/django_comment_common/models.py @@ -14,6 +14,7 @@ from six import text_type from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager from student.models import CourseEnrollment +from student.roles import GlobalStaff from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError @@ -157,6 +158,13 @@ def all_permissions_for_user_in_course(user, course_id): # pylint: disable=inva if not permission_blacked_out(course, role_names, permission.name): permission_names.add(permission.name) + # Prevent a circular import + from django_comment_common.utils import GLOBAL_STAFF_ROLE_PERMISSIONS + + if GlobalStaff().has_user(user): + for permission in GLOBAL_STAFF_ROLE_PERMISSIONS: + permission_names.add(permission) + return permission_names diff --git a/common/djangoapps/django_comment_common/utils.py b/common/djangoapps/django_comment_common/utils.py index 5197b5bc9c..06b73fc5e5 100644 --- a/common/djangoapps/django_comment_common/utils.py +++ b/common/djangoapps/django_comment_common/utils.py @@ -3,6 +3,7 @@ Common comment client utility functions. """ from django_comment_common.models import ( + CourseDiscussionSettings, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_COMMUNITY_TA, FORUM_ROLE_GROUP_MODERATOR, @@ -13,8 +14,6 @@ from django_comment_common.models import ( from openedx.core.djangoapps.course_groups.cohorts import get_legacy_discussion_settings from openedx.core.lib.cache_utils import request_cached -from .models import CourseDiscussionSettings - class ThreadContext(object): """ An enumeration that represents the context of a thread. Used primarily by the comments service. """ @@ -34,6 +33,8 @@ GROUP_MODERATOR_ROLE_PERMISSIONS = ["group_edit_content", "group_delete_thread", ADMINISTRATOR_ROLE_PERMISSIONS = ["manage_moderator"] +GLOBAL_STAFF_ROLE_PERMISSIONS = ["see_all_cohorts"] + def _save_forum_role(course_key, name): """ diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index 6bc60fa237..375fb79800 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -771,6 +771,17 @@ class ForumFormDiscussionContentGroupTestCase(ForumsEnableMixin, ContentGroupTes ) self.assert_has_access(response, 3) + def test_global_staff_user(self, mock_request): + """ + Verify that global staff user has access to all threads regardless + of cohort. + """ + response = self.call_view( + mock_request, + self.staff_user + ) + self.assert_has_access(response, 4) + @patch('requests.request', autospec=True) class SingleThreadContentGroupTestCase(ForumsEnableMixin, UrlResetMixin, ContentGroupTestCase): diff --git a/openedx/core/djangoapps/util/testing.py b/openedx/core/djangoapps/util/testing.py index 1558640f3d..6719c7076c 100644 --- a/openedx/core/djangoapps/util/testing.py +++ b/openedx/core/djangoapps/util/testing.py @@ -72,7 +72,7 @@ class ContentGroupTestCase(ModuleStoreTestCase): alpha_cohort = CohortFactory( course_id=self.course.id, name='Cohort Alpha', - users=[self.alpha_user, self.community_ta] + users=[self.alpha_user, self.community_ta, self.staff_user] ) beta_cohort = CohortFactory( course_id=self.course.id,