Esempio n. 1
0
def get_booking_by_token(token: str) -> tuple[str, int]:
    email: Optional[str] = request.args.get("email", None)
    offer_id = dehumanize(request.args.get("offer_id", None))

    check_user_is_logged_in_or_email_is_provided(current_user, email)

    booking = booking_repository.find_by(token, email, offer_id)
    bookings_validation.check_is_usable(booking)

    if check_user_can_validate_bookings(current_user, booking.offererId):
        response = _create_response_to_get_booking_by_token(booking)
        return jsonify(response), 200

    return "", 204
Esempio n. 2
0
def patch_booking_by_token(token: str) -> tuple[str, int]:
    email: Optional[str] = request.args.get("email", None)
    humanized_offer_id: Optional[str] = request.args.get("offer_id")
    offer_id: Optional[int] = dehumanize(humanized_offer_id)
    booking = booking_repository.find_by(token, email, offer_id)

    if current_user.is_authenticated:
        check_user_has_access_to_offerer(current_user, booking.offererId)
    else:
        check_email_and_offer_id_for_anonymous_user(email, offer_id)

    bookings_api.mark_as_used(booking)

    return "", 204
Esempio n. 3
0
def patch_booking_keep_by_token(token: str):
    """Let a pro user mark a booking as _not_ used."""
    booking = booking_repository.find_by(token=token.upper())
    offerer_id = booking.stock.offer.venue.managingOffererId
    valid_api_key = _get_api_key_from_header(request)

    if current_user.is_authenticated:
        check_user_can_validate_bookings_v2(current_user, offerer_id)

    if valid_api_key:
        check_api_key_allows_to_validate_booking(valid_api_key, offerer_id)

    bookings_api.mark_as_unused(booking)

    return "", 204
Esempio n. 4
0
def patch_booking_keep_by_token(token: str) -> None:
    # in French, to be used by Swagger for the API documentation
    """Annulation de la validation d'une réservation."""
    booking = booking_repository.find_by(token=token)

    if current_user.is_authenticated:
        check_user_can_validate_bookings_v2(current_user, booking.offererId)

    if current_api_key:
        check_api_key_allows_to_validate_booking(
            current_api_key,  # type: ignore[arg-type]
            booking.offererId,
        )

    bookings_api.mark_as_unused(booking)
Esempio n. 5
0
def patch_booking_by_token(token: str):
    email = request.args.get("email", None)
    offer_id = dehumanize(request.args.get("offer_id", None))
    booking_token_upper_case = token.upper()
    booking = booking_repository.find_by(booking_token_upper_case, email,
                                         offer_id)

    if current_user.is_authenticated:
        ensure_current_user_has_rights(
            RightsType.editor, booking.stock.offer.venue.managingOffererId)
    else:
        check_email_and_offer_id_for_anonymous_user(email, offer_id)

    bookings_api.mark_as_used(booking)

    return "", 204
Esempio n. 6
0
def patch_cancel_booking_by_token(token: str):
    """Let a pro user cancel a booking."""
    valid_api_key = _get_api_key_from_header(request)
    token = token.upper()
    booking = booking_repository.find_by(token=token)
    offerer_id = booking.stock.offer.venue.managingOffererId

    if current_user.is_authenticated:
        ensure_current_user_has_rights(RightsType.editor, offerer_id)

    if valid_api_key:
        check_api_key_allows_to_cancel_booking(valid_api_key, offerer_id)

    bookings_api.cancel_booking_by_offerer(booking)

    return "", 204
Esempio n. 7
0
def get_booking_by_token(token: str):
    email = request.args.get("email", None)
    offer_id = dehumanize(request.args.get("offer_id", None))

    check_user_is_logged_in_or_email_is_provided(current_user, email)

    booking_token_upper_case = token.upper()
    booking = booking_repository.find_by(booking_token_upper_case, email,
                                         offer_id)
    bookings_validation.check_is_usable(booking)

    if check_user_can_validate_bookings(
            current_user, booking.stock.offer.venue.managingOffererId):
        response = _create_response_to_get_booking_by_token(booking)
        return jsonify(response), 200

    return "", 204
Esempio n. 8
0
def patch_booking_use_by_token(token: str) -> None:
    # in French, to be used by Swagger for the API documentation
    """Validation d'une réservation.

    Pour confirmer que la réservation a bien été utilisée par le jeune.
    """
    booking = booking_repository.find_by(token=token)

    if current_user.is_authenticated:
        check_user_can_validate_bookings_v2(current_user, booking.offererId)

    if current_api_key:
        check_api_key_allows_to_validate_booking(
            current_api_key,  # type: ignore[arg-type]
            booking.offererId,
        )

    bookings_api.mark_as_used(booking)
Esempio n. 9
0
def get_booking_by_token_v2(token: str):
    valid_api_key = _get_api_key_from_header(request)
    booking_token_upper_case = token.upper()
    booking = booking_repository.find_by(token=booking_token_upper_case)
    offerer_id = booking.stock.offer.venue.managingOffererId

    if current_user.is_authenticated:
        # warning : current user is not none when user is not logged in
        check_user_can_validate_bookings_v2(current_user, offerer_id)

    if valid_api_key:
        check_api_key_allows_to_validate_booking(valid_api_key, offerer_id)

    bookings_validation.check_is_usable(booking)

    response = serialize_booking(booking)

    return jsonify(response), 200
Esempio n. 10
0
def patch_cancel_booking_by_token(token: str) -> None:
    # in French, to be used by Swagger for the API documentation
    """Annulation d'une réservation.

    Bien que, dans le cas d’un événement, l’utilisateur ne peut plus annuler sa réservation 72h avant le début de ce dernier,
    cette API permet d’annuler la réservation d’un utilisateur si elle n’a pas encore été validé.
    """
    token = token.upper()
    booking = booking_repository.find_by(token=token)

    if current_user.is_authenticated:
        check_user_has_access_to_offerer(current_user, booking.offererId)

    if current_api_key:
        check_api_key_allows_to_cancel_booking(
            current_api_key,  # type: ignore[arg-type]
            booking.offererId,
        )

    bookings_api.cancel_booking_by_offerer(booking)
Esempio n. 11
0
def get_booking_by_token_v2(token: str) -> GetBookingResponse:
    # in French, to be used by Swagger for the API documentation
    """Consultation d'une réservation.

    Le code “contremarque” ou "token" est une chaîne de caractères permettant d’identifier la réservation et qui sert de preuve de réservation.
    Ce code unique est généré pour chaque réservation d'un utilisateur sur l'application et lui est transmis à cette occasion.
    """
    booking = booking_repository.find_by(token=token)

    if current_user.is_authenticated:
        # warning : current user is not none when user is not logged in
        check_user_can_validate_bookings_v2(current_user, booking.offererId)

    if current_api_key:
        check_api_key_allows_to_validate_booking(
            current_api_key,  # type: ignore[arg-type]
            booking.offererId,
        )

    bookings_validation.check_is_usable(booking)

    return get_booking_response(booking)