Exemplo n.º 1
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('explorationId')
                logging.info(
                    '[ADMIN] %s reloaded exploration %s' %
                    (self.user_id, exploration_id))
                exp_services.delete_demo(unicode(exploration_id))
                exp_services.load_demo(unicode(exploration_id))
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(
                    self.user_id, config_property_id)
            elif self.payload.get('action') == 'refresh_computed_property':
                computed_property_name = self.payload.get(
                    'computed_property_name')
                config_domain.Registry.get_config_property(
                    computed_property_name).refresh_default_value()

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise
Exemplo n.º 2
0
    def test_get_skill_opportunity_data_pagination_multiple_fetches(self):
        # Unassign topic 0 from the classroom.
        config_services.revert_property(self.admin_id, 'classroom_pages_data')

        # Create a new topic.
        topic_id = '1'
        topic_name = 'topic1'
        topic = topic_domain.Topic.create_default_topic(
            topic_id, topic_name, 'url-fragment', 'description')
        skill_id_2 = 'skill_id_2'
        skill_id_3 = 'skill_id_3'
        skill_id_4 = 'skill_id_4'
        skill_id_5 = 'skill_id_5'
        self._publish_valid_topic(
            topic, [skill_id_2, skill_id_3, skill_id_4, skill_id_5])

        # Add new topic to a classroom.
        config_services.set_property(self.admin_id, 'classroom_pages_data',
                                     [{
                                         'name': 'math',
                                         'url_fragment': 'math-one',
                                         'topic_ids': [topic_id],
                                         'course_details': '',
                                         'topic_list_intro': ''
                                     }])

        # Opportunities with IDs skill_id_0, skill_id_1, skill_id_2 will be
        # fetched first. Since skill_id_0, skill_id_1 are not linked to a
        # classroom, another fetch will be made to retrieve skill_id_3,
        # skill_id_4, skill_id_5 to fulfill the page size.
        with self.swap(constants, 'OPPORTUNITIES_PAGE_SIZE', 3):
            response = self.get_json('%s/skill' %
                                     feconf.CONTRIBUTOR_OPPORTUNITIES_DATA_URL,
                                     params={})
            self.assertEqual(len(response['opportunities']), 4)
            self.assertEqual(response['opportunities'],
                             [{
                                 'id': skill_id_2,
                                 'skill_description': 'skill_description',
                                 'question_count': 0,
                                 'topic_name': topic_name
                             }, {
                                 'id': skill_id_3,
                                 'skill_description': 'skill_description',
                                 'question_count': 0,
                                 'topic_name': topic_name
                             }, {
                                 'id': skill_id_4,
                                 'skill_description': 'skill_description',
                                 'question_count': 0,
                                 'topic_name': topic_name
                             }, {
                                 'id': skill_id_5,
                                 'skill_description': 'skill_description',
                                 'question_count': 0,
                                 'topic_name': topic_name
                             }])
            self.assertFalse(response['more'])
            self.assertTrue(
                isinstance(response['next_cursor'], python_utils.BASESTRING))
Exemplo n.º 3
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('explorationId')
                logging.info('[ADMIN] %s reloaded exploration %s' %
                             (self.user_id, exploration_id))
                exp_services.delete_demo(unicode(exploration_id))
                exp_services.load_demo(unicode(exploration_id))
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(self.user_id,
                                                config_property_id)
            elif self.payload.get('action') == 'refresh_computed_property':
                computed_property_name = self.payload.get(
                    'computed_property_name')
                config_domain.Registry.get_config_property(
                    computed_property_name).refresh_default_value()

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise
Exemplo n.º 4
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('exploration_id')
                logging.info(
                    '[ADMIN] %s reloaded exploration %s' %
                    (self.user_id, exploration_id))
                exp_services.delete_demo(unicode(exploration_id))
                exp_services.load_demo(unicode(exploration_id))
            elif self.payload.get('action') == 'clear_search_index':
                exp_services.clear_search_index()
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(
                    self.user_id, config_property_id)
            elif self.payload.get('action') == 'refresh_computed_property':
                computed_property_name = self.payload.get(
                    'computed_property_name')
                config_domain.Registry.get_config_property(
                    computed_property_name).refresh_default_value()
            elif self.payload.get('action') == 'start_new_job':
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == self.payload.get('job_type'):
                        klass.enqueue(klass.create_new())
                        break
            elif self.payload.get('action') == 'cancel_job':
                job_id = self.payload.get('job_id')
                job_type = self.payload.get('job_type')
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == job_type:
                        klass.cancel(job_id, self.user_id)
                        break
            elif self.payload.get('action') == 'start_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.start_computation()
                        break
            elif self.payload.get('action') == 'stop_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.stop_computation(self.user_id)
                        break

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise
Exemplo n.º 5
0
 def test_can_not_revert_config_property_with_invalid_config_property_name(
         self):
     with self.assertRaisesRegexp(
             Exception,
             'No config property with name new_config_property_name found.'
     ):
         config_services.revert_property('admin',
                                         'new_config_property_name')
