示例#1
0
 def test_get_or_create_user_is_spam(self):
     fullname = 'John Deacon'
     username = '[email protected]'
     fetched, created = utils.get_or_create_user(fullname, username, True)
     assert_true(created)
     assert_equal(fetched.fullname, fullname)
     assert_equal(fetched.username, username)
     assert_true('is_spam' in fetched.system_tags)
示例#2
0
 def test_get_or_create_user_not_exists(self):
     fullname = 'Roger Taylor'
     username = '[email protected]'
     fetched, created = utils.get_or_create_user(fullname, username, False)
     assert_true(created)
     assert_equal(fetched.fullname, fullname)
     assert_equal(fetched.username, username)
     assert_false('is_spam' in fetched.system_tags)
示例#3
0
def add_poster_by_email(conference, message):
    """
    :param Conference conference:
    :param ConferenceMessage message:
    """
    # Fail if no attachments
    if not message.attachments:
        return send_mail(message.sender_email, CONFERENCE_FAILED, fullname=message.sender_display)

    created = []

    with TokuTransaction():
        user, user_created = utils.get_or_create_user(message.sender_display, message.sender_email, message.is_spam)
        if user_created:
            created.append(user)
            set_password_url = web_url_for("reset_password", verification_key=user.verification_key, _absolute=True)
        else:
            set_password_url = None

        node, node_created = utils.get_or_create_node(message.subject, user)
        if node_created:
            created.append(node)

        utils.provision_node(conference, message, node, user)
        utils.record_message(message, created)

    utils.upload_attachments(user, node, message.attachments)

    download_url = node.web_url_for(
        "addon_view_or_download_file",
        path=message.attachments[0].filename,
        provider="osfstorage",
        action="download",
        _absolute=True,
    )

    # Send confirmation email
    send_mail(
        message.sender_email,
        CONFERENCE_SUBMITTED,
        conf_full_name=conference.name,
        conf_view_url=web_url_for("conference_results", meeting=message.conference_name, _absolute=True),
        fullname=message.sender_display,
        user_created=user_created,
        set_password_url=set_password_url,
        profile_url=user.absolute_url,
        node_url=node.absolute_url,
        file_url=download_url,
        presentation_type=message.conference_category.lower(),
        is_spam=message.is_spam,
    )
示例#4
0
 def test_get_or_create_user_exists(self):
     user = UserFactory()
     fetched, created = utils.get_or_create_user(user.fullname, user.username, True)
     assert_false(created)
     assert_equal(user._id, fetched._id)
     assert_false('is_spam' in fetched.system_tags)
示例#5
0
def add_poster_by_email(conference, message):
    """
    :param Conference conference:
    :param ConferenceMessage message:
    """
    # Fail if no attachments
    if not message.attachments:
        return send_mail(
            message.sender_email,
            CONFERENCE_FAILED,
            fullname=message.sender_display,
        )

    created = []

    with TokuTransaction():
        user, user_created = utils.get_or_create_user(
            message.sender_display,
            message.sender_email,
            message.is_spam,
        )
        if user_created:
            created.append(user)
            user.system_tags.append('osf4m')
            set_password_url = web_url_for(
                'reset_password',
                verification_key=user.verification_key,
                _absolute=True,
            )
            user.date_last_login = datetime.utcnow()
            user.save()
        else:
            set_password_url = None

        node, node_created = utils.get_or_create_node(message.subject, user)
        if node_created:
            created.append(node)
            node.system_tags.append('osf4m')
            node.save()

        utils.provision_node(conference, message, node, user)
        utils.record_message(message, created)
    # Prevent circular import error
    from framework.auth import signals as auth_signals
    if user_created:
        auth_signals.user_confirmed.send(user)

    utils.upload_attachments(user, node, message.attachments)

    download_url = node.web_url_for(
        'addon_view_or_download_file',
        path=message.attachments[0].filename,
        provider='osfstorage',
        action='download',
        _absolute=True,
    )

    # Send confirmation email
    send_mail(
        message.sender_email,
        CONFERENCE_SUBMITTED,
        conf_full_name=conference.name,
        conf_view_url=web_url_for(
            'conference_results',
            meeting=message.conference_name,
            _absolute=True,
        ),
        fullname=message.sender_display,
        user_created=user_created,
        set_password_url=set_password_url,
        profile_url=user.absolute_url,
        node_url=node.absolute_url,
        file_url=download_url,
        presentation_type=message.conference_category.lower(),
        is_spam=message.is_spam,
    )
    if node_created and user_created:
        signals.osf4m_user_created.send(user, conference=conference, node=node)