EDUCATOR-3213 make Global EdX Staff able to view all forum posts

This commit is contained in:
rabiaiftikhar
2018-10-09 15:17:55 +05:00
parent 6be27ed08d
commit aac430da34
4 changed files with 23 additions and 3 deletions

View File

@@ -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

View File

@@ -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):
"""

View File

@@ -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):

View File

@@ -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,