Exemplo n.º 6
0
 def test_can_not_revert_config_property_with_invalid_config_property_name(
         self) -> None:
     with self.assertRaisesRegex(  # type: ignore[no-untyped-call]
             Exception,
             'No config property with name new_config_property_name found.'
     ):
         config_services.revert_property('admin',
                                         'new_config_property_name')
Exemplo n.º 7
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('exploration_id')
                logging.info('[ADMIN] %s reloaded exploration %s' %
                             (self.user_id, exploration_id))
                exp_services.delete_demo(unicode(exploration_id))
                exp_services.load_demo(unicode(exploration_id))
            elif self.payload.get('action') == 'clear_search_index':
                exp_services.clear_search_index()
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(self.user_id,
                                                config_property_id)
            elif self.payload.get('action') == 'refresh_computed_property':
                computed_property_name = self.payload.get(
                    'computed_property_name')
                config_domain.Registry.get_config_property(
                    computed_property_name).refresh_default_value()
            elif self.payload.get('action') == 'start_new_job':
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == self.payload.get('job_type'):
                        klass.enqueue(klass.create_new())
                        break
            elif self.payload.get('action') == 'cancel_job':
                job_id = self.payload.get('job_id')
                job_type = self.payload.get('job_type')
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == job_type:
                        klass.cancel(job_id, self.user_id)
                        break
            elif self.payload.get('action') == 'start_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.start_computation()
                        break
            elif self.payload.get('action') == 'stop_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.stop_computation(self.user_id)
                        break

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise
Exemplo n.º 8
0
    def test_get_skill_opportunity_data_does_not_return_non_classroom_topics(
            self):
        config_services.revert_property(self.admin_id, 'classroom_pages_data')

        response = self.get_json('%s/skill' %
                                 feconf.CONTRIBUTOR_OPPORTUNITIES_DATA_URL,
                                 params={})

        self.assertEqual(response['opportunities'], [])
        self.assertFalse(response['more'])
        self.assertIsInstance(response['next_cursor'], str)
Exemplo n.º 9
0
 def post(self) -> None:
     """Handles POST requests."""
     result = {}
     if self.normalized_payload.get('action') == 'save_config_properties':
         new_config_property_values = self.normalized_payload.get(
             'new_config_property_values')
         for (name, value) in new_config_property_values.items():
             config_services.set_property(self.user_id, name, value)
         logging.info('[BLOG ADMIN] %s saved config property values: %s' %
                      (self.user_id, new_config_property_values))
     elif self.normalized_payload.get('action') == 'revert_config_property':
         config_property_id = (
             self.normalized_payload.get('config_property_id'))
         config_services.revert_property(self.user_id, config_property_id)
         logging.info('[BLOG ADMIN] %s reverted config property: %s' %
                      (self.user_id, config_property_id))
     self.render_json(result)
Exemplo n.º 10
0
 def test_can_revert_config_property(self):
     self.assertFalse(config_domain.PROMO_BAR_ENABLED.value)
     config_services.set_property('admin', 'promo_bar_enabled', True)
     self.assertTrue(config_domain.PROMO_BAR_ENABLED.value)
     config_services.revert_property('admin', 'promo_bar_enabled')
     self.assertFalse(config_domain.PROMO_BAR_ENABLED.value)
