示例#1
0
    def _push_messages(messages):
        if len(messages) == 0:
            return

        messages_objs = []
        for i, message in enumerate(messages):
            user = message.get("user")
            obj = message.get("message")
            # Store message in the database only if mentions option are disabled.
            if (
                user.mentions_notifications is False
                and obj.message_type == MessageType.MENTION_NOTIFICATION.value
            ):
                messages_objs.append(obj)
                continue
            if (
                user.projects_notifications is False
                and obj.message_type == MessageType.PROJECT_ACTIVITY_NOTIFICATION.value
            ):
                continue
            if (
                user.projects_notifications is False
                and obj.message_type == MessageType.BROADCAST.value
            ):
                continue
            if (
                user.teams_notifications is False
                and obj.message_type == MessageType.TEAM_BROADCAST.value
            ):
                messages_objs.append(obj)
                continue
            if user.comments_notifications is False and obj.message_type in (
                MessageType.TASK_COMMENT_NOTIFICATION.value,
                MessageType.PROJECT_CHAT_NOTIFICATION.value,
            ):
                continue
            if user.tasks_notifications is False and obj.message_type in (
                MessageType.VALIDATION_NOTIFICATION.value,
                MessageType.INVALIDATION_NOTIFICATION.value,
            ):
                messages_objs.append(obj)
                continue
            messages_objs.append(obj)

            SMTPService.send_email_alert(
                user.email_address,
                user.username,
                message["message"].id,
                clean_html(message["message"].subject),
                message["message"].message,
            )

            if i + 1 % 10 == 0:
                time.sleep(0.5)

        # Flush messages to the database.
        if len(messages_objs) > 0:
            db.session.add_all(messages_objs)
            db.session.flush()
            db.session.commit()
示例#2
0
 def test_does_send_if_user_verified(self):
     self.assertTrue(
         SMTPService.send_email_alert("*****@*****.**",
                                      "Iain Hunter", True))
     self.assertFalse(
         SMTPService.send_email_alert("", "Iain Hunter", 1, "test",
                                      "testing"))
    def _push_messages(messages):
        if len(messages) == 0:
            return

        # Flush messages to get the id
        db.session.add_all([m["message"] for m in messages])
        db.session.flush()

        for i, message in enumerate(messages):
            user = message.get("user")
            SMTPService.send_email_alert(user.email_address, user.username,
                                         message["message"].id)

            if i + 1 % 10 == 0:
                time.sleep(0.5)

        db.session.commit()
示例#4
0
    def test_send_alert(self):

        if os.getenv("TM_SMTP_HOST") is None:
            return  # If SMTP not setup there's no value attempting the integration tests

        self.assertTrue(
            SMTPService.send_email_alert("*****@*****.**",
                                         "Iain Hunter", True))
    def send_message_after_validation(
        status: int, validated_by: int, mapped_by: int, task_id: int, project_id: int
    ):
        """ Sends mapper a notification after their task has been marked valid or invalid """
        if validated_by == mapped_by:
            return  # No need to send a message to yourself

        user = UserService.get_user_by_id(mapped_by)
        if user.validation_message is False:
            return  # No need to send validation message
        if user.projects_notifications is False:
            return

        text_template = get_template(
            "invalidation_message_en.txt"
            if status == TaskStatus.INVALIDATED
            else "validation_message_en.txt"
        )
        status_text = (
            "marked invalid" if status == TaskStatus.INVALIDATED else "validated"
        )
        task_link = MessageService.get_task_link(project_id, task_id)
        text_template = text_template.replace("[USERNAME]", user.username)
        text_template = text_template.replace("[TASK_LINK]", task_link)

        validation_message = Message()
        validation_message.message_type = (
            MessageType.INVALIDATION_NOTIFICATION.value
            if status == TaskStatus.INVALIDATED
            else MessageType.VALIDATION_NOTIFICATION.value
        )
        validation_message.project_id = project_id
        validation_message.task_id = task_id
        validation_message.from_user_id = validated_by
        validation_message.to_user_id = mapped_by
        validation_message.subject = f"Your mapping in Project {project_id} on {task_link} has just been {status_text}"
        validation_message.message = text_template
        validation_message.add_message()

        SMTPService.send_email_alert(
            user.email_address, user.username, validation_message.id
        )
示例#6
0
    def test_send_alert_message_limits(self):
        if self.skip_tests:
            return

        if os.getenv("TM_SMTP_HOST") is None:
            return  # If SMTP not setup there's no value attempting the integration tests

        for x in range(0, 50):
            self.assertTrue(
                SMTPService.send_email_alert("*****@*****.**", "Iain Hunter")
            )
示例#7
0
 def test_alert_not_sent_if_email_not_supplied(self):
     self.assertFalse(SMTPService.send_email_alert("", "Iain Hunter"))
示例#8
0
 def test_does_not_send_if_user_not_verified(self):
     self.assertFalse(
         SMTPService.send_email_alert("*****@*****.**",
                                      "Iain Hunter", False))