From 6d48e1360d786c7dc4a5d6ad67e6757407976450 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Fri, 31 Jul 2015 20:22:31 +0000 Subject: [PATCH] Extend is_commentable_cohorted to support teams --- .../django_comment_client/tests/group_id.py | 7 +++++++ .../django_comment_client/tests/test_utils.py | 12 ++++++++++++ lms/djangoapps/django_comment_client/utils.py | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/django_comment_client/tests/group_id.py b/lms/djangoapps/django_comment_client/tests/group_id.py index 24f0b15fda..2773b5ee99 100644 --- a/lms/djangoapps/django_comment_client/tests/group_id.py +++ b/lms/djangoapps/django_comment_client/tests/group_id.py @@ -1,5 +1,6 @@ import json import re +from teams.tests.factories import CourseTeamFactory class GroupIdAssertionMixin(object): @@ -145,3 +146,9 @@ class NonCohortedTopicGroupIdTestMixin(GroupIdAssertionMixin): invalid_id = self.student_cohort.id + self.moderator_cohort.id self.call_view(mock_request, "non_cohorted_topic", self.moderator, invalid_id) self._assert_comments_service_called_without_group_id(mock_request) + + def test_team_discussion_id_not_cohorted(self, mock_request): + team = CourseTeamFactory(course_id=self.course.id) + team.add_user(self.student) # pylint: disable=no-member + self.call_view(mock_request, team.discussion_topic_id, self.student, None) + self._assert_comments_service_called_without_group_id(mock_request) diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index c1dc4bcaee..4910ffc67d 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -26,6 +26,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_MIXED_TOY_MODULESTORE from xmodule.modulestore.django import modulestore from opaque_keys.edx.locator import CourseLocator +from teams.tests.factories import CourseTeamFactory @attr('shard_1') @@ -1209,3 +1210,14 @@ class IsCommentableCohortedTestCase(ModuleStoreTestCase): utils.is_commentable_cohorted(course.id, to_id("Feedback")), "If always_cohort_inline_discussions set to False, top-level discussion are not affected." ) + + def test_is_commentable_cohorted_team(self): + course = modulestore().get_course(self.toy_course_key) + self.assertFalse(cohorts.is_course_cohorted(course.id)) + + config_course_cohorts(course, is_cohorted=True) + team = CourseTeamFactory(course_id=course.id) + + # Verify that team discussions are not cohorted, but other discussions are + self.assertFalse(utils.is_commentable_cohorted(course.id, team.discussion_topic_id)) + self.assertTrue(utils.is_commentable_cohorted(course.id, "random")) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index a91fa4b9cb..cf71030b37 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -15,7 +15,7 @@ from opaque_keys.edx.keys import CourseKey from xmodule.modulestore.django import modulestore from django_comment_common.models import Role, FORUM_ROLE_STUDENT -from django_comment_client.permissions import check_permissions_by_view, has_permission +from django_comment_client.permissions import check_permissions_by_view, has_permission, get_team from django_comment_client.settings import MAX_COMMENT_DEPTH from edxmako import lookup_template @@ -678,7 +678,7 @@ def is_commentable_cohorted(course_key, commentable_id): course = courses.get_course_by_id(course_key) course_cohort_settings = get_course_cohort_settings(course_key) - if not course_cohort_settings.is_cohorted: + if not course_cohort_settings.is_cohorted or get_team(commentable_id): # this is the easy case :) ans = False elif (