Repository: oppia/oppia

Issue:
Topic prerequisite skill checking is broken and prevents topic being published
**Describe the bug**

In a topic, chapters with prerequisite skills outside the topic make the topic unpublishable, because "this skill was not taught in any chapter before it". This behaviour is wrong because the validation error should only be triggered for skills that have been assigned to the topic currently being edited.

**To Reproduce**
Steps to reproduce the behavior:
 1. Create topic P (the prerequisite topic) and topic M (the main topic).
 2. Create skill S1 and assign it to P. Create skill S2 and assign it to M.
 3. Create a chapter in topic M and assign it a prerequisite skill of S1, and an acquired skill of S2.
 4. Save all changes.
 5. Refresh the page and try to publish the topic. This is not possible because of a validation error: "The skill with id XYZ was specified as a prerequisite for Chapter Name but was not taught in any chapter before it.". See screenshot below:
 
![Screenshot from 2022-02-24 18-00-50](https://user-images.githubusercontent.com/10575562/155502391-ff753a66-243d-43b9-9778-bf6c094118d8.png)

**Observed behavior**
The topic cannot be published, and further changes to the story/chapter cannot be saved, because the prerequisite skills include ones from outside the topic.

**Expected behavior**
The topic should be publishable. The validation message should **only** occur for skills that have been assigned to the main topic M, and not to other topics.



Discussion:
@krishita30j @Rijuta-s @Lawful2002 Would it be possible for the Quality team to take a look at this with some priority, please? It is blocking Percentages from being published.

Thanks!
Hey @seanlip I'm unable to reproduce this issue on develop. I've attached a screencast, please see if I'm missing something.

https://user-images.githubusercontent.com/73544247/155549029-b8dccd93-eb97-4901-9890-489c47afd277.mp4


Thanks for trying to repro, @Lawful2002!

Could you please try going into the chapter for topic 2, adding another prereq skill (or making some change), and seeing if you can save the draft? Also make sure the exploration attached to the chapter isn't published yet (since that was the case for the topic I was editing).
Update: I think the issue may be that the prereq skills were added on chapters 2, 3, and 4, so you might need to create a multi-chapter story to repro.

(Ignore the unpublished exps, sorry -- I think that probably has nothing to do with it. There's no reason why the prereq skills validation should be looking at exploration publication status, I think.)
@seanlip i'm working on it.

Already in discussion with @Lawful2002.

I am able to reproduce it. Correct, issue occur when we add prereq skills on chapters 2, 3 and 4,
We can also use published exploration for that.


Resolving patch:
diff --git a/core/controllers/story_editor.py b/core/controllers/story_editor.py
--- a/core/controllers/story_editor.py
+++ b/core/controllers/story_editor.py
@@ -81,10 +81,6 @@ def get(self, story_id):
         topic_id = story.corresponding_topic_id
         topic = topic_fetchers.get_topic_by_id(topic_id, strict=False)
         skill_ids = topic.get_all_skill_ids()
-        for node in story.story_contents.nodes:
-            for skill_id in node.prerequisite_skill_ids:
-                if skill_id not in skill_ids:
-                    skill_ids.append(skill_id)
 
         skill_summaries = skill_services.get_multi_skill_summaries(skill_ids)
         skill_summary_dicts = [summary.to_dict() for summary in skill_summaries]


Test patch:
diff --git a/core/controllers/story_editor_test.py b/core/controllers/story_editor_test.py
--- a/core/controllers/story_editor_test.py
+++ b/core/controllers/story_editor_test.py
@@ -439,9 +439,7 @@ def test_editable_story_handler_get(self):
                 feconf.STORY_EDITOR_DATA_URL_PREFIX, self.story_id))
         self.assertEqual(self.story_id, json_response['story']['id'])
         self.assertEqual('Name', json_response['topic_name'])
-        self.assertEqual(len(json_response['skill_summaries']), 1)
-        self.assertEqual(
-            json_response['skill_summaries'][0]['description'], 'Description 3')
+        self.assertEqual(len(json_response['skill_summaries']), 0)
         self.logout()
 
     def test_editable_story_handler_put(self):