diff --git a/common/djangoapps/course_groups/cohorts.py b/common/djangoapps/course_groups/cohorts.py index b7401ef8a2..c09e60dd80 100644 --- a/common/djangoapps/course_groups/cohorts.py +++ b/common/djangoapps/course_groups/cohorts.py @@ -40,7 +40,18 @@ def is_commentable_cohorted(course_id, commentable_id): Http404 if the course doesn't exist. """ course = courses.get_course_by_id(course_id) - ans = commentable_id in course.cohorted_discussions() + + if not course.is_cohorted: + # this is the easy case :) + ans = False + elif commentable_id in course.top_level_discussion_topic_ids: + # top level discussions have to be manually configured as cohorted + # (default is not) + ans = commentable_id in course.cohorted_discussions() + else: + # inline discussions are cohorted by default + ans = True + log.debug("is_commentable_cohorted({0}, {1}) = {2}".format(course_id, commentable_id, ans)) @@ -49,7 +60,11 @@ def is_commentable_cohorted(course_id, commentable_id): def get_cohort(user, course_id): c = _get_cohort(user, course_id) - log.debug("get_cohort({0}, {1}) = {2}".format(user, course_id, c.id)) + log.debug("get_cohort({0}, {1}) = {2}".format( + user, course_id, + c.id if c is not None else None)) + return c + def _get_cohort(user, course_id): """ diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index df542a3d42..d35ba3ea6a 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -371,10 +371,21 @@ class CourseDescriptor(SequenceDescriptor): return bool(config.get("cohorted")) + @property + def top_level_discussion_topic_ids(self): + """ + Return list of topic ids defined in course policy. + """ + topics = self.metadata.get("discussion_topics", {}) + return [d["id"] for d in topics.values()] + + + @property def cohorted_discussions(self): """ - Return the set of discussions that is cohorted. It may be the empty - set. + Return the set of discussions that is explicitly cohorted. It may be + the empty set. Note that all inline discussions are automatically + cohorted based on the course's is_cohorted setting. """ config = self.metadata.get("cohort_config") if config is None: