-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat: Adds discussions settings for new discusions experience [BD-38] [TNL-8621] [BB-4854] #28749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
asadazam93
merged 1 commit into
openedx:master
from
open-craft:kshiitj/discussions-structure-in-course
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1512,7 +1512,6 @@ | |
|
|
||
| # Discussion | ||
| 'openedx.core.djangoapps.django_comment_common', | ||
| 'openedx.core.djangoapps.discussions', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I've added a plugin entrypoint, this isn't needed any more. |
||
|
|
||
| # for course creator table | ||
| 'django.contrib.admin', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,15 @@ | |
| has_permission | ||
| ) | ||
| from lms.djangoapps.discussion.django_comment_client.settings import MAX_COMMENT_DEPTH | ||
| from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted | ||
| from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id | ||
| from openedx.core.djangoapps.discussions.utils import ( | ||
| get_accessible_discussion_xblocks, | ||
| get_accessible_discussion_xblocks_by_course_id, | ||
| get_course_division_scheme, | ||
| get_discussion_categories_ids, | ||
| get_group_names_by_id, | ||
| has_required_keys, | ||
| ) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving these over allows us to import this in both LMS and studio code. |
||
| from openedx.core.djangoapps.django_comment_common.models import ( | ||
| FORUM_ROLE_COMMUNITY_TA, | ||
| FORUM_ROLE_STUDENT, | ||
|
|
@@ -116,45 +124,6 @@ def is_user_community_ta(user, course_id): | |
| return has_forum_access(user, course_id, FORUM_ROLE_COMMUNITY_TA) | ||
|
|
||
|
|
||
| def has_required_keys(xblock): | ||
| """ | ||
| Returns True iff xblock has the proper attributes for generating metadata | ||
| with get_discussion_id_map_entry() | ||
| """ | ||
| for key in ('discussion_id', 'discussion_category', 'discussion_target'): | ||
| if getattr(xblock, key, None) is None: | ||
| log.debug( | ||
| "Required key '%s' not in discussion %s, leaving out of category map", | ||
| key, | ||
| xblock.location | ||
| ) | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def get_accessible_discussion_xblocks(course, user, include_all=False): | ||
| """ | ||
| Return a list of all valid discussion xblocks in this course that | ||
| are accessible to the given user. | ||
| """ | ||
| include_all = getattr(user, 'is_community_ta', False) | ||
| return get_accessible_discussion_xblocks_by_course_id(course.id, user, include_all=include_all) | ||
|
|
||
|
|
||
| @request_cached() | ||
| def get_accessible_discussion_xblocks_by_course_id(course_id, user=None, include_all=False): # pylint: disable=invalid-name | ||
| """ | ||
| Return a list of all valid discussion xblocks in this course. | ||
| Checks for the given user's access if include_all is False. | ||
| """ | ||
| all_xblocks = modulestore().get_items(course_id, qualifiers={'category': 'discussion'}, include_orphans=False) | ||
|
|
||
| return [ | ||
| xblock for xblock in all_xblocks | ||
| if has_required_keys(xblock) and (include_all or has_access(user, 'load', xblock, course_id)) | ||
| ] | ||
|
|
||
|
|
||
| def get_discussion_id_map_entry(xblock): | ||
| """ | ||
| Returns a tuple of (discussion_id, metadata) suitable for inclusion in the results of get_discussion_id_map(). | ||
|
|
@@ -465,23 +434,6 @@ def discussion_category_id_access(course, user, discussion_id, xblock=None): | |
| return discussion_id in get_discussion_categories_ids(course, user) | ||
|
|
||
|
|
||
| def get_discussion_categories_ids(course, user, include_all=False): | ||
| """ | ||
| Returns a list of available ids of categories for the course that | ||
| are accessible to the given user. | ||
|
|
||
| Args: | ||
| course: Course for which to get the ids. | ||
| user: User to check for access. | ||
| include_all (bool): If True, return all ids. Used by configuration views. | ||
|
|
||
| """ | ||
| accessible_discussion_ids = [ | ||
| xblock.discussion_id for xblock in get_accessible_discussion_xblocks(course, user, include_all=include_all) | ||
| ] | ||
| return course.top_level_discussion_topic_ids + accessible_discussion_ids | ||
|
|
||
|
|
||
| class JsonResponse(HttpResponse): | ||
| """ | ||
| Django response object delivering JSON representations | ||
|
|
@@ -881,7 +833,7 @@ def get_group_id_for_user(user, course_discussion_settings): | |
| If discussions are not divided, this method will return None. | ||
| It will also return None if the user is in no group within the specified division_scheme. | ||
| """ | ||
| division_scheme = _get_course_division_scheme(course_discussion_settings) | ||
| division_scheme = get_course_division_scheme(course_discussion_settings) | ||
| if division_scheme == CourseDiscussionSettings.COHORT: | ||
| return get_cohort_id(user, course_discussion_settings.course_id) | ||
| elif division_scheme == CourseDiscussionSettings.ENROLLMENT_TRACK: | ||
|
|
@@ -960,51 +912,7 @@ def course_discussion_division_enabled(course_discussion_settings): | |
|
|
||
| Returns: True if discussion division is enabled for the course, else False | ||
| """ | ||
| return _get_course_division_scheme(course_discussion_settings) != CourseDiscussionSettings.NONE | ||
|
|
||
|
|
||
| def available_division_schemes(course_key): | ||
| """ | ||
| Returns a list of possible discussion division schemes for this course. | ||
| This takes into account if cohorts are enabled and if there are multiple | ||
| enrollment tracks. If no schemes are available, returns an empty list. | ||
| Args: | ||
| course_key: CourseKey | ||
|
|
||
| Returns: list of possible division schemes (for example, CourseDiscussionSettings.COHORT) | ||
| """ | ||
| available_schemes = [] | ||
| if is_course_cohorted(course_key): | ||
| available_schemes.append(CourseDiscussionSettings.COHORT) | ||
| if enrollment_track_group_count(course_key) > 1: | ||
| available_schemes.append(CourseDiscussionSettings.ENROLLMENT_TRACK) | ||
| return available_schemes | ||
|
|
||
|
|
||
| def enrollment_track_group_count(course_key): | ||
| """ | ||
| Returns the count of possible enrollment track division schemes for this course. | ||
| Args: | ||
| course_key: CourseKey | ||
| Returns: | ||
| Count of enrollment track division scheme | ||
| """ | ||
| return len(_get_enrollment_track_groups(course_key)) | ||
|
|
||
|
|
||
| def _get_course_division_scheme(course_discussion_settings): | ||
| division_scheme = course_discussion_settings.division_scheme | ||
| if ( | ||
| division_scheme == CourseDiscussionSettings.COHORT and | ||
| not is_course_cohorted(course_discussion_settings.course_id) | ||
| ): | ||
| division_scheme = CourseDiscussionSettings.NONE | ||
| elif ( | ||
| division_scheme == CourseDiscussionSettings.ENROLLMENT_TRACK and | ||
| enrollment_track_group_count(course_discussion_settings.course_id) <= 1 | ||
| ): | ||
| division_scheme = CourseDiscussionSettings.NONE | ||
| return division_scheme | ||
| return get_course_division_scheme(course_discussion_settings) != CourseDiscussionSettings.NONE | ||
|
|
||
|
|
||
| def get_group_name(group_id, course_discussion_settings): | ||
|
|
@@ -1023,38 +931,6 @@ def get_group_name(group_id, course_discussion_settings): | |
| return group_names_by_id[group_id] if group_id in group_names_by_id else None | ||
|
|
||
|
|
||
| def get_group_names_by_id(course_discussion_settings): | ||
| """ | ||
| Creates of a dict of group_id to learner-facing group names, for the division_scheme | ||
| in use as specified by course_discussion_settings. | ||
| Args: | ||
| course_discussion_settings: CourseDiscussionSettings model instance | ||
|
|
||
| Returns: dict of group_id to learner-facing group names. If no division_scheme | ||
| is in use, returns an empty dict. | ||
| """ | ||
| division_scheme = _get_course_division_scheme(course_discussion_settings) | ||
| course_key = course_discussion_settings.course_id | ||
| if division_scheme == CourseDiscussionSettings.COHORT: | ||
| return get_cohort_names(get_course_by_id(course_key)) | ||
| elif division_scheme == CourseDiscussionSettings.ENROLLMENT_TRACK: | ||
| # We negate the group_ids from dynamic partitions so that they will not conflict | ||
| # with cohort IDs (which are an auto-incrementing integer field, starting at 1). | ||
| return {-1 * group.id: group.name for group in _get_enrollment_track_groups(course_key)} | ||
| else: | ||
| return {} | ||
|
|
||
|
|
||
| def _get_enrollment_track_groups(course_key): | ||
| """ | ||
| Helper method that returns an array of the Groups in the EnrollmentTrackUserPartition for the given course. | ||
| If no such partition exists on the course, an empty array is returned. | ||
| """ | ||
| partition_service = PartitionService(course_key) | ||
| partition = partition_service.get_user_partition(ENROLLMENT_TRACK_PARTITION_ID) | ||
| return partition.groups if partition else [] | ||
|
|
||
|
|
||
| def _verify_group_exists(group_id, course_discussion_settings): | ||
| """ | ||
| Helper method that verifies the given group_id corresponds to a Group in the | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will hide these new settings from the advanced settings UI.
Might be worth removing it from here while testing to have an easy way to check for changes.