Repository: oppia/oppia

Issue:
Eliminate jQuery ajax call and ts-ignore and use Angular's HttpClient.
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
Currently, we are migrating Angular services and we use ```new AbcService()``` syntax to provide this service as a dependency to the other services that are not yet migrated. So if we introduce HttpClient in the csrfTokenService, we'll have to do ```new CsrfTokenService(new HttpClient())``` in the ```UpgradedService.ts``` file which is not possible to do since HttpClient can't be instantiated. Hence we have to keep using jquery's ajax call until **the service migrated is complete.**

Once the angular migration is done, we will no longer need to provide the ```upgraded services ```as we do now to the AngularJS services by creating instances, hence we won't need the above syntax(new HttpClient()) and hence our problem will be solved.

Todo: Convert the $.ajax call to angular HttpClient once the service migration is completed and remove the usage of @ts-ignore and find the exact type to be used. A helper todo for Angular Migration.

Files: 
csrf-token.service.ts
csrf-token.service.spec.ts
   



Discussion:
Not needed anymore!
@Showtim3, Can you please add details on why this is not needed anymore? (Just to keep a record in the issue thread) 
Since, we are not using jquery anymore in the CsrfTokenService, (which was causing some type inconsistencies), so the ts-ignore is also removed from that part of the codebase and this issue was created to keep a track of the ts-ignore, hence this issue is not needed anymore. [link](https://github.com/oppia/oppia/pull/7818/files/dae4ff8c4e4cdd741accb412692c4f38e2e7dad3#r349940856)
Reopening this....and updated the description.


Resolving patch:
diff --git a/core/controllers/oppia_root.py b/core/controllers/oppia_root.py
--- a/core/controllers/oppia_root.py
+++ b/core/controllers/oppia_root.py
@@ -24,13 +24,31 @@
 
 class OppiaRootPage(base.BaseHandler):
     """Renders oppia root page (unified entry point) for all routes registered
-       with angular router.
+    with angular router.
     """
 
     # Using type ignore[misc] here because untyped decorator makes function
     # "get" also untyped.
+    # The '**kwargs' argument is needed because some routes pass keyword
+    # arguments and even when we don't use them we need to allow them so that
+    # there is no error in the callsite.
     @acl_decorators.open_access # type: ignore[misc]
-    def get(self, **kwargs: Dict[str, str]) -> None: # pylint: disable=unused-argument
+    def get(self, **kwargs: Dict[str, str]) -> None:
         """Handles GET requests."""
-        self.render_template( # type: ignore[no-untyped-call]
-            'oppia-root.mainpage.html')
+        self.render_template('oppia-root.mainpage.html') # type: ignore[no-untyped-call]
+
+
+class OppiaLightweightRootPage(base.BaseHandler):
+    """Renders lightweight oppia root page (unified entry point) for all routes
+    registered with angular router.
+    """
+
+    # Using type ignore[misc] here because untyped decorator makes function
+    # "get" also untyped.
+    # The '**kwargs' argument is needed because some routes pass keyword
+    # arguments and even when we don't use them we need to allow them so that
+    # there is no error in the callsite.
+    @acl_decorators.open_access # type: ignore[misc]
+    def get(self, **kwargs: Dict[str, str]) -> None:
+        """Handles GET requests."""
+        self.render_template('lightweight-oppia-root.mainpage.html') # type: ignore[no-untyped-call]
diff --git a/core/handler_schema_constants.py b/core/handler_schema_constants.py
--- a/core/handler_schema_constants.py
+++ b/core/handler_schema_constants.py
@@ -88,9 +88,6 @@
     'ValueGeneratorHandler',
     'VoiceArtistManagementHandler',
     'OppiaMLVMHandler',
-    # Oppia Root page is the unified entry for page routes to the frontend.
-    # So, it should exempted from schema validation.
-    'OppiaRootPage',
     'CsrfTokenHandler',
     'Error404Handler',
     'FrontendErrorHandler',
@@ -103,7 +100,11 @@
 HANDLER_CLASS_NAMES_WHICH_DO_NOT_REQUIRE_SCHEMAS = [
     'SessionBeginHandler',
     'SessionEndHandler',
-    'SeedFirebaseHandler'
+    'SeedFirebaseHandler',
+    # Oppia root page is the unified entry for page routes to the frontend.
+    # So, it should exempted from schema validation.
+    'OppiaRootPage',
+    'OppiaLightweightRootPage'
 ]
 
 # HANDLER_CLASS_NAMES_WITH_NO_SCHEMA is addressed everywhere in the
diff --git a/main.py b/main.py
--- a/main.py
+++ b/main.py
@@ -938,9 +938,17 @@ def get_redirect_route(
 # Redirect all routes handled using angular router to the oppia root page.
 for page in constants.PAGES_REGISTERED_WITH_FRONTEND.values():
     if not 'MANUALLY_REGISTERED_WITH_BACKEND' in page:
-        URLS.append(
-            get_redirect_route(
-                r'/%s' % page['ROUTE'], oppia_root.OppiaRootPage))
+        if 'LIGHTWEIGHT' in page:
+            URLS.append(
+                get_redirect_route(
+                    r'/%s' % page['ROUTE'],
+                    oppia_root.OppiaLightweightRootPage
+                )
+            )
+        else:
+            URLS.append(
+                get_redirect_route(
+                    r'/%s' % page['ROUTE'], oppia_root.OppiaRootPage))
 
 # Manually redirect routes with url fragments to the oppia root page.
 URLS.extend((
@@ -949,7 +957,9 @@ def get_redirect_route(
         r'%s/story/<story_url_fragment>' % feconf.TOPIC_VIEWER_URL_PREFIX,
         oppia_root.OppiaRootPage),
     get_redirect_route(
-        r'/learn/<classroom_url_fragment>', oppia_root.OppiaRootPage),
+        r'/learn/<classroom_url_fragment>',
+        oppia_root.OppiaLightweightRootPage
+    ),
 ))
 
 # Add cron urls. Note that cron URLs MUST start with /cron for them to work


Test patch:
diff --git a/core/controllers/base_test.py b/core/controllers/base_test.py
--- a/core/controllers/base_test.py
+++ b/core/controllers/base_test.py
@@ -459,7 +459,7 @@ def test_signup_attempt_on_wrong_page_fails(self):
             ))
             response = self.get_html_response('/', expected_status_int=200)
             self.assertIn(
-                b'<oppia-root></oppia-root>',
+                b'<lightweight-oppia-root></lightweight-oppia-root>',
                 response.body
             )
 
