From ebd96cba8a6b100f486714c42ae964b2b8e4086a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ch=C3=A1vez?= Date: Tue, 2 Aug 2022 11:40:23 -0500 Subject: [PATCH] fix: Bug showing hidden sections for learners of a public course fixed (#27925) The bug is explained in https://openedx.atlassian.net/browse/CRI-233. Only is missing add the `VisibilityTransformer` in `get_blocks()` when the user is not enrolled to the course. On the test, `html_block` is visible only for staff and `vertical_block` is a normal block. The new behaviour hides the `html_block` and show the `vertical_block` to anonymous users --- lms/djangoapps/course_api/blocks/api.py | 2 ++ lms/djangoapps/course_api/blocks/tests/test_api.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/course_api/blocks/api.py b/lms/djangoapps/course_api/blocks/api.py index 7c14dfd4c3..95e6c73e98 100644 --- a/lms/djangoapps/course_api/blocks/api.py +++ b/lms/djangoapps/course_api/blocks/api.py @@ -90,6 +90,8 @@ def get_blocks( ), HiddenContentTransformer() ] + else: + transformers += [course_blocks_api.visibility.VisibilityTransformer()] # Note: A change to the BlockCompletionTransformer (https://github.com/edx/edx-platform/pull/27622/) # will be introducing a bug if hide_access_denials is True. I'm accepting this risk because in diff --git a/lms/djangoapps/course_api/blocks/tests/test_api.py b/lms/djangoapps/course_api/blocks/tests/test_api.py index 6ae491ea30..8bf7b9d518 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_api.py +++ b/lms/djangoapps/course_api/blocks/tests/test_api.py @@ -53,7 +53,9 @@ class TestGetBlocks(SharedModuleStoreTestCase): def test_no_user(self): blocks = get_blocks(self.request, self.course.location) - assert str(self.html_block.location) in blocks['blocks'] + assert str(self.html_block.location) not in blocks['blocks'] + vertical_block = self.store.get_item(self.course.id.make_usage_key('vertical', 'vertical_x1a')) + assert str(vertical_block.location) in blocks['blocks'] def test_access_before_api_transformer_order(self): """