Repository: oppia/oppia

Issue:
FetchIssuesHandler should respond with a JSON object instead of an array
`FetchIssuesHandler` ([link](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/controllers/editor.py#L526)) currently responds to GET requests with a JSON array. This conflicts with HTTP best practices, and should be changed to respond with a JSON object instead.

The fix itself is straightforward. We should change the return value from:
```python
self.render_json(exp_issues_dict['unresolved_issues'])
```
to:
```python
self.render_json(exp_issues_dict)
```

We will need to update the corresponding `PlaythroughIssuesBackendApiService` ([link](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/templates/services/playthrough-issues-backend-api.service.ts#L33)) and unit tests accordingly as well.


Discussion:
Hi, I would like to work on this issue! I'm new to Oppia, so I will need a little guidance.
Hi @ayegnb, it's all yours! I'm happy to give you a starting point, and can be reached for questions on Gitter or through email (brian@brianrodri.com).

Happy coding :)

---
Here are the files I expect will need changing:
- [core/controllers/editor.py#L548](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/controllers/editor.py#L548) (backend)
- [core/controllers/editor_test.py#L1842](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/controllers/editor_test.py#L1842) (backend unit tests)
- [core/templates/services/playthrough-issues-backend-api.service.ts#L57](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/templates/services/playthrough-issues-backend-api.service.ts#L57-L62) (frontend)
- [core/templates/services/playthrough-issues-backend-api.service.spec.ts#L34](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/templates/services/playthrough-issues-backend-api.service.spec.ts#L34-L47) (frontend unit tests)

You'll need to update the backend/frontend independently, since they aren't automatically kept in-sync. You should write and run unit tests to confirm whether your changes work as intended. Here are the commands to do so:
```bash
# Backend tests:
python -m scripts.run_backend_tests --test_target=core.controllers.editor_test.FetchIssuesPlaythroughHandlerTests
# Frontend tests:
python -m scripts.run_frontend_tests
```

Finally, in order to understand what the new JSON response will become, you'll need to know what the dict format of `exp_issues` is. Here is the definition: [core/domain/stats_domain.py](https://github.com/oppia/oppia/blob/84c00daefcda8174bf312e11106c31940b96fd4a/core/domain/stats_domain.py#L455).

Feel free to contact me for anything else you'd like help finding/understanding!
@brianrodri, I have written to you in the gitter. Could you please read the message from me there?
@ayegnb are u still working on this?
@brianrodri Should i give it a try?

Hi @Radesh-kumar, thanks for offering, sure! I've just assigned you, feel free to assign me as reviewer once your PR is ready.
@brianrodri Thanks for assigning.
Can you suggest to me how to reproduce any of these issues on FE(multiple-incorrect-issue,cyclic-transitions-issue).
I tried but failed to reproduce, Are these related to the Statistics tab in Exploration Editor?
> @brianrodri Thanks for assigning.
> Can you suggest to me how to reproduce any of these issues on FE(multiple-incorrect-issue,cyclic-transitions-issue).
> I tried but failed to reproduce, Are these related to the Statistics tab in Exploration Editor?

@kevintab95 @nithusha21 need some help.
@brianrodri After a while of backtracking calls, I figured out that the playthrough-issues.component is never been used (dead), @DubeySandeep told me to ping in here so it will be helpful for others too.
@brianrodri Can you help me to reproduce this issue?
@Radesh-kumar Are you still working on this ? Please ping me if you want to continue working on this issue.

@brianrodri I am taking up this issue. Thanks!
Overdue follow-up here (sorry for lateness): there is no way to test this in production yet because this code is unused. The code will be re-used eventually, so as long as unit tests pass it's fine to post the PR.

Resolving patch:
diff --git a/core/controllers/editor.py b/core/controllers/editor.py
--- a/core/controllers/editor.py
+++ b/core/controllers/editor.py
@@ -558,7 +558,7 @@ def get(self, exp_id):
                 unresolved_issues.append(issue)
         exp_issues.unresolved_issues = unresolved_issues
         exp_issues_dict = exp_issues.to_dict()
-        self.render_json(exp_issues_dict['unresolved_issues'])
+        self.render_json(exp_issues_dict)
 
 
 class FetchPlaythroughHandler(EditorHandler):


Test patch:
diff --git a/core/controllers/editor_test.py b/core/controllers/editor_test.py
--- a/core/controllers/editor_test.py
+++ b/core/controllers/editor_test.py
@@ -2114,10 +2114,12 @@ def test_fetch_issues_handler(self):
         response = self.get_json(
             '/issuesdatahandler/%s' % self.EXP_ID,
             params={'exp_version': 1})
-        self.assertEqual(len(response), 2)
-        self.assertEqual(response[0]['issue_type'], 'EarlyQuit')
+        self.assertEqual(len(response['unresolved_issues']), 2)
         self.assertEqual(
-            response[1]['issue_type'], 'MultipleIncorrectSubmissions')
+            response['unresolved_issues'][0]['issue_type'], 'EarlyQuit')
+        self.assertEqual(
+            response['unresolved_issues'][1]['issue_type'],
+            'MultipleIncorrectSubmissions')
 
     def test_invalid_issues_are_not_retrieved(self):
         """Test that invalid issues are not retrieved."""
@@ -2130,8 +2132,9 @@ def test_invalid_issues_are_not_retrieved(self):
         response = self.get_json(
             '/issuesdatahandler/%s' % self.EXP_ID,
             params={'exp_version': 1})
-        self.assertEqual(len(response), 1)
-        self.assertEqual(response[0]['issue_type'], 'EarlyQuit')
+        self.assertEqual(len(response['unresolved_issues']), 1)
+        self.assertEqual(
+            response['unresolved_issues'][0]['issue_type'], 'EarlyQuit')
 
     def test_fetch_playthrough_handler(self):
         """Test that the playthrough gets fetched correctly."""