Exemplo n.º 11
0
 def post(self):
     """Handles POST requests."""
     try:
         if self.payload.get('action') == 'reload_exploration':
             exploration_id = self.payload.get('exploration_id')
             self._reload_exploration(exploration_id)
         elif self.payload.get('action') == 'reload_collection':
             collection_id = self.payload.get('collection_id')
             self._reload_collection(collection_id)
         elif self.payload.get('action') == 'generate_dummy_explorations':
             num_dummy_exps_to_generate = self.payload.get(
                 'num_dummy_exps_to_generate')
             num_dummy_exps_to_publish = self.payload.get(
                 'num_dummy_exps_to_publish')
             if not isinstance(num_dummy_exps_to_generate, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_generate)
             elif not isinstance(num_dummy_exps_to_publish, int):
                 raise self.InvalidInputException('%s is not a number' %
                                                  num_dummy_exps_to_publish)
             elif num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                 raise self.InvalidInputException(
                     'Generate count cannot be less than publish count')
             else:
                 self._generate_dummy_explorations(
                     num_dummy_exps_to_generate, num_dummy_exps_to_publish)
         elif self.payload.get('action') == 'clear_search_index':
             exp_services.clear_search_index()
         elif self.payload.get('action') == 'save_config_properties':
             new_config_property_values = self.payload.get(
                 'new_config_property_values')
             logging.info('[ADMIN] %s saved config property values: %s' %
                          (self.user_id, new_config_property_values))
             for (name, value) in new_config_property_values.iteritems():
                 config_services.set_property(self.user_id, name, value)
         elif self.payload.get('action') == 'revert_config_property':
             config_property_id = self.payload.get('config_property_id')
             logging.info('[ADMIN] %s reverted config property: %s' %
                          (self.user_id, config_property_id))
             config_services.revert_property(self.user_id,
                                             config_property_id)
         elif self.payload.get('action') == 'start_new_job':
             for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                 if klass.__name__ == self.payload.get('job_type'):
                     klass.enqueue(klass.create_new())
                     break
         elif self.payload.get('action') == 'cancel_job':
             job_id = self.payload.get('job_id')
             job_type = self.payload.get('job_type')
             for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                 if klass.__name__ == job_type:
                     klass.cancel(job_id, self.user_id)
                     break
         elif self.payload.get('action') == 'start_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.start_computation()
                     break
         elif self.payload.get('action') == 'stop_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.stop_computation(self.user_id)
                     break
         elif self.payload.get('action') == 'upload_topic_similarities':
             data = self.payload.get('data')
             recommendations_services.update_topic_similarities(data)
         self.render_json({})
     except Exception as e:
         self.render_json({'error': unicode(e)})
         raise
