Beispiel #1
0
def _add_message_to_email_buffer(author_id, thread_id, message_id,
                                 message_length, old_status, new_status):
    """Sends the given message to the recipients of the given thread.

    Sends the given message to the recipients of the given thread. If
    status has changed, notify the recipients as well.

    Args:
        author_id: str. ID of author of message.
        thread_id: str. ID of thread that received new message.
        message_id: int. ID of new message.
        message_length: int. Length of the feedback message to be sent.
        old_status: str. one of STATUS_CHOICES. Value of old thread status.
        new_status: str. one of STATUS_CHOICES. Value of new thread status.
    """
    if constants.ENABLE_GENERALIZED_FEEDBACK_THREADS:
        thread = feedback_models.GeneralFeedbackThreadModel.get_by_id(
            thread_id)
        exploration_id = thread.entity_id
    else:
        thread = feedback_models.FeedbackThreadModel.get_by_id(thread_id)
        exploration_id = thread.exploration_id
    has_suggestion = thread.has_suggestion
    if constants.ENABLE_GENERALIZED_FEEDBACK_THREADS:
        feedback_message_reference = feedback_domain.FeedbackMessageReference(
            thread.entity_type, thread.entity_id, thread_id, message_id)
    else:

        feedback_message_reference = feedback_domain.FeedbackMessageReference(
            feconf.ENTITY_TYPE_EXPLORATION, thread.exploration_id, thread_id,
            message_id)
    batch_recipient_ids, other_recipient_ids = (_get_all_recipient_ids(
        exploration_id, thread_id, author_id))

    _ensure_each_recipient_has_reply_to_id(other_recipient_ids, thread_id)

    if old_status != new_status:
        # Send email for feedback thread status change.
        _send_feedback_thread_status_change_emails(other_recipient_ids,
                                                   feedback_message_reference,
                                                   old_status, new_status,
                                                   exploration_id,
                                                   has_suggestion)

    if message_length > 0:
        # Send feedback message email only if message text is non empty.
        # It can be empty in the case when only status is changed.
        _send_batch_emails(batch_recipient_ids, feedback_message_reference,
                           exploration_id, has_suggestion)
        _send_instant_emails(other_recipient_ids, feedback_message_reference,
                             exploration_id, has_suggestion)
Beispiel #2
0
def _add_message_to_email_buffer(author_id, exploration_id, thread_id,
                                 message_id, message_length, old_status,
                                 new_status):
    """sends email of feedback message to all thread participants.

    sends email for new feedback message and change in status of thread.

    Args:
        author_id: id of author of message.
        exploration_id: id of exploration that received new message.
        thread_id: id of thread that received new message.
        message_id: id of new message.
        message_length: length of the feedback message to be sent.
        old_status: value of old thread status.
        new_status: value of new thread status.
    """
    feedback_message_reference = feedback_domain.FeedbackMessageReference(
        exploration_id, thread_id, message_id)
    batch_recipient_ids, other_recipient_ids = (_get_all_recipient_ids(
        exploration_id, thread_id, author_id))

    if old_status != new_status:
        # Send email for feedback thread status change.
        _send_feedback_thread_status_change_emails(other_recipient_ids,
                                                   feedback_message_reference,
                                                   old_status, new_status)

    if message_length > 0:
        # Send feedback message email only if message text is non empty.
        # It can be empty in the case when only status is changed.
        _send_batch_emails(batch_recipient_ids, feedback_message_reference)
        _send_instant_emails(other_recipient_ids, feedback_message_reference)
Beispiel #3
0
def _add_message_to_email_buffer(author_id, exploration_id, thread_id,
                                 message_id, message_length, old_status,
                                 new_status):
    """Sends the given message to the recipients of the given thread.

    Sends the given message to the recipients of the given thread. If
    status has changed, notify the recipients as well.

    Args:
        author_id: str. ID of author of message.
        exploration_id: str. ID of exploration that received new message.
        thread_id: str. ID of thread that received new message.
        message_id: int. ID of new message.
        message_length: int. Length of the feedback message to be sent.
        old_status: str, one of STATUS_CHOICES. Value of old thread status.
        new_status: str, one of STATUS_CHOICES. Value of new thread status.
    """
    feedback_message_reference = feedback_domain.FeedbackMessageReference(
        exploration_id, thread_id, message_id)
    batch_recipient_ids, other_recipient_ids = (_get_all_recipient_ids(
        exploration_id, thread_id, author_id))

    if old_status != new_status:
        # Send email for feedback thread status change.
        _send_feedback_thread_status_change_emails(other_recipient_ids,
                                                   feedback_message_reference,
                                                   old_status, new_status)

    if message_length > 0:
        # Send feedback message email only if message text is non empty.
        # It can be empty in the case when only status is changed.
        _send_batch_emails(batch_recipient_ids, feedback_message_reference)
        _send_instant_emails(other_recipient_ids, feedback_message_reference)
def add_message_to_email_buffer(author_id, exploration_id, thread_id,
                                message_id):
    exploration_rights = rights_manager.get_exploration_rights(exploration_id)
    feedback_message_reference = feedback_domain.FeedbackMessageReference(
        exploration_id, thread_id, message_id)

    for owner_id in exploration_rights.owner_ids:
        owner_preferences = user_services.get_email_preferences(owner_id)
        if (owner_id != author_id
                and owner_preferences['can_receive_feedback_message_email']):
            transaction_services.run_in_transaction(
                _add_feedback_message_reference, owner_id,
                feedback_message_reference)
    def test_to_dict(self):
        expected_feedback_message_reference = {
            'exploration_id': self.exp_id,
            'thread_id': self.thread_id,
            'message_id': self.message_id
        }

        observed_feedback_message_reference = (
            feedback_domain.FeedbackMessageReference(
                self.exp_id, self.thread_id, self.message_id))

        self.assertDictEqual(observed_feedback_message_reference.to_dict(),
                             expected_feedback_message_reference)
