@@ -149,6 +149,74 @@ def test_views_lti_select(self):
149149 {"can_access_dashboard" : False , "can_update" : True },
150150 )
151151
152+ @override_settings (
153+ DOCUMENT_ENABLED = False , VIDEO_ENABLED = False , WEBINAR_ENABLED = False
154+ )
155+ def test_views_lti_select_disabled (self ):
156+ """Frontend context flags should be disabled when flags are disabled."""
157+ lti_consumer_parameters = {
158+ "roles" : random .choice (["instructor" , "administrator" ]),
159+ "content_item_return_url" : "https://lti-consumer.site/lti" ,
160+ "context_id" : "sent_lti_context_id" ,
161+ "title" : "Sent LMS activity title" ,
162+ "text" : "Sent LMS activity text" ,
163+ }
164+ lti_parameters , passport = generate_passport_and_signed_lti_parameters (
165+ url = "http://testserver/lti/select/" ,
166+ lti_parameters = lti_consumer_parameters ,
167+ )
168+
169+ resolutions = [144 ]
170+ playlist = PlaylistFactory (
171+ lti_id = lti_parameters .get ("context_id" ),
172+ consumer_site = passport .consumer_site ,
173+ )
174+ VideoFactory (
175+ playlist = playlist ,
176+ uploaded_on = timezone .now (),
177+ resolutions = resolutions ,
178+ position = 1 ,
179+ )
180+ DocumentFactory (
181+ playlist = playlist ,
182+ uploaded_on = timezone .now (),
183+ )
184+ VideoFactory (
185+ playlist = playlist ,
186+ live_state = IDLE ,
187+ live_type = JITSI ,
188+ position = 2 ,
189+ )
190+ VideoFactory (
191+ playlist = playlist ,
192+ live_state = ENDED ,
193+ live_type = JITSI ,
194+ position = 3 ,
195+ )
196+
197+ response = self .client .post (
198+ "/lti/select/" ,
199+ lti_parameters ,
200+ HTTP_REFERER = "http://testserver" ,
201+ )
202+ self .assertEqual (response .status_code , 200 )
203+ self .assertContains (response , "<html>" )
204+
205+ match = re .search (
206+ '<div id="marsha-frontend-data" data-context="(.*)">' ,
207+ response .content .decode ("utf-8" ),
208+ )
209+ context = json .loads (unescape (match .group (1 )))
210+
211+ self .assertFalse (context .get ("flags" ).get ("document" ))
212+ self .assertIsNone (context .get ("document" ))
213+
214+ self .assertFalse (context .get ("flags" ).get ("video" ))
215+ self .assertIsNone (context .get ("video" ))
216+
217+ self .assertFalse (context .get ("flags" ).get ("webinar" ))
218+ self .assertIsNone (context .get ("webinar" ))
219+
152220 def test_views_lti_select_video (self ):
153221 """
154222 Validate the context passed to the frontend app for an LTI Content selection targeting
@@ -242,6 +310,60 @@ def test_views_lti_select_video(self):
242310 {"can_access_dashboard" : False , "can_update" : True },
243311 )
244312
313+ @override_settings (VIDEO_ENABLED = False )
314+ def test_views_lti_select_video_disabled (self ):
315+ """
316+ Frontend context flag should be disabled when flag is disabled."""
317+ lti_consumer_parameters = {
318+ "roles" : random .choice (["instructor" , "administrator" ]),
319+ "content_item_return_url" : "https://lti-consumer.site/lti" ,
320+ "context_id" : "sent_lti_context_id" ,
321+ "title" : "Sent LMS activity title" ,
322+ "text" : "Sent LMS activity text" ,
323+ }
324+ lti_parameters , passport = generate_passport_and_signed_lti_parameters (
325+ url = "http://testserver/lti/select/video/" ,
326+ lti_parameters = lti_consumer_parameters ,
327+ )
328+
329+ playlist = PlaylistFactory (
330+ lti_id = lti_parameters .get ("context_id" ),
331+ consumer_site = passport .consumer_site ,
332+ )
333+ VideoFactory (
334+ playlist = playlist ,
335+ uploaded_on = timezone .now (),
336+ resolutions = [144 ],
337+ position = 1 ,
338+ )
339+ DocumentFactory (
340+ playlist = playlist ,
341+ uploaded_on = timezone .now (),
342+ )
343+ VideoFactory (
344+ playlist = playlist ,
345+ live_state = IDLE ,
346+ live_type = JITSI ,
347+ position = 2 ,
348+ )
349+
350+ response = self .client .post (
351+ "/lti/select/video/" ,
352+ lti_parameters ,
353+ HTTP_REFERER = "http://testserver" ,
354+ )
355+ self .assertEqual (response .status_code , 200 )
356+ self .assertContains (response , "<html>" )
357+
358+ match = re .search (
359+ '<div id="marsha-frontend-data" data-context="(.*)">' ,
360+ response .content .decode ("utf-8" ),
361+ )
362+ context = json .loads (unescape (match .group (1 )))
363+
364+ self .assertFalse (context .get ("flags" ).get ("video" ))
365+ self .assertIsNone (context .get ("video" ))
366+
245367 @override_settings (LTI_CONFIG_TITLE = "Marsha" )
246368 def test_views_lti_select_default_title (self ):
247369 """Validate the context passed to the frontend app for an LTI Content selection."""
0 commit comments