Example #1
0
 def get(self, exploration_id, thread_id):  # pylint: disable=unused-argument
     self.values.update({
         'messages': feedback_services.get_messages(
             exploration_id, thread_id)})
     self.values.update({
         'suggestion': feedback_services.get_suggestion(
             exploration_id, thread_id)})
     self.render_json(self.values)
Example #2
0
 def get(self, exploration_id, thread_id):  # pylint: disable=unused-argument
     suggestion = feedback_services.get_suggestion(exploration_id, thread_id)
     self.values.update({
         'messages': [m.to_dict() for m in feedback_services.get_messages(
             exploration_id, thread_id)],
         'suggestion': suggestion.to_dict() if suggestion else None
     })
     self.render_json(self.values)
Example #3
0
    def get(self, exploration_id, thread_id):
        """Handles GET requests."""
        messages = feedback_services.get_messages(exploration_id, thread_id)
        author_ids = [m.author_id for m in messages]
        authors_settings = user_services.get_users_settings(author_ids)

        message_ids = [m.message_id for m in messages]
        feedback_services.update_messages_read_by_the_user(
            self.user_id, exploration_id, thread_id, message_ids)

        message_summary_list = []
        suggestion = feedback_services.get_suggestion(exploration_id,
                                                      thread_id)

        if suggestion:
            exploration = exp_services.get_exploration_by_id(exploration_id)
            current_content_html = (
                exploration.states[suggestion.state_name].content.html)
            suggestion_summary = {
                'suggestion_html':
                suggestion.suggestion_html,
                'current_content_html':
                current_content_html,
                'description':
                suggestion.description,
                'author_username':
                authors_settings[0].username,
                'author_picture_data_url':
                (authors_settings[0].profile_picture_data_url)
            }
            message_summary_list.append(suggestion_summary)
            messages.pop(0)
            authors_settings.pop(0)

        for m, author_settings in zip(messages, authors_settings):

            if author_settings is None:
                author_username = None
                author_picture_data_url = None
            else:
                author_username = author_settings.username
                author_picture_data_url = (
                    author_settings.profile_picture_data_url)

            message_summary = {
                'message_id': m.message_id,
                'text': m.text,
                'updated_status': m.updated_status,
                'author_username': author_username,
                'author_picture_data_url': author_picture_data_url,
                'created_on': utils.get_time_in_millisecs(m.created_on)
            }
            message_summary_list.append(message_summary)

        self.render_json({'message_summary_list': message_summary_list})
Example #4
0
    def post(self):
        payload = json.loads(self.request.body)
        exploration_id = payload["exploration_id"]
        thread_id = payload["thread_id"]

        exploration_rights = rights_manager.get_exploration_rights(exploration_id)
        exploration = exp_services.get_exploration_by_id(exploration_id)
        suggestion = feedback_services.get_suggestion(exploration_id, thread_id)

        email_manager.send_suggestion_email(
            exploration.title, exploration.id, suggestion.author_id, exploration_rights.owner_ids
        )
Example #5
0
    def post(self):
        payload = json.loads(self.request.body)
        exploration_id = payload['exploration_id']
        thread_id = payload['thread_id']

        exploration_rights = (
            rights_manager.get_exploration_rights(exploration_id))
        exploration = exp_services.get_exploration_by_id(exploration_id)
        suggestion = feedback_services.get_suggestion(exploration_id, thread_id)

        email_manager.send_suggestion_email(
            exploration.title, exploration.id, suggestion.author_id,
            exploration_rights.owner_ids)
Example #6
0
 def get(self, thread_id):
     suggestion = feedback_services.get_suggestion(thread_id)
     messages = [
         m.to_dict() for m in feedback_services.get_messages(thread_id)
     ]
     message_ids = [message['message_id'] for message in messages]
     feedback_services.update_messages_read_by_the_user(
         self.user_id, thread_id, message_ids)
     self.values.update({
         'messages':
         messages,
         'suggestion':
         suggestion.to_dict() if suggestion else None
     })
     self.render_json(self.values)
Example #7
0
    def post(self, thread_id):
        suggestion = feedback_services.get_suggestion(thread_id)
        text = self.payload.get('text')
        updated_status = self.payload.get('updated_status')
        if not text and not updated_status:
            raise self.InvalidInputException(
                'Text for the message must be specified.')
        if suggestion and updated_status:
            raise self.InvalidInputException(
                'Suggestion thread status cannot be changed manually.')

        feedback_services.create_message(thread_id, self.user_id,
                                         updated_status,
                                         self.payload.get('updated_subject'),
                                         text)
        self.render_json(self.values)
