@@ -35,7 +35,7 @@ def __init__(self, root_block_usage_key, modulestore, cache):
35
35
self .modulestore = modulestore
36
36
self .store = BlockStructureStore (cache )
37
37
38
- def get_transformed (self , transformers , starting_block_usage_key = None , collected_block_structure = None ):
38
+ def get_transformed (self , transformers , starting_block_usage_key = None , collected_block_structure = None , user = None ):
39
39
"""
40
40
Returns the transformed Block Structure for the root_block_usage_key,
41
41
starting at starting_block_usage_key, getting block data from the cache
@@ -57,11 +57,14 @@ def get_transformed(self, transformers, starting_block_usage_key=None, collected
57
57
get_collected. Can be optionally provided if already available,
58
58
for optimization.
59
59
60
+ user (django.contrib.auth.models.User) - User object for
61
+ which the block structure is to be transformed.
62
+
60
63
Returns:
61
64
BlockStructureBlockData - A transformed block structure,
62
65
starting at starting_block_usage_key.
63
66
"""
64
- block_structure = collected_block_structure .copy () if collected_block_structure else self .get_collected ()
67
+ block_structure = collected_block_structure .copy () if collected_block_structure else self .get_collected (user )
65
68
66
69
if starting_block_usage_key :
67
70
# Override the root_block_usage_key so traversals start at the
@@ -77,7 +80,7 @@ def get_transformed(self, transformers, starting_block_usage_key=None, collected
77
80
transformers .transform (block_structure )
78
81
return block_structure
79
82
80
- def get_collected (self ):
83
+ def get_collected (self , user = None ):
81
84
"""
82
85
Returns the collected Block Structure for the root_block_usage_key,
83
86
getting block data from the cache and modulestore, as needed.
@@ -86,6 +89,10 @@ def get_collected(self):
86
89
the modulestore is accessed if needed (at cache miss), and the
87
90
transformers data is collected if needed.
88
91
92
+ In the case of a cache miss, the function bypasses runtime access checks for the current
93
+ user. This is done to prevent inconsistencies in the data, which can occur when
94
+ certain blocks are inaccessible due to access restrictions.
95
+
89
96
Returns:
90
97
BlockStructureBlockData - A collected block structure,
91
98
starting at root_block_usage_key, with collected data
@@ -99,7 +106,15 @@ def get_collected(self):
99
106
BlockStructureTransformers .verify_versions (block_structure )
100
107
101
108
except (BlockStructureNotFound , TransformerDataIncompatible ):
102
- block_structure = self ._update_collected ()
109
+ if user :
110
+ # This bypasses the runtime access checks. When we are populating the course blocks cache,
111
+ # we do not want to perform access checks. Access checks result in inconsistent blocks where
112
+ # inaccessible blocks are missing from the cache. Cached course blocks are then used for all the users.
113
+ user .known = False
114
+ block_structure = self ._update_collected ()
115
+ user .known = True
116
+ else :
117
+ block_structure = self ._update_collected ()
103
118
104
119
return block_structure
105
120
0 commit comments