Repository: indico/indico
Issue: Registration form zodbimporter fixes

- enable "publish registrants" unless menu customization is enabled and the registrant/participation list menu item is disabled
- force input_type=email for pd_type=email fields


Changed files:
indico_zodbimport/modules/event_regforms.py

diff --git a/indico_zodbimport/modules/event_regforms.py b/indico_zodbimport/modules/event_regforms.py
index 20bf7bf6e8..3193947b56 100644
--- a/indico_zodbimport/modules/event_regforms.py
+++ b/indico_zodbimport/modules/event_regforms.py
@@ -37,6 +37,7 @@ from indico.core.db import db
 from indico.core.db.sqlalchemy import UTCDateTime, PyIntEnum
 from indico.modules.events import Event, EventSetting
 from indico.modules.events.features.util import set_feature_enabled
+from indico.modules.events.layout.models import MenuEntry
 from indico.modules.events.registration.models.form_fields import (RegistrationFormPersonalDataField,
                                                                    RegistrationFormField, RegistrationFormFieldData)
 from indico.modules.events.registration.models.forms import RegistrationForm, ModificationMode
@@ -44,7 +45,6 @@ from indico.modules.events.registration.models.items import (RegistrationFormSec
                                                              RegistrationFormPersonalDataSection, RegistrationFormText)
 from indico.modules.events.registration.models.legacy_mapping import LegacyRegistrationMapping
 from indico.modules.events.registration.models.registrations import Registration, RegistrationState, RegistrationData
-from indico.modules.payment import settings as payment_settings
 from indico.modules.payment.models.transactions import TransactionStatus, PaymentTransaction
 from indico.modules.users import User
 from indico.util.caching import memoize
@@ -151,6 +151,8 @@ class RegformMigration(object):
         self.regform.manager_notification_recipients = sorted(set(old_rf.notification._ccList) |
                                                               set(old_rf.notification._toList))
         self.regform.manager_notifications_enabled = bool(self.regform.manager_notification_recipients)
+        self.regform.publish_registrations_enabled = not self.importer.participant_list_disabled.get(int(self.event.id),
+                                                                                                     False)
         old_messages = self.importer.all_payment_settings.get(int(self.event.id))
         if old_messages:
             self.regform.message_unpaid = old_messages.get('register_email', '')
@@ -377,18 +379,20 @@ class RegformMigration(object):
         field = field_cls(registration_form=self.regform, personal_data_type=pd_type, is_required=is_required,
                           is_enabled=is_enabled, title=_sanitize(old_field._caption),
                           description=_sanitize(getattr(old_field, '_description', '')))
-        self._migrate_field_input(field, old_field)
+        self._migrate_field_input(field, old_field, pd_type)
         self.importer.print_info(cformat('%{green}Field/{}%{reset} - %{cyan}{}').format(field.input_type, field.title))
         self.field_map[old_field] = field
         return field
 
-    def _migrate_field_input(self, field, old_field):
+    def _migrate_field_input(self, field, old_field, pd_type):
         field_data = {}
         field_billable = False
         field_places_limit = False
         inp = old_field._input
         old_type = inp._id
-        if old_type in {'text', 'country', 'file'}:
+        if pd_type == PersonalDataType.email:
+            input_type = 'email'
+        elif old_type in {'text', 'country', 'file'}:
             input_type = old_type
         elif old_type == 'textarea':
             input_type = 'textarea'
@@ -963,7 +967,6 @@ class EventRegformImporter(LocalFileImporterMixin, Importer):
 
     def load_data(self):
         self.print_step("Loading some data")
-        self.default_currency = payment_settings.get('currency')
         self.all_users_by_email = {}
         for user in User.query.options(joinedload('_all_emails')):
             if user.is_deleted:
@@ -977,6 +980,9 @@ class EventRegformImporter(LocalFileImporterMixin, Importer):
                 value = setting.value.strip() if isinstance(setting.value, basestring) else setting.value
                 if value:
                     self.all_payment_settings[setting.event_id][setting.name] = value
+        self.participant_list_disabled = {x for x, in db.session.query(MenuEntry.event_id)
+                                                                .filter(MenuEntry.name == 'participants',
+                                                                        ~MenuEntry.is_enabled)}
 
     @contextmanager
     def _monkeypatch(self):