~homeworkprod/byceps

30551318892174287d26f20393421fc5af72a424 — Jochen Kupperschmidt 5 months ago a5c7b39
Introduce `get_ticket`
M byceps/blueprints/admin/ticketing/service.py => byceps/blueprints/admin/ticketing/service.py +1 -3
@@ 40,9 40,7 @@ def get_events(ticket_id: TicketID) -> Iterator[TicketEventData]:


def _fake_ticket_creation_event(ticket_id: TicketID) -> TicketEvent:
    ticket = ticket_service.find_ticket(ticket_id)
    if ticket is None:
        raise ValueError('Unknown ticket ID')
    ticket = ticket_service.get_ticket(ticket_id)

    data: TicketEventData = {}


M byceps/services/ticketing/ticket_revocation_service.py => byceps/services/ticketing/ticket_revocation_service.py +1 -4
@@ 22,10 22,7 @@ def revoke_ticket(
    ticket_id: TicketID, initiator_id: UserID, *, reason: Optional[str] = None
) -> None:
    """Revoke the ticket."""
    ticket = ticket_service.find_ticket(ticket_id)

    if ticket is None:
        raise ValueError('Unknown ticket ID.')
    ticket = ticket_service.get_ticket(ticket_id)

    # Release seat.
    if ticket.occupied_seat_id:

M byceps/services/ticketing/ticket_seat_management_service.py => byceps/services/ticketing/ticket_seat_management_service.py +1 -4
@@ 135,10 135,7 @@ def _get_ticket(ticket_id: TicketID) -> DbTicket:
    Raise an exception if the ID is unknown or if the ticket has been
    revoked.
    """
    ticket = ticket_service.find_ticket(ticket_id)

    if ticket is None:
        raise ValueError(f'Unknown ticket ID "{ticket_id}"')
    ticket = ticket_service.get_ticket(ticket_id)

    if ticket.revoked:
        raise TicketIsRevoked(f'Ticket {ticket_id} has been revoked.')

M byceps/services/ticketing/ticket_service.py => byceps/services/ticketing/ticket_service.py +11 -3
@@ 30,9 30,7 @@ def update_ticket_code(
    ticket_id: TicketID, code: str, initiator_id: UserID
) -> None:
    """Set a custom code for the ticket."""
    ticket = find_ticket(ticket_id)
    if ticket is None:
        raise ValueError(f'Unknown ticket ID "{ticket_id}"')
    ticket = get_ticket(ticket_id)

    if not ticket_code_service.is_ticket_code_wellformed(code):
        raise ValueError(f'Ticket code "{code}" is not well-formed')


@@ 73,6 71,16 @@ def find_ticket(ticket_id: TicketID) -> Optional[DbTicket]:
    return DbTicket.query.get(ticket_id)


def get_ticket(ticket_id: TicketID) -> DbTicket:
    """Return the ticket with that id, or raise an exception."""
    ticket = find_ticket(ticket_id)

    if ticket is None:
        raise ValueError(f'Unknown ticket ID "{ticket_id}"')

    return ticket


def find_ticket_by_code(
    party_id: PartyID, code: TicketCode
) -> Optional[DbTicket]:

M byceps/services/ticketing/ticket_user_checkin_service.py => byceps/services/ticketing/ticket_user_checkin_service.py +2 -5
@@ 61,10 61,7 @@ def check_in_user(


def _get_ticket_for_checkin(party_id: PartyID, ticket_id: TicketID) -> DbTicket:
    ticket = ticket_service.find_ticket(ticket_id)

    if ticket is None:
        raise ValueError(f"Unknown ticket ID '{ticket_id}'")
    ticket = ticket_service.get_ticket(ticket_id)

    if ticket.party_id != party_id:
        raise TicketBelongsToDifferentParty(


@@ 106,7 103,7 @@ def _get_user_for_checkin(user_id: UserID) -> User:

def revert_user_check_in(ticket_id: TicketID, initiator_id: UserID) -> None:
    """Revert a user check-in that was done by mistake."""
    ticket = ticket_service.find_ticket(ticket_id)
    ticket = ticket_service.get_ticket(ticket_id)

    initiator = user_service.get_user(initiator_id)


M byceps/services/ticketing/ticket_user_management_service.py => byceps/services/ticketing/ticket_user_management_service.py +4 -4
@@ 26,7 26,7 @@ def appoint_user_manager(
    ticket_id: TicketID, manager_id: UserID, initiator_id: UserID
) -> None:
    """Appoint the user as the ticket's user manager."""
    ticket = ticket_service.find_ticket(ticket_id)
    ticket = ticket_service.get_ticket(ticket_id)

    if ticket.revoked:
        raise TicketIsRevoked(f'Ticket {ticket_id} has been revoked.')


@@ 48,7 48,7 @@ def appoint_user_manager(

def withdraw_user_manager(ticket_id: TicketID, initiator_id: UserID) -> None:
    """Withdraw the ticket's custom user manager."""
    ticket = ticket_service.find_ticket(ticket_id)
    ticket = ticket_service.get_ticket(ticket_id)

    if ticket.revoked:
        raise TicketIsRevoked(f'Ticket {ticket_id} has been revoked.')


@@ 71,7 71,7 @@ def appoint_user(
    ticket_id: TicketID, user_id: UserID, initiator_id: UserID
) -> None:
    """Appoint the user as the ticket's user."""
    ticket = ticket_service.find_ticket(ticket_id)
    ticket = ticket_service.get_ticket(ticket_id)

    if ticket.revoked:
        raise TicketIsRevoked(f'Ticket {ticket_id} has been revoked.')


@@ 105,7 105,7 @@ def appoint_user(

def withdraw_user(ticket_id: TicketID, initiator_id: UserID) -> None:
    """Withdraw the ticket's user."""
    ticket = ticket_service.find_ticket(ticket_id)
    ticket = ticket_service.get_ticket(ticket_id)

    if ticket.revoked:
        raise TicketIsRevoked(f'Ticket {ticket_id} has been revoked.')

M tests/integration/services/ticketing/test_revocation.py => tests/integration/services/ticketing/test_revocation.py +1 -1
@@ 86,7 86,7 @@ def test_revoke_ticket(admin_app, ticket, ticketing_admin):

    # -------------------------------- #

    ticket_after = ticket_service.find_ticket(ticket_id)
    ticket_after = ticket_service.get_ticket(ticket_id)
    assert ticket_after.revoked

    events_after = event_service.get_events_for_ticket(ticket_after.id)

M tests/integration/services/ticketing/test_user_check_in.py => tests/integration/services/ticketing/test_user_check_in.py +1 -1
@@ 56,7 56,7 @@ def test_check_in_user(admin_app, party, ticket, ticketing_admin, make_user):

    # -------------------------------- #

    ticket_after = ticket_service.find_ticket(ticket_id)
    ticket_after = ticket_service.get_ticket(ticket_id)
    assert ticket_before.user_checked_in

    assert event.__class__ is TicketCheckedIn