Skip to content

Commit

Permalink
fix: get topics for blocks with discussions enabled (openedx#34732)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhtishamShahid authored May 13, 2024
1 parent 60e86dd commit d3ffb3e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lms/djangoapps/discussion/rest_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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
Expand All @@ -34,7 +33,6 @@
)

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
Expand Down Expand Up @@ -82,6 +80,7 @@
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

Expand Down Expand Up @@ -131,7 +130,6 @@
is_posting_allowed
)


User = get_user_model()

ThreadType = Literal["discussion", "question"]
Expand Down Expand Up @@ -418,6 +416,7 @@ def sort_categories(category_list):
Required arguments:
category_list -- list of categories.
"""

def convert(text):
if text.isdigit():
return int(text)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d3ffb3e

Please sign in to comment.