Skip to content

Commit

Permalink
Remove mandatory email requirement from new participant form (#1889)
Browse files Browse the repository at this point in the history
* Remove mandatory email requirement from new participant form

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Check for field data, add migration name

* Optional join of EmailAddress list

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kiran Jonnalagadda <[email protected]>
  • Loading branch information
3 people authored Oct 6, 2023
1 parent d8ab0b3 commit 1f03eb8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
7 changes: 5 additions & 2 deletions funnel/forms/sync_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class TicketParticipantForm(forms.Form):
)
email = forms.EmailField(
__("Email"),
validators=[forms.validators.DataRequired(), forms.validators.ValidEmail()],
filters=[forms.filters.strip()],
validators=[forms.validators.Optional(), forms.validators.ValidEmail()],
filters=[forms.filters.none_if_empty()],
)
phone = forms.StringField(
__("Phone number"),
Expand Down Expand Up @@ -219,6 +219,9 @@ def set_queries(self) -> None:
def validate(self, *args, **kwargs) -> bool:
"""Validate form."""
result = super().validate(*args, **kwargs)
if self.email.data is None:
self.user = None
return True
with db.session.no_autoflush:
accountemail = AccountEmail.get(email=self.email.data)
if accountemail is not None:
Expand Down
6 changes: 4 additions & 2 deletions funnel/models/sync_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class TicketParticipant(EmailAddressMixin, UuidMixin, BaseMixin, Model):
"""A participant in one or more events, synced from an external ticket source."""

__tablename__ = 'ticket_participant'
__email_optional__ = False
__email_optional__ = True
__email_for__ = 'participant'

fullname = with_roles(
Expand Down Expand Up @@ -376,7 +376,9 @@ def checkin_list(cls, ticket_event: TicketEvent) -> list: # TODO: List type?
TicketEventParticipant,
TicketParticipant.id == TicketEventParticipant.ticket_participant_id,
)
.join(EmailAddress, EmailAddress.id == TicketParticipant.email_address_id)
.outerjoin(
EmailAddress, EmailAddress.id == TicketParticipant.email_address_id
)
.outerjoin(
SyncTicket, TicketParticipant.id == SyncTicket.ticket_participant_id
)
Expand Down
4 changes: 3 additions & 1 deletion funnel/views/ticket_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def ticket_participant_checkin_data(ticket_participant, project, ticket_event):
'puuid_b58': puuid_b58,
'fullname': ticket_participant.fullname,
'company': ticket_participant.company,
'email': mask_email(ticket_participant.email),
'email': mask_email(ticket_participant.email)
if ticket_participant.email
else None,
'badge_printed': ticket_participant.badge_printed,
'checked_in': ticket_participant.checked_in,
'ticket_type_titles': ticket_participant.ticket_type_titles,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Make ticket participant email optional.
Revision ID: 017c60414c03
Revises: 4f9ca10b7b9d
Create Date: 2023-10-05 15:08:34.540672
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = '017c60414c03'
down_revision: str = '4f9ca10b7b9d'
branch_labels: str | tuple[str, ...] | None = None
depends_on: str | tuple[str, ...] | None = None


def upgrade(engine_name: str = '') -> None:
"""Upgrade all databases."""
# Do not modify. Edit `upgrade_` instead
globals().get(f'upgrade_{engine_name}', lambda: None)()


def downgrade(engine_name: str = '') -> None:
"""Downgrade all databases."""
# Do not modify. Edit `downgrade_` instead
globals().get(f'downgrade_{engine_name}', lambda: None)()


def upgrade_() -> None:
"""Upgrade default database."""
with op.batch_alter_table('ticket_participant', schema=None) as batch_op:
batch_op.alter_column(
'email_address_id', existing_type=sa.INTEGER(), nullable=True
)


def downgrade_() -> None:
"""Downgrade default database."""
with op.batch_alter_table('ticket_participant', schema=None) as batch_op:
batch_op.alter_column(
'email_address_id', existing_type=sa.INTEGER(), nullable=False
)

0 comments on commit 1f03eb8

Please sign in to comment.