コード例 #1
0
 def test_get_text_for_add_text_message(self):
     for language, is_html, message in list(itertools.product(['en', 'de'],
                                                              [True, False],
                                                              [_.statementAddedMessageContent,
                                                               _.argumentAddedMessageContent])):
         text = tg.get_text_for_message(self.name, language, self.url, message, is_html)
         if is_html:
             self.assertNotIn("\n", text)
             self.assertIn("<br>", text)
         else:
             self.assertNotIn("<br>", text)
             self.assertIn("\n", text)
コード例 #2
0
def send_add_argument_notification(url, attacked_argument_uid, user, mailer):
    """
    Sends an notification because an argument was added

    :param url: String
    :param attacked_argument_uid: Argument.uid
    :param user: User
    :param mailer: Instance of pyramid mailer
    :return:
    """
    # getting current argument, arguments author, current user and some settings
    db_argument = DBDiscussionSession.query(Argument).get(
        attacked_argument_uid)
    db_author = DBDiscussionSession.query(User).get(db_argument.author_uid)
    db_current_user = DBDiscussionSession.query(User).filter_by(
        nickname=user).first()
    if db_author == db_current_user:
        return None

    db_author_settings = db_author.settings
    user_lang = DBDiscussionSession.query(Language).get(
        db_author_settings.lang_uid).ui_locales

    # send notification via websocket to last author
    _t_user = Translator(user_lang)
    if db_author_settings.should_send_notifications:
        send_request_for_info_popup_to_socketio(db_author.nickname,
                                                _t_user.get(_.argumentAdded),
                                                url)

    # send mail to last author
    if db_author_settings.should_send_mails:
        email_helper.send_mail_due_to_added_text(user_lang, url, db_author,
                                                 mailer)

    # find admin
    db_admin = user_handler.get_list_of_admins()[0]

    topic = _t_user.get(_.argumentAdded)
    content = get_text_for_message(db_author.firstname, user_lang, url,
                                   _.argumentAddedMessageContent, True)

    DBDiscussionSession.add(
        Message(from_author_uid=db_admin.uid,
                to_author_uid=db_author.uid,
                topic=topic,
                content=content,
                is_inbox=True))
    transaction.commit()
コード例 #3
0
def send_mail_due_to_added_text(lang, url, recipient, mailer):
    """
    Will send an email to the recipient

    :param lang: ui_locales
    :param url: current url
    :param recipient: User
    :param mailer: current mailer
    :return: duple with boolean for sent message, message-string
    """
    _t = Translator(lang)
    subject = _t.get(_.statementAdded)
    body = get_text_for_message(recipient.firstname, lang, url,
                                _.statementAddedMessageContent, False)

    return send_mail(mailer, subject, body, recipient.email, lang)
コード例 #4
0
 def test_get_text_for_add_text_message(self):
     for language, is_html, message in list(
             itertools.product(['en', 'de'], [True, False], [
                 _.statementAddedMessageContent,
                 _.argumentAddedMessageContent
             ])):
         text = tg.get_text_for_message(self.name, language, self.url,
                                        message, is_html)
         _t = Translator(language)
         intro = _t.get(message).format(self.name)
         if is_html:
             intro = intro + '<br>' + _t.get(
                 _.clickForMore) + ': <a href="{}/discuss{}">' + _t.get(
                     _.clickForMore) + '</a>'
             intro = intro.format(get_global_url(), self.url)
         else:
             intro = intro + '\n' + _t.get(_.clickForMore)
             intro = intro + ': {}/discuss{}'.format(
                 get_global_url(), self.url)
         self.assertEqual(text, intro)
         print(text)
コード例 #5
0
 def test_mail_for_reaction_on_argument(self):
     url = UrlManager(slug='cat-or-dog')
     url = url.get_url_for_reaction_on_argument(argument_uid=123,
                                                relation=Relations.REBUT,
                                                confrontation_argument=35)
     for language, for_html in list(
             itertools.product(['de', 'en'], [True, False])):
         subject = "Test Mail"
         body = get_text_for_message(
             nickname=DummyUser().firstname,
             lang=language,
             path=url,
             message_content=_.argumentAddedMessageContent,
             for_html=for_html)
         was_send, was_send_msg, msg = send_mail(
             mailer=DummyMailer,
             subject=subject,
             body=body,
             recipient=DummyUser().email,
             lang=language)
         self.assertTrue(was_send)
         self.assertEqual(msg.body, body)
