Beispiel #1
0
def modify_registration(registration,
                        data,
                        management=False,
                        notify_user=True):
    old_price = registration.price
    personal_data_changes = {}
    regform = registration.registration_form
    data_by_field = registration.data_by_field
    if management or not registration.user:
        registration.user = get_user_by_email(data['email'])

    billable_items_locked = not management and registration.is_paid
    for form_item in regform.active_fields:
        field_impl = form_item.field_impl
        if management or not form_item.parent.is_manager_only:
            value = data.get(form_item.html_field_name)
        elif form_item.id not in data_by_field:
            # set default value for manager-only field if it didn't have one before
            value = field_impl.default_value
        else:
            # manager-only field that has data which should be preserved
            continue

        if form_item.id not in data_by_field:
            data_by_field[form_item.id] = RegistrationData(
                registration=registration, field_data=form_item.current_data)

        attrs = field_impl.process_form_data(
            registration,
            value,
            data_by_field[form_item.id],
            billable_items_locked=billable_items_locked)
        for key, val in attrs.iteritems():
            setattr(data_by_field[form_item.id], key, val)
        if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column:
            key = form_item.personal_data_type.column
            if getattr(registration, key) != value:
                personal_data_changes[key] = value
            setattr(registration, key, value)
    registration.sync_state()
    db.session.flush()
    # sanity check
    if billable_items_locked and old_price != registration.price:
        raise Exception(
            "There was an error while modifying your registration (price mismatch: %s / %s)",
            old_price, registration.price)
    if personal_data_changes:
        signals.event.registration_personal_data_modified.send(
            registration, change=personal_data_changes)
    signals.event.registration_updated.send(registration,
                                            management=management)
    notify_registration_modification(registration, notify_user)
    logger.info('Registration %s modified by %s', registration, session.user)
    registration.log(
        EventLogRealm.management if management else EventLogRealm.participants,
        EventLogKind.change,
        'Registration',
        'Registration modified: {}'.format(registration.full_name),
        session.user,
        data={'Email': registration.email})
    def _process(self):
        if self._getUser() is not None and self._getUser().isRegisteredInConf(self._conf):
            if (
                not self._conf.getRegistrationForm().inRegistrationPeriod()
                and not self._conf.getRegistrationForm().inModificationPeriod()
            ):
                flash(_("Your modification could not be recorded since the modification period is over."), "error")
                return redirect(url_for("event.confRegistrationFormDisplay", self._conf))
            else:
                rp = self._getUser().getRegistrantById(self._conf.getId())

                # Check if the email matches an existing user
                params = self._getRequestParams()
                email = self._regForm.getPersonalData().getValueFromParams(params, "email") or ""
                user = get_user_by_email(email)
                if user:
                    if not session.user:
                        flash(
                            _(
                                "The provided email ({email}) is linked to an Indico account. Please sign in with it "
                                "first."
                            ).format(email=email),
                            "error",
                        )
                        return redirect(url_for("event.confRegistrationFormDisplay-modify", self._conf))
                    elif session.user != user:
                        flash(
                            _(
                                "The provided email ({email}) is linked to another Indico account. Please sign in with "
                                "it first."
                            ).format(email=email),
                            "error",
                        )
                        return redirect(url_for("event.confRegistrationFormDisplay-modify", self._conf))

                # check if the email is being changed by another one that already exists
                if email != rp.getEmail() and self._conf.hasRegistrantByEmail(email):
                    raise FormValuesError(
                        _('There is already a user with the email "{email}". ' "Please choose another one.").format(
                            email or "--no email--"
                        )
                    )
                rp.setValues(self._getRequestParams(), self._getUser())
                log_msg = u"User modified his registration data: {}"
                self._conf.log(
                    EventLogRealm.participants,
                    EventLogKind.positive,
                    u"Registration",
                    log_msg.format(to_unicode(rp.getFullName(title=False, firstNameFirst=True))),
                    session.user,
                    data={u"Indico user": u"{} ({})".format(user.full_name, user.id) if user else u"None"},
                )
                notify_registration_modification(self._conf, rp)
                flash(_(u"Your registration has been modified successfully."), "success")
                if rp.doPay():
                    self._redirect(urlHandlers.UHConfRegistrationFormCreationDone.getURL(rp))
                else:
                    self._redirect(urlHandlers.UHConfRegistrationForm.getURL(self._conf))
        else:
            self._redirect(urlHandlers.UHConfRegistrationForm.getURL(self._conf))