Example #8
0
 def get(self, exploration_id, thread_id):  # pylint: disable=unused-argument
     suggestion = feedback_services.get_suggestion(exploration_id,
                                                   thread_id)
     messages = [
         m.to_dict()
         for m in feedback_services.get_messages(exploration_id, thread_id)
     ]
     message_ids = [message['message_id'] for message in messages]
     feedback_services.update_messages_read_by_the_user(
         self.user_id, exploration_id, thread_id, message_ids)
     self.values.update({
         'messages':
         messages,
         'suggestion':
         suggestion.to_dict() if suggestion else None
     })
     self.render_json(self.values)
Example #9
0
 def test_create_and_get_suggestion(self):
     with self.swap(feedback_models.FeedbackThreadModel,
                    'generate_new_thread_id', self._generate_thread_id):
         feedback_services.create_suggestion(
             self.EXP_ID3, self.user_id, 3, 'state_name',
             'description', {'old_content': {}})
     suggestion = feedback_services.get_suggestion(
         self.EXP_ID3, self.THREAD_ID1)
     thread = feedback_models.FeedbackThreadModel.get(
         feedback_models.FeedbackThreadModel.generate_full_thread_id(
             self.EXP_ID3, self.THREAD_ID1))
     self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN)
     self.assertEqual(suggestion['exploration_id'], self.EXP_ID3)
     self.assertEqual(suggestion['author_name'], 'user123')
     self.assertEqual(suggestion['exploration_version'], 3)
     self.assertEqual(suggestion['state_name'], 'state_name')
     self.assertEqual(suggestion['description'], 'description')
     self.assertEqual(suggestion['state_content'], {'old_content': {}})
Example #10
0
    def post(self, exploration_id, thread_id):  # pylint: disable=unused-argument
        suggestion = feedback_services.get_suggestion(exploration_id, thread_id)
        text = self.payload.get('text')
        updated_status = self.payload.get('updated_status')
        if not text and not updated_status:
            raise self.InvalidInputException(
                'Text for the message must be specified.')
        if suggestion and updated_status:
            raise self.InvalidInputException(
                'Suggestion thread status cannot be changed manually.')

        feedback_services.create_message(
            exploration_id,
            thread_id,
            self.user_id,
            updated_status,
            self.payload.get('updated_subject'),
            text)
        self.render_json(self.values)
Example #11
0
    def get(self, thread_id):
        if constants.USE_NEW_SUGGESTION_FRAMEWORK:
            suggestion = suggestion_services.get_suggestion_by_id(thread_id)
        else:
            suggestion = feedback_services.get_suggestion(thread_id)

        messages = [
            m.to_dict() for m in feedback_services.get_messages(thread_id)
        ]
        message_ids = [message['message_id'] for message in messages]
        feedback_services.update_messages_read_by_the_user(
            self.user_id, thread_id, message_ids)
        self.values.update({
            'messages':
            messages,
            'suggestion':
            suggestion.to_dict() if suggestion else None
        })
        self.render_json(self.values)
Example #12
0
 def test_create_and_get_suggestion(self):
     with self.swap(feedback_models.FeedbackThreadModel,
                    'generate_new_thread_id', self._generate_thread_id):
         feedback_services.create_suggestion(
             self.EXP_ID2, self.user_id, 3, 'state_name',
             'description', {'old_content': {}})
     suggestion = feedback_services.get_suggestion(
         self.EXP_ID2, self.THREAD_ID1)
     thread = feedback_models.FeedbackThreadModel.get(
         feedback_models.FeedbackThreadModel.generate_full_thread_id(
             self.EXP_ID2, self.THREAD_ID1))
     expected_suggestion_dict = {
         'exploration_id': self.EXP_ID2,
         'author_name': 'user123',
         'exploration_version': 3,
         'state_name': 'state_name',
         'description': 'description',
         'state_content': {'old_content': {}}
     }
     self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN)
     self.assertDictEqual(expected_suggestion_dict, suggestion.to_dict())
Example #13
0
 def test_create_and_get_suggestion(self):
     with self.swap(feedback_models.FeedbackThreadModel,
                    'generate_new_thread_id', self._generate_thread_id):
         feedback_services.create_suggestion(
             self.EXP_ID2, self.user_id, 3, 'state_name',
             'description', {'old_content': {}})
     suggestion = feedback_services.get_suggestion(
         self.EXP_ID2, self.THREAD_ID1)
     thread = feedback_models.FeedbackThreadModel.get(
         feedback_models.FeedbackThreadModel.generate_full_thread_id(
             self.EXP_ID2, self.THREAD_ID1))
     expected_suggestion_dict = {
         'exploration_id': self.EXP_ID2,
         'author_name': 'user123',
         'exploration_version': 3,
         'state_name': 'state_name',
         'description': 'description',
         'state_content': {'old_content': {}}
     }
     self.assertEqual(thread.status, feedback_models.STATUS_CHOICES_OPEN)
     self.assertDictEqual(expected_suggestion_dict, suggestion.to_dict())