Exemplo n.º 12
0
 def post(self):
     """Handles POST requests."""
     try:
         result = {}
         if self.payload.get('action') == 'reload_exploration':
             exploration_id = self.payload.get('exploration_id')
             self._reload_exploration(exploration_id)
         elif self.payload.get('action') == 'reload_collection':
             collection_id = self.payload.get('collection_id')
             self._reload_collection(collection_id)
         elif self.payload.get('action') == 'generate_dummy_explorations':
             num_dummy_exps_to_generate = self.payload.get(
                 'num_dummy_exps_to_generate')
             num_dummy_exps_to_publish = self.payload.get(
                 'num_dummy_exps_to_publish')
             if not isinstance(num_dummy_exps_to_generate, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_generate)
             elif not isinstance(num_dummy_exps_to_publish, int):
                 raise self.InvalidInputException('%s is not a number' %
                                                  num_dummy_exps_to_publish)
             elif num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                 raise self.InvalidInputException(
                     'Generate count cannot be less than publish count')
             else:
                 self._generate_dummy_explorations(
                     num_dummy_exps_to_generate, num_dummy_exps_to_publish)
         elif self.payload.get('action') == 'clear_search_index':
             search_services.clear_collection_search_index()
             search_services.clear_exploration_search_index()
         elif (self.payload.get('action') ==
               'generate_dummy_new_structures_data'):
             self._load_dummy_new_structures_data()
         elif self.payload.get('action') == (
                 'flush_migration_bot_contribution_data'):
             user_services.flush_migration_bot_contributions_model()
         elif self.payload.get('action') == 'save_config_properties':
             new_config_property_values = self.payload.get(
                 'new_config_property_values')
             logging.info('[ADMIN] %s saved config property values: %s' %
                          (self.user_id, new_config_property_values))
             for (name, value) in new_config_property_values.items():
                 config_services.set_property(self.user_id, name, value)
         elif self.payload.get('action') == 'revert_config_property':
             config_property_id = self.payload.get('config_property_id')
             logging.info('[ADMIN] %s reverted config property: %s' %
                          (self.user_id, config_property_id))
             config_services.revert_property(self.user_id,
                                             config_property_id)
         elif self.payload.get('action') == 'start_new_job':
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == self.payload.get('job_type'):
                     klass.enqueue(klass.create_new())
                     break
         elif self.payload.get('action') == 'cancel_job':
             job_id = self.payload.get('job_id')
             job_type = self.payload.get('job_type')
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == job_type:
                     klass.cancel(job_id, self.user_id)
                     break
         elif self.payload.get('action') == 'start_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.start_computation()
                     break
         elif self.payload.get('action') == 'stop_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.stop_computation(self.user_id)
                     break
         elif self.payload.get('action') == 'upload_topic_similarities':
             data = self.payload.get('data')
             recommendations_services.update_topic_similarities(data)
         elif self.payload.get('action') == (
                 'regenerate_topic_related_opportunities'):
             topic_id = self.payload.get('topic_id')
             opportunities_count = (
                 opportunity_services.
                 regenerate_opportunities_related_to_topic(
                     topic_id, delete_existing_opportunities=True))
             result = {'opportunities_count': opportunities_count}
         self.render_json(result)
     except Exception as e:
         self.render_json({'error': python_utils.UNICODE(e)})
         raise
Exemplo n.º 13
0
    def post(self):
        """Handles POST requests."""
        action = self.normalized_payload.get('action')
        try:
            result = {}
            if action == 'reload_exploration':
                exploration_id = self.normalized_payload.get('exploration_id')
                self._reload_exploration(exploration_id)
            elif action == 'reload_collection':
                collection_id = self.normalized_payload.get('collection_id')
                self._reload_collection(collection_id)
            elif action == 'generate_dummy_explorations':
                num_dummy_exps_to_generate = self.normalized_payload.get(
                    'num_dummy_exps_to_generate')
                num_dummy_exps_to_publish = self.normalized_payload.get(
                    'num_dummy_exps_to_publish')

                if num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                    raise self.InvalidInputException(
                        'Generate count cannot be less than publish count')
                else:
                    self._generate_dummy_explorations(
                        num_dummy_exps_to_generate, num_dummy_exps_to_publish)
            elif action == 'clear_search_index':
                search_services.clear_collection_search_index()
                search_services.clear_exploration_search_index()
            elif action == 'generate_dummy_new_structures_data':
                self._load_dummy_new_structures_data()
            elif action == 'generate_dummy_new_skill_data':
                self._generate_dummy_skill_and_questions()
            elif action == 'save_config_properties':
                new_config_property_values = self.normalized_payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.items():
                    config_services.set_property(self.user_id, name, value)
            elif action == 'revert_config_property':
                config_property_id = self.normalized_payload.get(
                    'config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(self.user_id,
                                                config_property_id)
            elif action == 'upload_topic_similarities':
                data = self.normalized_payload.get('data')
                recommendations_services.update_topic_similarities(data)
            elif action == 'regenerate_topic_related_opportunities':
                topic_id = self.normalized_payload.get('topic_id')
                opportunities_count = (
                    opportunity_services.
                    regenerate_opportunities_related_to_topic(
                        topic_id, delete_existing_opportunities=True))
                result = {'opportunities_count': opportunities_count}
            elif action == 'update_feature_flag_rules':
                feature_name = self.normalized_payload.get('feature_name')
                new_rule_dicts = self.normalized_payload.get('new_rules')
                commit_message = self.normalized_payload.get('commit_message')

                try:
                    feature_services.update_feature_flag_rules(
                        feature_name, self.user_id, commit_message,
                        new_rule_dicts)
                except (utils.ValidationError,
                        feature_services.FeatureFlagNotFoundException) as e:
                    raise self.InvalidInputException(e)
                logging.info('[ADMIN] %s updated feature %s with new rules: '
                             '%s.' %
                             (self.user_id, feature_name, new_rule_dicts))
            self.render_json(result)
        except Exception as e:
            logging.exception('[ADMIN] %s', e)
            self.render_json({'error': python_utils.UNICODE(e)})
            python_utils.reraise_exception()
