fix: get topics for blocks with discussions enabled (#34732)
This commit is contained in:
@@ -13,7 +13,6 @@ from typing import Dict, Iterable, List, Literal, Optional, Set, Tuple
|
||||
from urllib.parse import urlencode, urlunparse
|
||||
from pytz import UTC
|
||||
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError
|
||||
@@ -34,7 +33,6 @@ from common.djangoapps.student.roles import (
|
||||
)
|
||||
|
||||
from lms.djangoapps.course_api.blocks.api import get_blocks
|
||||
from lms.djangoapps.course_blocks.api import get_course_blocks
|
||||
from lms.djangoapps.courseware.courses import get_course_with_access
|
||||
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
@@ -82,6 +80,7 @@ from openedx.core.djangoapps.django_comment_common.signals import (
|
||||
from openedx.core.djangoapps.user_api.accounts.api import get_account_settings
|
||||
from openedx.core.lib.exceptions import CourseNotFoundError, DiscussionNotFoundError, PageNotFoundError
|
||||
from xmodule.course_block import CourseBlock
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.tabs import CourseTabList
|
||||
|
||||
@@ -131,7 +130,6 @@ from .utils import (
|
||||
is_posting_allowed
|
||||
)
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
ThreadType = Literal["discussion", "question"]
|
||||
@@ -418,6 +416,7 @@ def get_courseware_topics(
|
||||
Required arguments:
|
||||
category_list -- list of categories.
|
||||
"""
|
||||
|
||||
def convert(text):
|
||||
if text.isdigit():
|
||||
return int(text)
|
||||
@@ -697,11 +696,19 @@ def get_course_topics_v2(
|
||||
FORUM_ROLE_ADMINISTRATOR,
|
||||
]
|
||||
).exists()
|
||||
course_blocks = get_course_blocks(user, store.make_course_usage_key(course_key))
|
||||
accessible_vertical_keys = [
|
||||
block for block in course_blocks.get_block_keys()
|
||||
if block.block_type == 'vertical'
|
||||
] + [None]
|
||||
|
||||
with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, course_key):
|
||||
blocks = store.get_items(
|
||||
course_key,
|
||||
qualifiers={'category': 'vertical'},
|
||||
fields=['usage_key', 'discussion_enabled', 'display_name'],
|
||||
)
|
||||
accessible_vertical_keys = []
|
||||
for block in blocks:
|
||||
if block.discussion_enabled and (not block.visible_to_staff_only or user_is_privileged):
|
||||
accessible_vertical_keys.append(block.usage_key)
|
||||
accessible_vertical_keys.append(None)
|
||||
|
||||
topics_query = DiscussionTopicLink.objects.filter(
|
||||
context_key=course_key,
|
||||
provider_id=provider_type,
|
||||
|
||||
Reference in New Issue
Block a user