Beispiel #3
0
def modify_registration(registration, data, management=False, notify_user=True):
    old_price = registration.price
    personal_data_changes = {}
    regform = registration.registration_form
    data_by_field = registration.data_by_field
    if management or not registration.user:
        registration.user = get_user_by_email(data['email'])

    billable_items_locked = not management and registration.is_paid
    for form_item in regform.active_fields:
        field_impl = form_item.field_impl
        if management or not form_item.parent.is_manager_only:
            value = data.get(form_item.html_field_name)
        elif form_item.id not in data_by_field:
            # set default value for manager-only field if it didn't have one before
            value = field_impl.default_value
        else:
            # manager-only field that has data which should be preserved
            continue

        if form_item.id not in data_by_field:
            data_by_field[form_item.id] = RegistrationData(registration=registration,
                                                           field_data=form_item.current_data)

        attrs = field_impl.process_form_data(registration, value, data_by_field[form_item.id],
                                             billable_items_locked=billable_items_locked)
        for key, val in attrs.iteritems():
            setattr(data_by_field[form_item.id], key, val)
        if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column:
            key = form_item.personal_data_type.column
            if getattr(registration, key) != value:
                personal_data_changes[key] = value
            setattr(registration, key, value)
    registration.sync_state()
    db.session.flush()
    # sanity check
    if billable_items_locked and old_price != registration.price:
        raise Exception("There was an error while modifying your registration (price mismatch: %s / %s)",
                        old_price, registration.price)
    if personal_data_changes:
        signals.event.registration_personal_data_modified.send(registration, change=personal_data_changes)
    signals.event.registration_updated.send(registration, management=management)
    notify_registration_modification(registration, notify_user)
    logger.info('Registration %s modified by %s', registration, session.user)
    regform.event.log(EventLogRealm.management if management else EventLogRealm.participants,
                      EventLogKind.change, 'Registration',
                      'Registration modified: {}'.format(registration.full_name),
                      session.user, data={'Email': registration.email})
Beispiel #4
0
def modify_registration(registration,
                        data,
                        management=False,
                        notify_user=True):
    old_price = registration.price
    with db.session.no_autoflush:
        regform = registration.registration_form
        data_by_field = registration.data_by_field
        if management or not registration.user:
            registration.user = get_user_by_email(data['email'])

        billable_items_locked = not management and registration.is_paid
        for form_item in regform.active_fields:
            field_impl = form_item.field_impl
            if management or not form_item.parent.is_manager_only:
                value = data.get(form_item.html_field_name)
            elif form_item.id not in data_by_field:
                # set default value for manager-only field if it didn't have one before
                value = field_impl.default_value
            else:
                # manager-only field that has data which should be preserved
                continue

            if form_item.id not in data_by_field:
                data_by_field[form_item.id] = RegistrationData(
                    registration=registration,
                    field_data=form_item.current_data)

            attrs = field_impl.process_form_data(
                registration,
                value,
                data_by_field[form_item.id],
                billable_items_locked=billable_items_locked)
            for key, val in attrs.iteritems():
                setattr(data_by_field[form_item.id], key, val)
            if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column:
                setattr(registration, form_item.personal_data_type.column,
                        value)
        registration.sync_state()
    db.session.flush()
    # sanity check
    if billable_items_locked and old_price != registration.price:
        raise Exception(
            "There was an error while modifying your registration (price mismatch: %s / %s)",
            old_price, registration.price)
    notify_registration_modification(registration, notify_user)
    logger.info('Registration %s modified by %s', registration, session.user)
Beispiel #5
0
    def _process(self):
        if self._getUser() is not None and self._getUser().isRegisteredInConf(self._conf):
            if not self._conf.getRegistrationForm().inRegistrationPeriod() and not self._conf.getRegistrationForm().inModificationPeriod():
                flash(_("Your modification could not be recorded since the modification period is over."), 'error')
                return redirect(url_for('event.confRegistrationFormDisplay', self._conf))
            else:
                rp = self._getUser().getRegistrantById(self._conf.getId())
                # check if the email is being changed by another one that already exists
                if self._getRequestParams().get("email", "") != rp.getEmail() and self._conf.hasRegistrantByEmail(self._getRequestParams().get("email", "")):
                    raise FormValuesError(_("There is already a user with the email \"%s\". Please choose another one") % self._getRequestParams().get("email", "--no email--"))
                rp.setValues(self._getRequestParams(), self._getUser())

                notify_registration_modification(self._conf, rp)
                flash(_(u"Your registration has been modified successfully."), 'success')
                if rp.doPay():
                    self._redirect(urlHandlers.UHConfRegistrationFormCreationDone.getURL(rp))
                else:
                    self._redirect(urlHandlers.UHConfRegistrationForm.getURL(self._conf))
        else:
            self._redirect(urlHandlers.UHConfRegistrationForm.getURL(self._conf))