Beispiel #6
0
    def test_to_dict(self) -> None:
        expected_feedback_message_reference: Dict[str, str] = {
            'entity_type': feconf.ENTITY_TYPE_EXPLORATION,
            'entity_id': self.exp_id,
            'thread_id': self.thread_id,
            'message_id': self.message_id
        }

        observed_feedback_message_reference = (
            feedback_domain.FeedbackMessageReference(
                feconf.ENTITY_TYPE_EXPLORATION, self.exp_id, self.thread_id,
                self.message_id))

        self.assertDictEqual(observed_feedback_message_reference.to_dict(),
                             expected_feedback_message_reference)
def get_feedback_message_references(user_id):
    """Returns a list of feedback message references corresponding to the given
    user id. If the user id is invalid or there are no messages for this user,
    returns an empty list."""

    model = feedback_models.UnsentFeedbackEmailModel.get(user_id, strict=False)

    if model is None:
        # Model may not exist if user has already attended to feedback.
        return []

    return [
        feedback_domain.FeedbackMessageReference(reference['exploration_id'],
                                                 reference['thread_id'],
                                                 reference['message_id'])
        for reference in model.feedback_message_references
    ]
Beispiel #8
0
    def test_create_new_instant_task(self):
        user_id = 'user'
        reference_dict = {
            'exploration_id': 'eid',
            'thread_id': 'tid',
            'message_id': 'mid'
        }
        reference = feedback_domain.FeedbackMessageReference(
            reference_dict['exploration_id'], reference_dict['thread_id'],
            reference_dict['message_id'])

        feedback_services.enqueue_feedback_message_instant_email_task(
            user_id, reference)
        self.assertEqual(self.count_jobs_in_taskqueue(), 1)

        tasks = self.get_pending_tasks()
        payload = json.loads(tasks[0].payload)
        self.assertEqual(
            tasks[0].url, feconf.TASK_URL_INSTANT_FEEDBACK_EMAILS)
        self.assertDictEqual(payload['reference_dict'], reference_dict)
Beispiel #9
0
def get_feedback_message_references(user_id):
    """Fetches all FeedbackMessageReference objects written by the given user。

    Args:
        user_id: str. If the user id is invalid or there is no message for this
            user, return an empty list.

    Returns:
        list(FeedbackMessageReference). The resulting FeedbackMessageReference
        domain objects.
    """
    model = feedback_models.UnsentFeedbackEmailModel.get(user_id, strict=False)
    feedback_message_references = (
        () if model is None else model.feedback_message_references)
    return [
        feedback_domain.FeedbackMessageReference(
            reference['entity_type'], reference['entity_id'],
            reference['thread_id'], reference['message_id'])
        for reference in feedback_message_references
    ]
Beispiel #10
0
def get_feedback_message_references(user_id):
    """Fetches all FeedbackMessageReference objects written by the given user。

    Args:
        user_id: str. If the user id is invalid or there is no message for this
            user, return an empty list.

    Returns:
        list of FeedbackMessageReference. The resulting FeedbackMessageReference
        domain objects.
    """
    model = feedback_models.UnsentFeedbackEmailModel.get(user_id, strict=False)

    if model is None:
        # Model may not exist if user has already attended to feedback.
        return []

    return [feedback_domain.FeedbackMessageReference(
        reference['exploration_id'], reference['thread_id'],
        reference['message_id']
    ) for reference in model.feedback_message_references]
Beispiel #11
0
def _add_message_to_email_buffer(
        author_id, thread_id, message_id, message_length, old_status,
        new_status):
    """Sends the given message to the recipients of the given thread. If status
    has changed, notify the recipients as well.

    Args:
        author_id: str. The id of the author of message.
        thread_id: str. The id of the thread that received new message.
        message_id: int. The id of the new message.
        message_length: int. Length of the feedback message to be sent.
        old_status: str. One of STATUS_CHOICES. Value of old thread status.
        new_status: str. One of STATUS_CHOICES. Value of new thread status.
    """
    thread = feedback_models.GeneralFeedbackThreadModel.get_by_id(thread_id)
    exploration_id = thread.entity_id
    has_suggestion = thread.has_suggestion
    feedback_message_reference = feedback_domain.FeedbackMessageReference(
        thread.entity_type, thread.entity_id, thread_id, message_id)
    batch_recipient_ids, other_recipient_ids = (
        _get_all_recipient_ids(exploration_id, thread_id, author_id))

    _ensure_each_recipient_has_reply_to_id(other_recipient_ids, thread_id)

    if old_status != new_status:
        # Send email for feedback thread status change.
        _send_feedback_thread_status_change_emails(
            other_recipient_ids, feedback_message_reference, old_status,
            new_status, exploration_id, has_suggestion)

    if message_length:
        # Send feedback message email only if message text is non empty (the
        # message text can be empty in the case when only status is changed).
        _send_batch_emails(
            batch_recipient_ids, feedback_message_reference, exploration_id,
            has_suggestion)
        _send_instant_emails(
            other_recipient_ids, feedback_message_reference, exploration_id,
            has_suggestion)