diff --git a/core/controllers/classroom_test.py b/core/controllers/classroom_test.py
--- a/core/controllers/classroom_test.py
+++ b/core/controllers/classroom_test.py
@@ -46,7 +46,8 @@ class ClassroomPageTests(BaseClassroomControllerTests):
 
     def test_any_user_can_access_classroom_page(self):
         response = self.get_html_response('/learn/math')
-        self.assertIn('<oppia-root></oppia-root>', response)
+        self.assertIn(
+            '<lightweight-oppia-root></lightweight-oppia-root>', response)
 
 
 class ClassroomDataHandlerTests(BaseClassroomControllerTests):
diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py
--- a/core/controllers/creator_dashboard_test.py
+++ b/core/controllers/creator_dashboard_test.py
@@ -78,7 +78,7 @@ def test_logged_out_homepage(self):
         """Test the logged-out version of the home page."""
         response = self.get_html_response('/')
         self.assertEqual(response.status_int, 200)
-        self.assertIn('</oppia-root>', response)
+        self.assertIn('</lightweight-oppia-root>', response)
 
 
 class CreatorDashboardHandlerTests(test_utils.GenericTestBase):
diff --git a/core/controllers/oppia_root_test.py b/core/controllers/oppia_root_test.py
--- a/core/controllers/oppia_root_test.py
+++ b/core/controllers/oppia_root_test.py
@@ -26,6 +26,10 @@ def test_oppia_root_page(self) -> None:
         """Tests access to the unified entry page."""
         for page in constants.PAGES_REGISTERED_WITH_FRONTEND.values():
             if not 'MANUALLY_REGISTERED_WITH_BACKEND' in page:
-                response = self.get_html_response( # type: ignore[no-untyped-call]
+                response = self.get_html_response(  # type: ignore[no-untyped-call]
                     '/%s' % page['ROUTE'], expected_status_int=200)
-                response.mustcontain('<oppia-root></oppia-root>')
+                if 'LIGHTWEIGHT' in page:
+                    response.mustcontain(
+                        '<lightweight-oppia-root></lightweight-oppia-root>')
+                else:
+                    response.mustcontain('<oppia-root></oppia-root>')