Beispiel #6
0
def modify_registration(registration, data, management=False, notify_user=True):
    old_price = registration.price
    with db.session.no_autoflush:
        regform = registration.registration_form
        data_by_field = registration.data_by_field
        if management or not registration.user:
            registration.user = get_user_by_email(data['email'])

        billable_items_locked = not management and registration.is_paid
        for form_item in regform.active_fields:
            field_impl = form_item.field_impl
            if management or not form_item.parent.is_manager_only:
                value = data.get(form_item.html_field_name)
            elif form_item.id not in data_by_field:
                # set default value for manager-only field if it didn't have one before
                value = field_impl.default_value
            else:
                # manager-only field that has data which should be preserved
                continue

            if form_item.id not in data_by_field:
                data_by_field[form_item.id] = RegistrationData(registration=registration,
                                                               field_data=form_item.current_data)

            attrs = field_impl.process_form_data(registration, value, data_by_field[form_item.id],
                                                 billable_items_locked=billable_items_locked)
            for key, val in attrs.iteritems():
                setattr(data_by_field[form_item.id], key, val)
            if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column:
                setattr(registration, form_item.personal_data_type.column, value)
        registration.sync_state()
    db.session.flush()
    # sanity check
    if billable_items_locked and old_price != registration.price:
        raise Exception("There was an error while modifying your registration (price mismatch: %s / %s)",
                        old_price, registration.price)
    notify_registration_modification(registration, notify_user)
    logger.info('Registration %s modified by %s', registration, session.user)
    def _process(self):
        if self._getUser() is not None and self._getUser().isRegisteredInConf(self._conf):
            if not self._conf.getRegistrationForm().inRegistrationPeriod() and not self._conf.getRegistrationForm().inModificationPeriod():
                flash(_("Your modification could not be recorded since the modification period is over."), 'error')
                return redirect(url_for('event.confRegistrationFormDisplay', self._conf))
            else:
                rp = self._getUser().getRegistrantById(self._conf.getId())

                # Check if the email matches an existing user
                params = self._getRequestParams()
                email = self._regForm.getPersonalData().getValueFromParams(params, 'email') or ''
                user = get_user_by_email(email)
                if user:
                    if not session.user:
                        flash(_('The provided email ({email}) is linked to an Indico account. Please sign in with it '
                                'first.').format(email=email), 'error')
                        return redirect(url_for('event.confRegistrationFormDisplay-modify', self._conf))
                    elif session.user != user:
                        flash(_('The provided email ({email}) is linked to another Indico account. Please sign in with '
                                'it first.').format(email=email), 'error')
                        return redirect(url_for('event.confRegistrationFormDisplay-modify', self._conf))

                # check if the email is being changed by another one that already exists
                if email != rp.getEmail() and self._conf.hasRegistrantByEmail(email):
                    raise FormValuesError(_("There is already a user with the email \"{email}\". "
                                            "Please choose another one.").format(email or "--no email--"))
                rp.setValues(self._getRequestParams(), self._getUser())

                notify_registration_modification(self._conf, rp)
                flash(_(u"Your registration has been modified successfully."), 'success')
                if rp.doPay():
                    self._redirect(urlHandlers.UHConfRegistrationFormCreationDone.getURL(rp))
                else:
                    self._redirect(urlHandlers.UHConfRegistrationForm.getURL(self._conf))
        else:
            self._redirect(urlHandlers.UHConfRegistrationForm.getURL(self._conf))
Beispiel #8
0
def modify_registration(registration,
                        data,
                        management=False,
                        notify_user=True):
    old_data = snapshot_registration_data(registration)
    old_price = registration.price
    personal_data_changes = {}
    regform = registration.registration_form
    data_by_field = registration.data_by_field
    if 'email' in data and (management or not registration.user):
        registration.user = get_user_by_email(data['email'])

    billable_items_locked = not management and registration.is_paid
    for form_item in regform.active_fields:
        if form_item.is_purged:
            continue

        field_impl = form_item.field_impl
        has_data = form_item.html_field_name in data
        can_modify = management or not form_item.parent.is_manager_only

        if has_data and can_modify:
            value = data.get(form_item.html_field_name)
        elif not has_data and form_item.id not in data_by_field:
            # set default value for a field if it didn't have one before (including manager-only fields)
            value = field_impl.default_value
        else:
            # keep current value
            continue

        if form_item.id not in data_by_field:
            data_by_field[form_item.id] = RegistrationData(
                registration=registration, field_data=form_item.current_data)

        attrs = field_impl.process_form_data(
            registration,
            value,
            data_by_field[form_item.id],
            billable_items_locked=billable_items_locked)
        for key, val in attrs.items():
            setattr(data_by_field[form_item.id], key, val)
        if form_item.type == RegistrationFormItemType.field_pd and form_item.personal_data_type.column:
            key = form_item.personal_data_type.column
            if getattr(registration, key) != value:
                personal_data_changes[key] = value
            setattr(registration, key, value)
    if not management and regform.needs_publish_consent:
        registration.consent_to_publish = data.get(
            'consent_to_publish', RegistrationVisibility.nobody)
    registration.sync_state()
    db.session.flush()
    # sanity check
    if billable_items_locked and old_price != registration.price:
        raise Exception(
            'There was an error while modifying your registration (price mismatch: %s / %s)',
            old_price, registration.price)
    if personal_data_changes:
        signals.event.registration_personal_data_modified.send(
            registration, change=personal_data_changes)
    signals.event.registration_updated.send(registration,
                                            management=management,
                                            data=data)

    new_data = snapshot_registration_data(registration)
    diff = diff_registration_data(old_data, new_data)
    notify_registration_modification(registration,
                                     notify_user,
                                     diff=diff,
                                     old_price=old_price)
    logger.info('Registration %s modified by %s', registration, session.user)
    registration.log(
        EventLogRealm.management if management else EventLogRealm.participants,
        LogKind.change,
        'Registration',
        f'Registration modified: {registration.full_name}',
        session.user,
        data={'Email': registration.email})