@@ -43,6 +43,10 @@ def _format_date(date):
43
43
return date .strftime ('%Y-%m-%d %H:%M:%S' ) if isinstance (date , datetime ) else None
44
44
45
45
46
+ def _staff_user (block ):
47
+ return getattr (block .runtime , 'user_is_staff' , False )
48
+
49
+
46
50
def _render_summary (context ):
47
51
template = Template (summary_fragment )
48
52
return template .render (Context (context ))
@@ -135,7 +139,13 @@ class SummaryHookAside(XBlockAside):
135
139
def summary_handler (self , request = None , suffix = None ): # pylint: disable=unused-argument
136
140
"""
137
141
Extract and return summarizable text from unit children.
142
+
143
+ Only services and staff users are allowed to fetch summary text, everyone else
144
+ gets an unhelpful 403.
138
145
"""
146
+ if not _staff_user (self ):
147
+ return Response (status = 403 )
148
+
139
149
block = get_block (self .scope_ids .usage_id .usage_key )
140
150
valid = self .should_apply_to_block (block )
141
151
@@ -199,14 +209,7 @@ def _student_view_can_throw(self, block):
199
209
if length < settings .SUMMARY_HOOK_MIN_SIZE :
200
210
return fragment
201
211
202
- # thirdparty=true connects to the unauthenticated handler for now,
203
- # we will secure it in ACADEMIC-16187
204
- handler_url = self .runtime .handler_url (self , 'summary_handler' , thirdparty = True )
205
-
206
- # enable ai-spot to see the LMS when they are installed together in devstack
207
- aispot_lms_name = settings .AISPOT_LMS_NAME
208
- if aispot_lms_name != '' :
209
- handler_url = handler_url .replace ('localhost' , aispot_lms_name )
212
+ handler_url = self ._summary_handler_url ()
210
213
211
214
fragment .add_content (
212
215
_render_summary (
@@ -221,6 +224,24 @@ def _student_view_can_throw(self, block):
221
224
)
222
225
return fragment
223
226
227
+ def _summary_handler_url (self ):
228
+ """
229
+ Generate the summary handler URL for this block.
230
+
231
+ A separate function to handle overrides required
232
+ for the unusual use of the handler (non-edx codebase edx service)
233
+ and to override the URL for use in devstack.
234
+ """
235
+ # thirdparty=true gives the full host name and unauthenticated handler
236
+ handler_url = self .runtime .handler_url (self , 'summary_handler' , thirdparty = True )
237
+ # but we want the authenticated handler
238
+ handler_url = handler_url .replace ('handler_noauth' , 'handler' )
239
+ # enable ai-spot to see the LMS when they are installed together in devstack
240
+ aispot_lms_name = settings .AISPOT_LMS_NAME
241
+ if aispot_lms_name != '' :
242
+ handler_url = handler_url .replace ('localhost' , aispot_lms_name )
243
+ return handler_url
244
+
224
245
@classmethod
225
246
def should_apply_to_block (cls , block ):
226
247
"""
@@ -245,7 +266,6 @@ def _should_apply_can_throw(cls, block):
245
266
if getattr (block , 'category' , None ) != 'vertical' :
246
267
return False
247
268
course_key = block .scope_ids .usage_id .course_key
248
- if (getattr (block .runtime , 'user_is_staff' , False )
249
- and summary_staff_only (course_key )):
269
+ if _staff_user (block ) and summary_staff_only (course_key ):
250
270
return True
251
271
return summary_enabled (course_key )
0 commit comments