Esempio n. 1
0
def patch_offer(offer_id: str,
                body: PatchOfferBodyModel) -> OfferResponseIdModel:
    offer = load_or_404(Offer, human_id=offer_id)
    ensure_current_user_has_rights(RightsType.editor,
                                   offer.venue.managingOffererId)

    offer = offers_api.update_offer(offer, **body.dict(exclude_unset=True))

    return OfferResponseIdModel.from_orm(offer)
Esempio n. 2
0
def deactivate_venue_offers(venue_id):
    venue = load_or_404(VenueSQLEntity, venue_id)
    ensure_current_user_has_rights(RightsType.editor, venue.managingOffererId)
    offers = venue.offers
    deactivated_offers = update_is_active_status(offers, False)
    repository.save(*deactivated_offers)
    if feature_queries.is_active(FeatureToggle.SYNCHRONIZE_ALGOLIA):
        redis.add_venue_id(client=app.redis_client, venue_id=venue.id)
    return jsonify([
        as_dict(offer, includes=OFFER_INCLUDES) for offer in deactivated_offers
    ]), 200
Esempio n. 3
0
def delete_stock(stock_id: str) -> StockResponseIdModel:
    # fmt: off
    stock = (Stock.queryNotSoftDeleted().filter_by(
        id=dehumanize(stock_id)).join(Offer, VenueSQLEntity).first_or_404())
    # fmt: on

    offerer_id = stock.offer.venue.managingOffererId
    ensure_current_user_has_rights(RightsType.editor, offerer_id)

    offers_api.delete_stock(stock)

    return StockResponseIdModel.from_orm(stock)
Esempio n. 4
0
def update_mediation(
        mediation_id: str,
        body: UpdateMediationBodyModel) -> UpdateMediationResponseModel:

    mediation = Mediation.query.filter_by(
        id=dehumanize(mediation_id)).first_or_404()

    ensure_current_user_has_rights(RightsType.editor,
                                   mediation.offer.venue.managingOffererId)

    mediation = offers_api.update_mediation(mediation=mediation,
                                            is_active=body.isActive)

    return UpdateMediationResponseModel.from_orm(mediation)
Esempio n. 5
0
def create_stock(body: StockCreationBodyModel) -> StockResponseIdModel:
    offerer = offerer_queries.get_by_offer_id(body.offer_id)
    ensure_current_user_has_rights(RightsType.editor, offerer.id)

    offer = get_offer_by_id(body.offer_id)

    stock = offers_api.create_stock(
        offer=offer,
        price=body.price,
        quantity=body.quantity,
        beginning=body.beginning_datetime,
        booking_limit_datetime=body.booking_limit_datetime,
    )

    return StockResponseIdModel.from_orm(stock)
Esempio n. 6
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. 7
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. 8
0
def create_mediation(
        form: CreateMediationBodyModel) -> MediationResponseIdModel:
    ensure_current_user_has_rights(RightsType.editor, form.offerer_id)

    offer = get_offer_by_id(form.offer_id)
    image_as_bytes = form.get_image_as_bytes(request)

    mediation = offers_api.create_mediation(
        user=current_user,
        offer=offer,
        credit=form.credit,
        image_as_bytes=image_as_bytes,
        crop_params=form.crop_params,
    )

    return MediationResponseIdModel.from_orm(mediation)
Esempio n. 9
0
def edit_stock(stock_id: str,
               body: StockEditionBodyModel) -> StockResponseIdModel:
    stock = Stock.queryNotSoftDeleted().filter_by(
        id=dehumanize(stock_id)).join(Offer, VenueSQLEntity).first_or_404()

    offerer_id = stock.offer.venue.managingOffererId
    ensure_current_user_has_rights(RightsType.editor, offerer_id)

    stock = offers_api.edit_stock(
        stock,
        price=body.price,
        quantity=body.quantity,
        beginning=body.beginning_datetime,
        booking_limit_datetime=body.booking_limit_datetime,
    )

    return StockResponseIdModel.from_orm(stock)
Esempio n. 10
0
def edit_venue(venue_id):
    venue = load_or_404(VenueSQLEntity, venue_id)
    previous_venue = copy.deepcopy(venue)
    check_valid_edition(request, venue)
    validate_coordinates(request.json.get("latitude", None),
                         request.json.get("longitude", None))
    ensure_current_user_has_rights(RightsType.editor, venue.managingOffererId)
    venue.populate_from_dict(request.json)

    if not venue.isVirtual:
        delete_venue_from_iris_venues(venue.id)

    repository.save(venue)
    link_valid_venue_to_irises(venue)

    if is_algolia_indexing(previous_venue, request.json):
        if feature_queries.is_active(FeatureToggle.SYNCHRONIZE_ALGOLIA):
            redis.add_venue_id(client=app.redis_client,
                               venue_id=dehumanize(venue_id))

    return jsonify(as_dict(venue, includes=VENUE_INCLUDES)), 200
Esempio n. 11
0
def create_offer(offer_data: PostOfferBodyModel, user: User) -> models.Offer:
    venue = load_or_raise_error(VenueSQLEntity, offer_data.venue_id)

    ensure_current_user_has_rights(rights=RightsType.editor, offerer_id=venue.managingOffererId, user=user)

    if offer_data.product_id:
        product = load_or_raise_error(Product, offer_data.product_id)
        offer = models.Offer(
            product=product,
            type=product.type,
            name=product.name,
            description=product.description,
            url=product.url,
            mediaUrls=product.mediaUrls,
            conditions=product.conditions,
            ageMin=product.ageMin,
            ageMax=product.ageMax,
            durationMinutes=product.durationMinutes,
            isNational=product.isNational,
            extraData=product.extraData,
        )
    else:
        if offer_data.type == str(EventType.ACTIVATION):
            validation.check_user_can_create_activation_event(user)
        data = offer_data.dict(by_alias=True)
        product = Product()
        if data.get("url"):
            data["isNational"] = True
        product.populate_from_dict(data)
        offer = Offer()
        offer.populate_from_dict(data)
        offer.product = product
        offer.product.owningOfferer = venue.managingOfferer

    offer.venue = venue
    offer.bookingEmail = offer_data.booking_email
    repository.save(offer)
    admin_emails.send_offer_creation_notification_to_administration(offer, user, mailing.send_raw_email)

    return offer
Esempio n. 12
0
def get_venue(venue_id):
    venue = load_or_404(VenueSQLEntity, venue_id)
    ensure_current_user_has_rights(RightsType.editor, venue.managingOffererId)
    return jsonify(as_dict(venue, includes=VENUE_INCLUDES)), 200
Esempio n. 13
0
def get_offerer(offerer_id):
    ensure_current_user_has_rights(RightsType.editor, dehumanize(offerer_id))
    offerer = load_or_404(Offerer, offerer_id)

    return jsonify(get_dict_offerer(offerer)), 200