Skip to content

Commit 1ac9e56

Browse files
committed
fix: doc lint issues
1 parent 9ff15ba commit 1ac9e56

File tree

6 files changed

+48
-5
lines changed

6 files changed

+48
-5
lines changed

cms/djangoapps/contentstore/tests/test_upstream_downstream_links.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def _create_unit(self, num: int):
6060
)
6161

6262
def _create_unit_and_expected_container_link(self, course_key: str | CourseKey, num_blocks: int = 3):
63+
"""
64+
Create unit xblock with random upstream key and version number.
65+
"""
6366
data = []
6467
for i in range(num_blocks):
6568
upstream, block = self._create_unit(i + 1)

cms/djangoapps/contentstore/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,9 @@ def get_xblock_render_context(request, block):
23752375

23762376

23772377
def _create_or_update_component_link(course_key: CourseKey, created: datetime | None, xblock):
2378+
"""
2379+
Create or update upstream->downstream link for components in database for given xblock.
2380+
"""
23782381
upstream_usage_key = UsageKeyV2.from_string(xblock.upstream)
23792382
try:
23802383
lib_component = get_component_from_usage_key(upstream_usage_key)
@@ -2394,6 +2397,9 @@ def _create_or_update_component_link(course_key: CourseKey, created: datetime |
23942397

23952398

23962399
def _create_or_update_container_link(course_key: CourseKey, created: datetime | None, xblock):
2400+
"""
2401+
Create or update upstream->downstream link for containers in database for given xblock.
2402+
"""
23972403
upstream_container_key = LibraryContainerLocator.from_string(xblock.upstream)
23982404
try:
23992405
lib_component = get_container_from_key(upstream_container_key)

cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ def create_item(request):
525525

526526

527527
def sync_library_content(created_block: XBlock, request, store, remove_upstream_link: bool = False):
528+
"""
529+
Handle syncing library content for given xblock depending on its upstream type.
530+
It can sync unit containers and lower level xblocks.
531+
"""
528532
upstream_key = check_and_parse_upstream_key(created_block.upstream, created_block.usage_key)
529533
if isinstance(upstream_key, LibraryUsageLocatorV2):
530534
lib_block = sync_from_upstream(downstream=created_block, user=request.user)

cms/lib/xblock/container_upstream_sync.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
"""
2+
Synchronize content and settings from upstream containers to their downstream usages.
3+
4+
* The upstream is a Container from a Learning Core-backed Content Library.
5+
* The downstream is a block of matching type in a SplitModuleStore-backed Course.
6+
* They are both on the same Open edX instance.
7+
8+
HOWEVER, those assumptions may loosen in the future. So, we consider these to be INTERNAL ASSUMPIONS that should not be
9+
exposed through this module's public Python interface.
10+
"""
11+
112
import logging
213
import typing as t
314
from dataclasses import asdict, dataclass
@@ -120,6 +131,9 @@ def _get_library_container_url(container_key: LibraryContainerLocator):
120131

121132

122133
class ContainerUpstreamSyncManager(BaseUpstreamSyncManager):
134+
"""
135+
Manages sync process of downstream containers like unit with upstream containers.
136+
"""
123137
def __init__(self, downstream: XBlock, user: User, upstream: XBlock | None = None) -> None:
124138
super().__init__(downstream, user, upstream)
125139
if not isinstance(self.upstream_key, LibraryContainerLocator):
@@ -152,7 +166,8 @@ def _load_upstream_link_and_container_block(self) -> XBlock:
152166
153167
If `downstream` lacks a valid+supported upstream link, this raises an UpstreamLinkException.
154168
"""
155-
# We import load_block here b/c UpstreamSyncMixin is used by cms/envs, which loads before the djangoapps are ready.
169+
# We import load_block here b/c UpstreamSyncMixin is used by cms/envs,
170+
# which loads before the djangoapps are ready.
156171
from openedx.core.djangoapps.xblock.api import ( # pylint: disable=wrong-import-order
157172
CheckPerm,
158173
LatestVersion,
@@ -170,6 +185,9 @@ def _load_upstream_link_and_container_block(self) -> XBlock:
170185
return lib_block
171186

172187
def sync_new_children_blocks(self):
188+
"""
189+
Creates children xblocks in course based on library container children.
190+
"""
173191
for child in get_container_children(self.upstream_key, published=True):
174192
child_block = create_xblock(
175193
parent_locator=str(self.downstream.location),

cms/lib/xblock/upstream_sync.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
from __future__ import annotations
1313

14+
from abc import ABC
1415
import logging
1516
import typing as t
1617
from dataclasses import asdict, dataclass
@@ -186,7 +187,10 @@ def get_for_block(cls, downstream: XBlock) -> t.Self:
186187
)
187188

188189

189-
class BaseUpstreamSyncManager:
190+
class BaseUpstreamSyncManager(ABC):
191+
"""
192+
Base manager class for managing upstream link sync process.
193+
"""
190194
def __init__(
191195
self,
192196
downstream: XBlock,
@@ -293,6 +297,9 @@ def sync(self) -> None:
293297

294298

295299
class ComponentUpstreamSyncManager(BaseUpstreamSyncManager):
300+
"""
301+
Manages sync process of downstream component with upstream components.
302+
"""
296303
def __init__(self, downstream: XBlock, user: User, upstream: XBlock | None = None) -> None:
297304
super().__init__(downstream, user, upstream)
298305
if not upstream:
@@ -324,7 +331,8 @@ def _load_upstream_link_and_block(self) -> XBlock:
324331
325332
If `downstream` lacks a valid+supported upstream link, this raises an UpstreamLinkException.
326333
"""
327-
# We import load_block here b/c UpstreamSyncMixin is used by cms/envs, which loads before the djangoapps are ready.
334+
# We import load_block here b/c UpstreamSyncMixin is used by cms/envs,
335+
# which loads before the djangoapps are ready.
328336
from openedx.core.djangoapps.xblock.api import (
329337
CheckPerm,
330338
LatestVersion,

openedx/core/djangoapps/content_libraries/library_context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ def can_edit_block(self, user: UserType, usage_key: LibraryUsageLocatorV2 | Libr
4242
self._assert_key_instance(usage_key)
4343
return self._check_perm(user, usage_key.lib_key, permissions.CAN_EDIT_THIS_CONTENT_LIBRARY)
4444

45-
def can_view_block_for_editing(self, user: UserType, usage_key: LibraryUsageLocatorV2 | LibraryContainerLocator) -> bool:
45+
def can_view_block_for_editing(
46+
self,
47+
user: UserType,
48+
usage_key: LibraryUsageLocatorV2 | LibraryContainerLocator,
49+
) -> bool:
4650
"""
4751
Assuming a block with the specified ID (usage_key) exists, does the
4852
specified user have permission to view its fields and OLX details (but
@@ -65,7 +69,7 @@ def can_view_block(self, user: UserType, usage_key: LibraryUsageLocatorV2 | Libr
6569
return self._check_perm(user, usage_key.lib_key, permissions.CAN_LEARN_FROM_THIS_CONTENT_LIBRARY)
6670

6771
def _assert_key_instance(self, usage_key: LibraryUsageLocatorV2 | LibraryContainerLocator):
68-
assert isinstance(usage_key, LibraryUsageLocatorV2) or isinstance(usage_key, LibraryContainerLocator)
72+
assert isinstance(usage_key, (LibraryUsageLocatorV2, LibraryContainerLocator))
6973

7074
def _check_perm(self, user: UserType, lib_key: LibraryLocatorV2, perm) -> bool:
7175
""" Helper method to check a permission for the various can_ methods"""

0 commit comments

Comments
 (0)