コード例 #6
0
    def test_mail_for_justifying_statement(self):
        url = UrlManager(slug='cat-or-dog')
        url = url.get_url_for_justifying_statement(statement_uid=123,
                                                   attitude=Attitudes.AGREE)

        for language, for_html in list(
                itertools.product(['de', 'en'], [True, False])):
            subject = "Test Mail"
            body = get_text_for_message(
                nickname=DummyUser().firstname,
                lang=language,
                path=url,
                message_content=_.statementAddedMessageContent,
                for_html=for_html)
            was_send, was_send_msg, msg = send_mail(
                mailer=DummyMailer,
                subject=subject,
                body=body,
                recipient=DummyUser().email,
                lang=language)
            self.assertTrue(was_send)
            self.assertEqual(msg.body, body)
コード例 #7
0
def send_add_text_notification(url, conclusion_id, db_user: User, mailer):
    """
    Send notifications and mails to related users.

    :param url: current url
    :param conclusion_id: Statement.uid
    :param db_user: current users nickname
    :param mailer: Instance of pyramid mailer
    :return: None
    """
    # getting all text versions, the overview author, last editor and settings ob both authors as well as their languages
    db_textversions = DBDiscussionSession.query(TextVersion).filter_by(
        statement_uid=conclusion_id).all()
    db_root_author = DBDiscussionSession.query(User).get(
        db_textversions[0].author_uid)
    db_last_editor = DBDiscussionSession.query(User).get(
        db_textversions[-1].author_uid)
    db_root_author_settings = db_root_author.settings
    db_last_editor_settings = db_last_editor.settings
    root_lang = DBDiscussionSession.query(Language).get(
        db_root_author_settings.lang_uid).ui_locales
    editor_lang = DBDiscussionSession.query(Language).get(
        db_last_editor_settings.lang_uid).ui_locales
    _t_editor = Translator(editor_lang)
    _t_root = Translator(root_lang)

    # send mail to overview author
    if db_root_author_settings.should_send_mails \
            and db_user != db_root_author:
        email_helper.send_mail_due_to_added_text(root_lang, url,
                                                 db_root_author, mailer)

    # send mail to last author
    if db_last_editor_settings.should_send_mails \
            and db_last_editor != db_root_author \
            and db_last_editor != db_user:
        email_helper.send_mail_due_to_added_text(editor_lang, url,
                                                 db_last_editor, mailer)

    # send notification via websocket to overview author
    if db_root_author_settings.should_send_notifications and db_root_author != db_user:
        send_request_for_info_popup_to_socketio(db_root_author.nickname,
                                                _t_root.get(_.statementAdded),
                                                url,
                                                increase_counter=True)

    # send notification via websocket to last author
    if db_last_editor_settings.should_send_notifications \
            and db_last_editor != db_root_author \
            and db_last_editor != db_user:
        send_request_for_info_popup_to_socketio(db_last_editor.nickname,
                                                _t_editor.get(
                                                    _.statementAdded),
                                                url,
                                                increase_counter=True)

    # find admin, because generic mails are being sent by the admin
    db_admin = user_handler.get_list_of_admins()[0]

    # get topic and content for messages to both authors
    topic1 = _t_root.get(_.statementAdded)
    content1 = get_text_for_message(db_root_author.firstname, root_lang, url,
                                    _.statementAddedMessageContent, True)

    topic2 = _t_editor.get(_.statementAdded)
    content2 = get_text_for_message(db_last_editor.firstname, editor_lang, url,
                                    _.statementAddedMessageContent, True)

    if db_root_author != db_user:
        DBDiscussionSession.add(
            Message(from_author_uid=db_admin.uid,
                    to_author_uid=db_root_author.uid,
                    topic=topic1,
                    content=content1,
                    is_inbox=True))
    if db_root_author != db_last_editor and db_user != db_last_editor:
        DBDiscussionSession.add(
            Message(from_author_uid=db_admin.uid,
                    to_author_uid=db_last_editor.uid,
                    topic=topic2,
                    content=content2,
                    is_inbox=True))
    DBDiscussionSession.flush()
    transaction.commit()