Beispiel #1
0
    def post(self):
        payload = json.loads(self.request.body)
        user_id = payload['user_id']
        references = feedback_services.get_feedback_message_references(user_id)
        if not references:
            # Model may not exist if user has already attended to the feedback.
            return

        feedback_services.update_feedback_email_retries_transactional(user_id)

        messages = {}
        for reference in references:
            message = feedback_services.get_message(reference.thread_id,
                                                    reference.message_id)

            exploration = exp_fetchers.get_exploration_by_id(
                reference.entity_id)

            message_text = message.text
            if len(message_text) > 200:
                message_text = message_text[:200] + '...'

            if exploration.id in messages:
                messages[exploration.id]['messages'].append(message_text)
            else:
                messages[exploration.id] = {
                    'title': exploration.title,
                    'messages': [message_text]
                }

        email_manager.send_feedback_message_email(user_id, messages)
        feedback_services.pop_feedback_message_references_transactional(
            user_id, len(references))
        self.render_json({})
Beispiel #2
0
    def test_email_sent_when_feedback_in_thread(self):
        # Create feedback thread.
        with self.can_send_feedback_email_ctx, self.can_send_emails_ctx:
            feedback_services.create_thread(feconf.ENTITY_TYPE_EXPLORATION,
                                            self.exploration.id,
                                            self.user_id_a, 'a subject',
                                            'some text')
            threadlist = feedback_services.get_all_threads(
                feconf.ENTITY_TYPE_EXPLORATION, self.exploration.id, False)
            thread_id = threadlist[0].id

            # Create another message.
            feedback_services.create_message(thread_id, self.user_id_b, None,
                                             None, 'user b message')

            # Check that there are two messages in thread.
            messages = feedback_services.get_messages(thread_id)
            self.assertEqual(len(messages), 2)

            # Check that there are no feedback emails sent to Editor.
            messages = self._get_sent_email_messages(self.EDITOR_EMAIL)
            self.assertEqual(len(messages), 0)

            # Send task and subsequent email to Editor.
            self.process_and_flush_pending_tasks()
            messages = self._get_sent_email_messages(self.EDITOR_EMAIL)
            expected_message = (
                'Hi editor,\n\nYou\'ve received 2 new messages on your'
                ' Oppia explorations:\n- Title:\n- some text\n- user b message'
                '\nYou can view and reply to your messages from your dashboard.'
                '\n\nThanks, and happy teaching!\n\nBest wishes,\nThe Oppia'
                ' Team\n\nYou can change your email preferences via the '
                'Preferences page.')

            # Assert that the message is correct.
            self.assertEqual(len(messages), 1)
            self.assertEqual(messages[0].body, expected_message)

            # Create another message that is len = 201.
            user_b_message = 'B' * 201
            feedback_services.create_message(thread_id, self.user_id_b, None,
                                             None, user_b_message)

            # Check that there are three messages in thread.
            messages = feedback_services.get_messages(thread_id)
            self.assertEqual(len(messages), 3)

            # Send task and subsequent email to Editor.
            self.process_and_flush_pending_tasks()
            messages = self._get_sent_email_messages(self.EDITOR_EMAIL)

            # What is expected in the email body.
            expected_message = (
                'Hi editor,\n\nYou\'ve received a new message on your Oppia'
                ' explorations:\n- Title:\n- ' + 'B' * 200 + '...' +
                '\nYou can'
                ' view and reply to your messages from your dashboard.\n\nThank'
                's, and happy teaching!\n\nBest wishes,\nThe Oppia Team\n\nYou'
                ' can change your email preferences via the Preferences page.')

            # Check that greater than 200 word message is sent
            # and has correct message.

            self.assertEqual(len(messages), 2)
            self.assertEqual(messages[1].body, expected_message)

            # Create another message.
            feedback_services.create_message(thread_id, self.user_id_b, None,
                                             None, 'user b another message')

            # Pops feedback message references.
            feedback_services.pop_feedback_message_references_transactional(
                self.editor_id, 0)

            # Send task and subsequent email to Editor.
            self.process_and_flush_pending_tasks()
            messages = self._get_sent_email_messages(self.EDITOR_EMAIL)

            # Check that there are three messages.
            self.assertEqual(len(messages), 3)