Exemple #1
0
    def _create_test_data():
        video = Video(title='test', status='ready')
        video.thumbnails = [VideoThumbnail(url='http://lorempixel.com/640/360/technics/2/',
                                           width=640, height=360)]
        video.collaborators = [VideoCollaborator(email=recipient, name='Vidkun Quisling')]
        account = Account(id=88888888, name='test')
        user0 = AccountUser(username=recipient, password_hash='',
                            display_name='Maynard Cohen',
                            avatar='cohen')
        user1 = AccountUser(username='******', password_hash='',
                            display_name='Paul Hayes',
                            avatar='hayes')
        account.users = [user0, user1]
        account.videos = [video]
        user0.connections = [AccountUserConnection(connection=user1)]
        user1.connections = [AccountUserConnection(
            connection=user0, message="Connect, collaborate, ... profit!")]
        db.session.add(account)
        db.session.flush()
        video.comments = [VideoComment(comment='I like this!', timestamp=10,
                                       user_type='collaborator',
                                       user_id=video.collaborators[0].id)]

        reg_tokens = [RegistrationToken.new(recipient).id]

        invite_request = InviteRequest(email=recipient, name='Maynard Cohen')
        db.session.add(invite_request)

        db.session.commit()
        return namedtuple('Data', 'video, account, reg_tokens, invite_request')(
            video, account, reg_tokens, invite_request)
Exemple #2
0
def send_collaborator_invite_email(collaborator_id, sending_user_id, **kwargs):
    collaborator = VideoCollaborator.query.get(collaborator_id)
    if not collaborator:
        return

    sender = AccountUser.query.get(sending_user_id)

    # if the video isn't ready yet, wait 5 mins and try again
    if (collaborator.video.status not in ('ready', 'published') and
            current_app.config.get('ENABLE_BACKGROUND_SQS')):
        kwargs['_delay_seconds'] = 300
        send_collaborator_invite_email(collaborator_id, sending_user_id, **kwargs)
        return

    if current_app.config.get('ENABLE_REGISTRATION_AUTH'):
        kwargs['reg_token'] = RegistrationToken.new(collaborator.email).id

    template = email_template_env.get_template('collaborator_invite.html')
    body = template.render(
        collaborator=collaborator,
        sender=sender,
        video=collaborator.video,
        **kwargs
    )
    send_email(collaborator.email, body)