Repository: oppia/oppia

Issue:
Maths classroom page on test server throwing error
<!--
  - 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**
Maths classroom page on test server throwing error

**To Reproduce**
Steps to reproduce the behavior:
 1. Go to [/math](https://oppiatestserver.appspot.com/math)
 2. Check errors

**Observed behavior**
Error logs on the page and the pages don't load completely.

**Screenshots**
![image](https://user-images.githubusercontent.com/16653571/81873558-a17bc700-9599-11ea-88e0-a1a85aae76bd.png)
Maths classroom page on test server throwing error
<!--
  - 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**
Maths classroom page on test server throwing error

**To Reproduce**
Steps to reproduce the behavior:
 1. Go to [/math](https://oppiatestserver.appspot.com/math)
 2. Check errors

**Observed behavior**
Error logs on the page and the pages don't load completely.

**Screenshots**
![image](https://user-images.githubusercontent.com/16653571/81873558-a17bc700-9599-11ea-88e0-a1a85aae76bd.png)


Discussion:
@iamprayush, Can you please check what's going on here? Seems related to PR #9109

Note: This is blocking the release, so we need to fix this quickly!

/cc @aks681  
>  (Does not work on the test server, presumably because the classroom page is not ready for release yet)

I found this comment in the cherry-pick testing doc [here](https://docs.google.com/document/d/1ERrLgn3_ACFagvroXnjosgy7KUUcyacJVB02XIrYlSs/edit). So should we close this issue? [Though I don't think we should show error on test server, will it be same on prod?] 
It's not correct to show errors -- but shouldn't the classroom page be hidden behind a flag, and shouldn't that flag be set to False? I didn't think we were releasing it yet. /cc @aks681 @kevintab95 
Yes, this is because the classroom page has not been released yet. But, I don't think this is blocking since there is no way to access the classroom page since the callout and the buttons that lead to the classroom page are hidden behind a flag. So, unless the user explicitly enters `/math` in the search bar, they shouldn't even be landing on this page.

/cc @DubeySandeep @seanlip 
Disable the flag if the page is not ready for release. [Expect user can enter `/math` so we need to disable this and we should not expect any error on a prod or test server for any random usage!]

Can you please create a PR and disable the classroom page if it's not ready! Also, even if there isn't any classroom data the page should not fail, right?
Currently, the buttons that lead to the page are hidden behind a flag, but the page is still accessible via querying the URL directly. I'll create a PR that throws a 404 when the user tries to access this page and the flag is disabled.
@iamprayush, Can you please check what's going on here? Seems related to PR #9109

Note: This is blocking the release, so we need to fix this quickly!

/cc @aks681  
>  (Does not work on the test server, presumably because the classroom page is not ready for release yet)

I found this comment in the cherry-pick testing doc [here](https://docs.google.com/document/d/1ERrLgn3_ACFagvroXnjosgy7KUUcyacJVB02XIrYlSs/edit). So should we close this issue? [Though I don't think we should show error on test server, will it be same on prod?] 
It's not correct to show errors -- but shouldn't the classroom page be hidden behind a flag, and shouldn't that flag be set to False? I didn't think we were releasing it yet. /cc @aks681 @kevintab95 
Yes, this is because the classroom page has not been released yet. But, I don't think this is blocking since there is no way to access the classroom page since the callout and the buttons that lead to the classroom page are hidden behind a flag. So, unless the user explicitly enters `/math` in the search bar, they shouldn't even be landing on this page.

/cc @DubeySandeep @seanlip 
Disable the flag if the page is not ready for release. [Expect user can enter `/math` so we need to disable this and we should not expect any error on a prod or test server for any random usage!]

Can you please create a PR and disable the classroom page if it's not ready! Also, even if there isn't any classroom data the page should not fail, right?
Currently, the buttons that lead to the page are hidden behind a flag, but the page is still accessible via querying the URL directly. I'll create a PR that throws a 404 when the user tries to access this page and the flag is disabled.

Resolving patch:
diff --git a/core/controllers/classroom.py b/core/controllers/classroom.py
--- a/core/controllers/classroom.py
+++ b/core/controllers/classroom.py
@@ -32,7 +32,8 @@ class ClassroomPage(base.BaseHandler):
     def get(self):
         """Handles GET requests."""
 
-        if not constants.ENABLE_NEW_STRUCTURE_PLAYERS:
+        if not constants.ENABLE_NEW_STRUCTURE_PLAYERS or not (
+                config_domain.CLASSROOM_PAGE_IS_SHOWN.value):
             raise self.PageNotFoundException
 
         self.render_template('classroom-page.mainpage.html')
@@ -72,3 +73,19 @@ def get(self, classroom_name):
             'topic_summary_dicts': topic_summary_dicts
         })
         self.render_json(self.values)
+
+
+class ClassroomPageStatusHandler(base.BaseHandler):
+    """The handler for checking whether the classroom page is shown."""
+
+    GET_HANDLER_ERROR_RETURN_TYPE = feconf.HANDLER_TYPE_JSON
+    # This prevents partially logged in user from being logged out
+    # during user registration.
+    REDIRECT_UNFINISHED_SIGNUPS = False
+
+    @acl_decorators.open_access
+    def get(self):
+        self.render_json({
+            'classroom_page_is_shown': (
+                config_domain.CLASSROOM_PAGE_IS_SHOWN.value)
+        })
diff --git a/core/domain/config_domain.py b/core/domain/config_domain.py
--- a/core/domain/config_domain.py
+++ b/core/domain/config_domain.py
@@ -341,3 +341,7 @@ def get_all_config_property_names(cls):
     'always_ask_learners_for_answer_details', BOOL_SCHEMA,
     'Always ask learners for answer details. For testing -- do not use',
     False)
+
+CLASSROOM_PAGE_IS_SHOWN = ConfigProperty(
+    'classroom_page_is_shown', BOOL_SCHEMA,
+    'Show classroom components.', False)
diff --git a/main.py b/main.py
--- a/main.py
+++ b/main.py
@@ -698,6 +698,9 @@ def ui_access_wrapper(self, *args, **kwargs):
         feconf.VALIDATE_STORY_EXPLORATIONS_URL_PREFIX,
         story_editor.ValidateExplorationsHandler),
 
+    get_redirect_route(
+        '/classroom_page_status_handler', classroom.ClassroomPageStatusHandler),
+
     get_redirect_route(r'/emaildashboard', email_dashboard.EmailDashboardPage),
     get_redirect_route(
         r'/emaildashboarddatahandler',


Test patch:
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
@@ -37,13 +37,25 @@ def setUp(self):
 class ClassroomPageTests(BaseClassroomControllerTests):
 
     def test_any_user_can_access_classroom_page(self):
+        config_property = config_domain.Registry.get_config_property(
+            'classroom_page_is_shown')
+        config_property.set_value('committer_id', True)
         with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True):
             response = self.get_html_response('/math')
             self.assertIn('<classroom-page></classroom-page>', response)
+        config_property.set_value('committer_id', False)
 
     def test_get_fails_when_new_structures_not_enabled(self):
+        config_property = config_domain.Registry.get_config_property(
+            'classroom_page_is_shown')
+        config_property.set_value('committer_id', True)
         with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', False):
             self.get_html_response('/math', expected_status_int=404)
+        config_property.set_value('committer_id', False)
+
+    def test_get_fails_when_classroom_page_is_shown_not_enabled(self):
+        with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True):
+            self.get_html_response('/math', expected_status_int=404)
 
 
 class ClassroomDataHandlerTests(BaseClassroomControllerTests):
@@ -106,3 +118,22 @@ def test_get_fails_when_new_structures_not_enabled(self):
             self.get_json(
                 '%s/%s' % (feconf.CLASSROOM_DATA_HANDLER, 'math'),
                 expected_status_int=404)
+
+
+class ClassroomPageStatusHandlerTests(BaseClassroomControllerTests):
+    """Unit test for ClassroomPageStatusHandler."""
+    def test_get_request_returns_correct_status(self):
+        self.set_config_property(config_domain.CLASSROOM_PAGE_IS_SHOWN, False)
+
+        response = self.get_json('/classroom_page_status_handler')
+        self.assertEqual(
+            response, {
+                'classroom_page_is_shown': False
+            })
+
+        self.set_config_property(config_domain.CLASSROOM_PAGE_IS_SHOWN, True)
+        response = self.get_json('/classroom_page_status_handler')
+        self.assertEqual(
+            response, {
+                'classroom_page_is_shown': True,
+            })
diff --git a/core/tests/protractor_desktop/classroomPage.js b/core/tests/protractor_desktop/classroomPage.js
--- a/core/tests/protractor_desktop/classroomPage.js
+++ b/core/tests/protractor_desktop/classroomPage.js
@@ -22,19 +22,25 @@ var users = require('../protractor_utils/users.js');
 var waitFor = require('../protractor_utils/waitFor.js');
 var workflow = require('../protractor_utils/workflow.js');
 
+var AdminPage = require('../protractor_utils/AdminPage.js');
 var ClassroomPage = require('../protractor_utils/ClassroomPage.js');
 var LibraryPage = require('../protractor_utils/LibraryPage.js');
 
 describe('Classroom page functionality', function() {
+  var adminPage = null;
   var classroomPage = null;
   var libraryPage = null;
 
   beforeAll(function() {
+    adminPage = new AdminPage.AdminPage();
     classroomPage = new ClassroomPage.ClassroomPage();
     libraryPage = new LibraryPage.LibraryPage();
 
     users.createAndLoginAdminUser(
       'creator@classroomPage.com', 'creatorClassroomPage');
+    adminPage.editConfigProperty(
+      'Show classroom components.',
+      'Boolean', (elem) => elem.setValue(true));
   });
 
   beforeEach(function() {
diff --git a/core/tests/protractor_desktop/classroomPageFileUploadFeatures.js b/core/tests/protractor_desktop/classroomPageFileUploadFeatures.js
--- a/core/tests/protractor_desktop/classroomPageFileUploadFeatures.js
+++ b/core/tests/protractor_desktop/classroomPageFileUploadFeatures.js
@@ -44,6 +44,9 @@ describe('Classroom page functionality', function() {
 
     users.createAndLoginAdminUser(
       'creator@classroomPage.com', 'creatorClassroomPage');
+    adminPage.editConfigProperty(
+      'Show classroom components.',
+      'Boolean', (elem) => elem.setValue(true));
   });
 
   beforeEach(function() {