Repository: learningequality/kolibri

Issue:
Quizzes - The 'missing resource' alert is not displayed at the Home page
## Observed behavior

Observed while testing https://github.com/learningequality/kolibri/pull/11426 - quizzes with missing resources are not showing an alert on the home page.

## Expected behavior
To be further discussed.

## Steps to reproduce the issue
1. Install the latest build from https://github.com/learningequality/kolibri/pull/11426 and setup a full facility and a learn-only device.
2. Assign a quiz to the learner on the LOD.
3. Sign in as the learner and delete some of the quiz resources by going to Device > Channel
4. Go to the quiz an observe that it correctly alerts for missing resources.
5. Go to the learner's home page and observe that there the alert 'Some resources are missing or not supported..' is missing.

## More information

Video with replications steps - the original was more than 10 minutes long, so I had to shorten it:

https://github.com/learningequality/kolibri/assets/79847249/8fb9dcb4-8419-4e01-8f8f-180d39a3ad91

## Usage Details
Kolibri 0.16beta6
Ubuntu - Chrome, Firefox


Discussion:
@radinamatic @marcellamaki 
@pcenov just to clarify, the behavior of the missing alert on the home page is seen only with quizzes when following these steps, not if you do the same with lesson resources? I realize the quiz format is different, but if you
1. Assign a lesson to the learner on the LOD.
2. Sign in as the learner and delete some of the quiz resources by going to Device > Channel
If you go to the home page, is the alert 'Some resources are missing or not supported..' missing? Thank you!
Hi @marcellamaki - yes, the issue I've described here is specifically about the assigned quizzes with missing resources and not about assigned lessons containing missing quiz resources. 
@radinamatic we've discussed this and it's still valid.
@radinamatic - I confirm that this is still extant in the official 0.16 build. 

Quiz with missing resources (in which case we have to open the quiz to see that there are missing resources):

https://github.com/learningequality/kolibri/assets/79847249/f2426f8c-03a6-4b89-9ccf-d37e8a3b9047

Lesson with missing quiz resources (in which case the 'missing resource' alert is clearly displayed):

https://github.com/learningequality/kolibri/assets/79847249/e8037376-9d42-4e08-a606-d16085cbf420



Thank you for confirming, @pcenov! 🙏🏽 

@marcellamaki I believe with the recordings provided the inconsistent experience is now clear, and the priority to be fixed in the upcoming patch should remain P1. 

Resolving patch:
diff --git a/kolibri/plugins/learn/viewsets.py b/kolibri/plugins/learn/viewsets.py
--- a/kolibri/plugins/learn/viewsets.py
+++ b/kolibri/plugins/learn/viewsets.py
@@ -54,6 +54,16 @@ def get(self, request, format=None):
         )
 
 
+def _map_contentnodes(request, content_ids):
+    contentnodes = (
+        contentnode_viewset.serialize_list(request, {"ids": content_ids})
+        if content_ids
+        else []
+    )
+    contentnode_map = {c["id"]: c for c in contentnodes}
+    return contentnode_map
+
+
 def _consolidate_lessons_data(request, lessons):
     lesson_contentnode_ids = set()
     for lesson in lessons:
@@ -69,16 +79,10 @@ def _consolidate_lessons_data(request, lessons):
         else []
     )
 
-    contentnodes = (
-        contentnode_viewset.serialize_list(request, {"ids": lesson_contentnode_ids})
-        if lesson_contentnode_ids
-        else []
-    )
+    contentnode_map = _map_contentnodes(request, lesson_contentnode_ids)
 
     progress_map = {l["content_id"]: l["progress"] for l in contentnode_progress}
 
-    contentnode_map = {c["id"]: c for c in contentnodes}
-
     for lesson in lessons:
         lesson["progress"] = {
             "resource_progress": sum(
@@ -198,6 +202,8 @@ def consolidate(self, items, queryset):
             )
         )
 
+        contentnode_map = _map_contentnodes(self.request, available_exam_ids)
+
         for exam in exams:
             closed = exam.pop("closed")
             score = exam.pop("score")
@@ -216,10 +222,12 @@ def consolidate(self, items, queryset):
                     "closed": None,
                     "started": False,
                 }
-            exam["missing_resource"] = any(
-                question["exercise_id"] not in available_exam_ids
-                for question in exam.get("question_sources")
-            )
+            missing_resource = False
+            for question_source in exam["question_sources"]:
+                if question_source["exercise_id"] not in contentnode_map:
+                    missing_resource = True
+                    break
+            exam["missing_resource"] = missing_resource
         out_items = []
         for item in items:
             item["assignments"] = {


Test patch: