Esempio n. 1
0
 def _checkParams(self):
     self.invitation = None
     try:
         token = request.args['invitation']
     except KeyError:
         return
     try:
         UUID(hex=token)
     except ValueError:
         flash(_("Your invitation code is not valid."), 'warning')
         return
     self.invitation = RegistrationInvitation.find(uuid=token).with_parent(self.regform).first()
     if self.invitation is None:
         flash(_("This invitation does not exist or has been withdrawn."), 'warning')
Esempio n. 2
0
def create_registration(regform,
                        data,
                        invitation=None,
                        management=False,
                        notify_user=True):
    registration = Registration(registration_form=regform,
                                user=get_user_by_email(data['email']),
                                base_price=regform.base_price,
                                currency=regform.currency)
    for form_item in regform.active_fields:
        if form_item.parent.is_manager_only:
            with db.session.no_autoflush:
                value = form_item.field_impl.default_value
        else:
            value = data.get(form_item.html_field_name)
        with db.session.no_autoflush:
            data_entry = RegistrationData()
            registration.data.append(data_entry)
            for attr, value in form_item.field_impl.process_form_data(
                    registration, value).iteritems():
                setattr(data_entry, attr, value)
        if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column:
            setattr(registration, form_item.personal_data_type.column, value)
    if invitation is None:
        # Associate invitation based on email in case the user did not use the link
        with db.session.no_autoflush:
            invitation = (RegistrationInvitation.find(
                email=data['email'],
                registration_id=None).with_parent(regform).first())
    if invitation:
        invitation.state = InvitationState.accepted
        invitation.registration = registration
    registration.sync_state(_skip_moderation=management)
    db.session.flush()
    notify_registration_creation(registration, notify_user)
    logger.info('New registration %s by %s', registration, session.user)
    regform.event_new.log(
        EventLogRealm.management if management else EventLogRealm.participants,
        EventLogKind.positive,
        'Registration',
        'New registration: {}'.format(registration.full_name),
        session.user,
        data={'Email': registration.email})
    return registration
Esempio n. 3
0
 def validate_email(self, field):
     if RegistrationInvitation.find(email=field.data).with_parent(self.regform).count():
         raise ValidationError(_("There is already an invitation with this email address."))
     if Registration.find(email=field.data, is_active=True).with_parent(self.regform).count():
         raise ValidationError(_("There is already a registration with this email address."))
Esempio n. 4
0
 def _checkParams(self, params):
     RHManageRegFormBase._checkParams(self, params)
     self.invitation = RegistrationInvitation.get_one(
         request.view_args['invitation_id'])
Esempio n. 5
0
 def _checkParams(self, params):
     RHManageRegFormBase._checkParams(self, params)
     self.invitation = RegistrationInvitation.get_one(request.view_args['invitation_id'])
Esempio n. 6
0
 def _process_args(self):
     RHManageRegFormBase._process_args(self)
     self.invitation = RegistrationInvitation.get_one(
         request.view_args['invitation_id'])
Esempio n. 7
0
 def _process_args(self):
     RHManageRegFormBase._process_args(self)
     self.invitation = RegistrationInvitation.get_one(request.view_args['invitation_id'])
Esempio n. 8
0
 def validate_email(self, field):
     if RegistrationInvitation.find(email=field.data).with_parent(self.regform).count():
         raise ValidationError(_("There is already an invitation with this email address."))
     if Registration.find(email=field.data, is_active=True).with_parent(self.regform).count():
         raise ValidationError(_("There is already a registration with this email address."))
Esempio n. 9
0
def test_get_user_data(monkeypatch, dummy_event, dummy_user, dummy_regform):
    monkeypatch.setattr(
        'indico.modules.events.registration.util.notify_invitation',
        lambda *args, **kwargs: None)
    session.set_session_user(dummy_user)

    assert get_user_data(dummy_regform, None) == {}

    expected = {
        'email': '*****@*****.**',
        'first_name': 'Guinea',
        'last_name': 'Pig'
    }

    user_data = get_user_data(dummy_regform, dummy_user)
    assert user_data == expected

    user_data = get_user_data(dummy_regform, session.user)
    assert user_data == expected

    dummy_user.title = UserTitle.mr
    dummy_user.phone = '+1 22 50 14'
    dummy_user.address = 'Geneva'
    user_data = get_user_data(dummy_regform, dummy_user)
    assert type(user_data['title']) is dict
    assert user_data['phone'] == '+1 22 50 14'

    # Check that data is taken from the invitation
    invitation = RegistrationInvitation(skip_moderation=True,
                                        email='*****@*****.**',
                                        first_name='Amy',
                                        last_name='Wang',
                                        affiliation='ACME Inc.')
    dummy_regform.invitations.append(invitation)

    dummy_user.title = None
    user_data = get_user_data(dummy_regform, dummy_user, invitation)
    assert user_data == {
        'email': '*****@*****.**',
        'first_name': 'Amy',
        'last_name': 'Wang',
        'phone': '+1 22 50 14',
        'address': 'Geneva',
        'affiliation': 'ACME Inc.'
    }

    # Check that data is taken from the invitation when user is missing
    user_data = get_user_data(dummy_regform, None, invitation)
    assert user_data == {
        'email': '*****@*****.**',
        'first_name': 'Amy',
        'last_name': 'Wang',
        'affiliation': 'ACME Inc.'
    }

    # Check that data from disabled/deleted fields is not used
    title_field = next(item for item in dummy_regform.active_fields
                       if item.type == RegistrationFormItemType.field_pd
                       and item.personal_data_type.name == 'title')
    title_field.is_enabled = False

    dummy_user.title = UserTitle.dr
    user_data = get_user_data(dummy_regform, dummy_user)
    assert 'title' not in user_data

    phone_field = next(item for item in dummy_regform.active_fields
                       if item.type == RegistrationFormItemType.field_pd
                       and item.personal_data_type.name == 'phone')
    phone_field.is_deleted = True

    user_data = get_user_data(dummy_regform, dummy_user)
    assert 'title' not in user_data
    assert 'phone' not in user_data
    assert user_data == {
        'email': '*****@*****.**',
        'first_name': 'Guinea',
        'last_name': 'Pig',
        'address': 'Geneva'
    }

    for item in dummy_regform.active_fields:
        item.is_enabled = False

    assert get_user_data(dummy_regform, dummy_user) == {}
    assert get_user_data(dummy_regform, dummy_user, invitation) == {}
Esempio n. 10
0
def test_import_invitations_error(dummy_regform, dummy_user):
    dummy_user.secondary_emails.add('*****@*****.**')

    create_registration(dummy_regform, {
        'email': dummy_user.email,
        'first_name': dummy_user.first_name,
        'last_name': dummy_user.last_name
    },
                        notify_user=False)

    create_registration(dummy_regform, {
        'email': '*****@*****.**',
        'first_name': 'Big',
        'last_name': 'Boss'
    },
                        notify_user=False)

    invitation = RegistrationInvitation(skip_moderation=True,
                                        email='*****@*****.**',
                                        first_name='Bill',
                                        last_name='Doe',
                                        affiliation='ACME Inc.')
    dummy_regform.invitations.append(invitation)

    # duplicate e-mail (registration)
    csv = b'\n'.join([b'Big,Boss,ACME Inc.,[email protected]'])

    with pytest.raises(UserValueError) as e:
        import_invitations_from_csv(dummy_regform,
                                    BytesIO(csv),
                                    email_from='*****@*****.**',
                                    email_subject='invitation',
                                    email_body='Invitation to event',
                                    skip_moderation=False,
                                    skip_existing=False)
    assert 'a registration with this email already exists' in str(e.value)
    assert 'Row 1' in str(e.value)

    # duplicate user
    csv = b'\n'.join([b'Big,Boss,ACME Inc.,[email protected]'])

    with pytest.raises(UserValueError) as e:
        import_invitations_from_csv(dummy_regform,
                                    BytesIO(csv),
                                    email_from='*****@*****.**',
                                    email_subject='invitation',
                                    email_body='Invitation to event',
                                    skip_moderation=False,
                                    skip_existing=False)
    assert 'a registration for this user already exists' in str(e.value)
    assert 'Row 1' in str(e.value)

    # duplicate email (invitation)
    csv = b'\n'.join([b'Bill,Doe,ACME Inc.,[email protected]'])
    with pytest.raises(UserValueError) as e:
        import_invitations_from_csv(dummy_regform,
                                    BytesIO(csv),
                                    email_from='*****@*****.**',
                                    email_subject='invitation',
                                    email_body='Invitation to event',
                                    skip_moderation=False,
                                    skip_existing=False)
    assert 'an invitation for this user already exists' in str(e.value)
    assert 'Row 1' in str(e.value)