Repository: oppia/oppia

Issue:
Don't populate user roles related information in general response for a request
Currently, we populate response with `is_admin`, `is_moderator`, `is_topic_mange` in the base handler. These values are unexpecdtly sent via most of the handlers. Through this issue we want to remove populating response with roles-related information.

Code pointer:
https://github.com/oppia/oppia/blob/0d80c5e6960b19721678dd13db68636a631282dc/core/controllers/base.py#L241-L245


Discussion:

Resolving patch:
diff --git a/core/controllers/admin.py b/core/controllers/admin.py
--- a/core/controllers/admin.py
+++ b/core/controllers/admin.py
@@ -201,19 +201,11 @@ def get(self):
             'demo_collections': sorted(feconf.DEMO_COLLECTIONS.items()),
             'demo_explorations': sorted(feconf.DEMO_EXPLORATIONS.items()),
             'demo_exploration_ids': demo_exploration_ids,
-            'updatable_roles': {
-                role: role_services.HUMAN_READABLE_ROLES[role]
-                for role in role_services.UPDATABLE_ROLES
-            },
-            'viewable_roles': {
-                role: role_services.HUMAN_READABLE_ROLES[role]
-                for role in role_services.VIEWABLE_ROLES
-            },
+            'updatable_roles': role_services.UPDATABLE_ROLES,
+            'viewable_roles': role_services.VIEWABLE_ROLES,
+            'human_readable_roles': role_services.HUMAN_READABLE_ROLES,
+            'role_to_actions': role_services.get_role_actions(),
             'topic_summaries': topic_summary_dicts,
-            'role_to_actions': {
-                role_services.HUMAN_READABLE_ROLES[role]: actions
-                for role, actions in role_services.get_role_actions().items()
-            },
             'feature_flags': feature_flag_dicts,
         })
 
@@ -687,7 +679,8 @@ class AdminRoleHandler(base.BaseHandler):
             },
             'role': {
                 'schema': {
-                    'type': 'basestring'
+                    'type': 'basestring',
+                    'choices': role_services.VIEWABLE_ROLES
                 },
                 'default_value': None
             },
@@ -733,14 +726,12 @@ def get(self):
         if filter_criterion == feconf.USER_FILTER_CRITERION_ROLE:
             role = self.normalized_request.get(
                 feconf.USER_FILTER_CRITERION_ROLE)
-            users_by_role = {
-                username: role
-                for username in user_services.get_usernames_by_role(role)
-            }
             role_services.log_role_query(
                 self.user_id, feconf.ROLE_ACTION_VIEW_BY_ROLE,
                 role=role)
-            self.render_json(users_by_role)
+            self.render_json({
+                'usernames': user_services.get_usernames_by_role(role)
+            })
         elif filter_criterion == feconf.USER_FILTER_CRITERION_USERNAME:
             username = self.normalized_request.get(
                 feconf.USER_FILTER_CRITERION_USERNAME)
diff --git a/core/controllers/base.py b/core/controllers/base.py
--- a/core/controllers/base.py
+++ b/core/controllers/base.py
@@ -241,13 +241,6 @@ def __init__(self, request, response):  # pylint: disable=super-init-not-called
             auth_services.destroy_auth_session(self.response)
             return
 
-        # TODO(#13447): Remove populating response values with `is_moderator`,
-        # `is_curriculum_admin` & `is_topic_manager`.
-        self.values['is_moderator'] = user_services.is_moderator(self.user_id)
-        self.values['is_curriculum_admin'] = (
-            user_services.is_curriculum_admin(self.user_id))
-        self.values['is_topic_manager'] = (
-            user_services.is_topic_manager(self.user_id))
         self.values['is_super_admin'] = self.current_user_is_super_admin
 
     def dispatch(self):


Test patch:
diff --git a/core/controllers/admin_test.py b/core/controllers/admin_test.py
--- a/core/controllers/admin_test.py
+++ b/core/controllers/admin_test.py
@@ -1065,7 +1065,9 @@ def test_view_and_update_role(self):
                 'filter_criterion': 'role',
                 'role': feconf.ROLE_ID_MODERATOR
             })
-        self.assertEqual(response_dict, {'user1': feconf.ROLE_ID_MODERATOR})
+        self.assertEqual(response_dict, {
+            'usernames': ['user1']
+        })
         self.logout()
 
     def test_invalid_username_in_filter_criterion_and_update_role(self):
diff --git a/core/controllers/library_test.py b/core/controllers/library_test.py
--- a/core/controllers/library_test.py
+++ b/core/controllers/library_test.py
@@ -73,9 +73,6 @@ def test_library_handler_demo_exploration(self):
         """Test the library data handler on demo explorations."""
         response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
         self.assertEqual({
-            'is_curriculum_admin': False,
-            'is_topic_manager': False,
-            'is_moderator': False,
             'is_super_admin': False,
             'activity_list': [],
             'search_cursor': None
@@ -132,8 +129,6 @@ def test_library_handler_for_created_explorations(self):
         self.login(self.CURRICULUM_ADMIN_EMAIL)
         response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
         self.assertDictContainsSubset({
-            'is_curriculum_admin': True,
-            'is_moderator': False,
             'is_super_admin': False,
             'activity_list': [],
             'user_email': self.CURRICULUM_ADMIN_EMAIL,
@@ -203,9 +198,6 @@ def test_library_handler_for_created_explorations(self):
     def test_library_handler_with_exceeding_query_limit_logs_error(self):
         response_dict = self.get_json(feconf.LIBRARY_SEARCH_DATA_URL)
         self.assertEqual({
-            'is_curriculum_admin': False,
-            'is_topic_manager': False,
-            'is_moderator': False,
             'is_super_admin': False,
             'activity_list': [],
             'search_cursor': None
@@ -445,8 +437,6 @@ def test_handler_for_recently_published_library_group_page(self):
             feconf.LIBRARY_GROUP_DATA_URL,
             params={'group_name': feconf.LIBRARY_GROUP_RECENTLY_PUBLISHED})
         self.assertDictContainsSubset({
-            'is_curriculum_admin': False,
-            'is_moderator': False,
             'is_super_admin': False,
             'activity_list': [],
             'preferred_language_codes': ['en'],
@@ -482,8 +472,6 @@ def test_handler_for_top_rated_library_group_page(self):
             feconf.LIBRARY_GROUP_DATA_URL,
             params={'group_name': feconf.LIBRARY_GROUP_TOP_RATED})
         self.assertDictContainsSubset({
-            'is_curriculum_admin': False,
-            'is_moderator': False,
             'is_super_admin': False,
             'activity_list': [],
             'preferred_language_codes': ['en'],