Exemplo n.º 14
0
 def post(self):
     """Handles POST requests."""
     try:
         result = {}
         if self.payload.get('action') == 'reload_exploration':
             exploration_id = self.payload.get('exploration_id')
             self._reload_exploration(exploration_id)
         elif self.payload.get('action') == 'reload_collection':
             collection_id = self.payload.get('collection_id')
             self._reload_collection(collection_id)
         elif self.payload.get('action') == 'generate_dummy_explorations':
             num_dummy_exps_to_generate = self.payload.get(
                 'num_dummy_exps_to_generate')
             num_dummy_exps_to_publish = self.payload.get(
                 'num_dummy_exps_to_publish')
             if not isinstance(num_dummy_exps_to_generate, int):
                 raise self.InvalidInputException(
                     '%s is not a number' % num_dummy_exps_to_generate)
             elif not isinstance(num_dummy_exps_to_publish, int):
                 raise self.InvalidInputException('%s is not a number' %
                                                  num_dummy_exps_to_publish)
             elif num_dummy_exps_to_generate < num_dummy_exps_to_publish:
                 raise self.InvalidInputException(
                     'Generate count cannot be less than publish count')
             else:
                 self._generate_dummy_explorations(
                     num_dummy_exps_to_generate, num_dummy_exps_to_publish)
         elif self.payload.get('action') == 'clear_search_index':
             search_services.clear_collection_search_index()
             search_services.clear_exploration_search_index()
         elif (self.payload.get('action') ==
               'generate_dummy_new_structures_data'):
             self._load_dummy_new_structures_data()
         elif (self.payload.get('action') == 'generate_dummy_new_skill_data'
               ):
             self._generate_dummy_skill_and_questions()
         elif self.payload.get('action') == 'save_config_properties':
             new_config_property_values = self.payload.get(
                 'new_config_property_values')
             logging.info('[ADMIN] %s saved config property values: %s' %
                          (self.user_id, new_config_property_values))
             for (name, value) in new_config_property_values.items():
                 config_services.set_property(self.user_id, name, value)
         elif self.payload.get('action') == 'revert_config_property':
             config_property_id = self.payload.get('config_property_id')
             logging.info('[ADMIN] %s reverted config property: %s' %
                          (self.user_id, config_property_id))
             config_services.revert_property(self.user_id,
                                             config_property_id)
         elif self.payload.get('action') == 'start_new_job':
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == self.payload.get('job_type'):
                     klass.enqueue(klass.create_new())
                     break
         elif self.payload.get('action') == 'cancel_job':
             job_id = self.payload.get('job_id')
             job_type = self.payload.get('job_type')
             for klass in (jobs_registry.ONE_OFF_JOB_MANAGERS +
                           (jobs_registry.AUDIT_JOB_MANAGERS)):
                 if klass.__name__ == job_type:
                     klass.cancel(job_id, self.user_id)
                     break
         elif self.payload.get('action') == 'start_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.start_computation()
                     break
         elif self.payload.get('action') == 'stop_computation':
             computation_type = self.payload.get('computation_type')
             for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                 if klass.__name__ == computation_type:
                     klass.stop_computation(self.user_id)
                     break
         elif self.payload.get('action') == 'upload_topic_similarities':
             data = self.payload.get('data')
             recommendations_services.update_topic_similarities(data)
         elif self.payload.get('action') == (
                 'regenerate_topic_related_opportunities'):
             topic_id = self.payload.get('topic_id')
             opportunities_count = (
                 opportunity_services.
                 regenerate_opportunities_related_to_topic(
                     topic_id, delete_existing_opportunities=True))
             result = {'opportunities_count': opportunities_count}
         elif self.payload.get('action') == 'update_feature_flag_rules':
             feature_name = self.payload.get('feature_name')
             new_rule_dicts = self.payload.get('new_rules')
             commit_message = self.payload.get('commit_message')
             if not isinstance(feature_name, python_utils.BASESTRING):
                 raise self.InvalidInputException(
                     'feature_name should be string, received \'%s\'.' %
                     (feature_name))
             elif not isinstance(commit_message, python_utils.BASESTRING):
                 raise self.InvalidInputException(
                     'commit_message should be string, received \'%s\'.' %
                     (commit_message))
             elif (not isinstance(new_rule_dicts, list) or not all([
                     isinstance(rule_dict, dict)
                     for rule_dict in new_rule_dicts
             ])):
                 raise self.InvalidInputException(
                     'new_rules should be a list of dicts, received'
                     ' \'%s\'.' % new_rule_dicts)
             try:
                 feature_services.update_feature_flag_rules(
                     feature_name, self.user_id, commit_message,
                     new_rule_dicts)
             except (utils.ValidationError,
                     feature_services.FeatureFlagNotFoundException) as e:
                 raise self.InvalidInputException(e)
             logging.info('[ADMIN] %s updated feature %s with new rules: '
                          '%s.' %
                          (self.user_id, feature_name, new_rule_dicts))
         self.render_json(result)
     except Exception as e:
         logging.error('[ADMIN] %s', e)
         self.render_json({'error': python_utils.UNICODE(e)})
         python_utils.reraise_exception()
Exemplo n.º 15
0
    def post(self):
        """Handles POST requests."""
        try:
            if self.payload.get('action') == 'reload_exploration':
                exploration_id = self.payload.get('exploration_id')
                logging.info(
                    '[ADMIN] %s reloaded exploration %s' %
                    (self.user_id, exploration_id))
                exp_services.load_demo(unicode(exploration_id))
                rights_manager.release_ownership_of_exploration(
                    feconf.SYSTEM_COMMITTER_ID, unicode(exploration_id))
            elif self.payload.get('action') == 'reload_collection':
                collection_id = self.payload.get('collection_id')
                logging.info(
                    '[ADMIN] %s reloaded collection %s' %
                    (self.user_id, collection_id))
                collection_services.load_demo(unicode(collection_id))
                rights_manager.release_ownership_of_collection(
                    feconf.SYSTEM_COMMITTER_ID, unicode(collection_id))
            elif self.payload.get('action') == 'clear_search_index':
                exp_services.clear_search_index()
            elif self.payload.get('action') == 'save_config_properties':
                new_config_property_values = self.payload.get(
                    'new_config_property_values')
                logging.info('[ADMIN] %s saved config property values: %s' %
                             (self.user_id, new_config_property_values))
                for (name, value) in new_config_property_values.iteritems():
                    config_services.set_property(self.user_id, name, value)
            elif self.payload.get('action') == 'revert_config_property':
                config_property_id = self.payload.get('config_property_id')
                logging.info('[ADMIN] %s reverted config property: %s' %
                             (self.user_id, config_property_id))
                config_services.revert_property(
                    self.user_id, config_property_id)
            elif self.payload.get('action') == 'start_new_job':
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == self.payload.get('job_type'):
                        klass.enqueue(klass.create_new())
                        break
            elif self.payload.get('action') == 'cancel_job':
                job_id = self.payload.get('job_id')
                job_type = self.payload.get('job_type')
                for klass in jobs_registry.ONE_OFF_JOB_MANAGERS:
                    if klass.__name__ == job_type:
                        klass.cancel(job_id, self.user_id)
                        break
            elif self.payload.get('action') == 'start_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.start_computation()
                        break
            elif self.payload.get('action') == 'stop_computation':
                computation_type = self.payload.get('computation_type')
                for klass in jobs_registry.ALL_CONTINUOUS_COMPUTATION_MANAGERS:
                    if klass.__name__ == computation_type:
                        klass.stop_computation(self.user_id)
                        break
            elif self.payload.get('action') == 'upload_topic_similarities':
                data = self.payload.get('data')
                recommendations_services.update_topic_similarities(data)

            self.render_json({})
        except Exception as e:
            self.render_json({'error': unicode(e)})
            raise