예제 #1
0
def get_booking(booking_id: int) -> Any:
    booking = (
        Booking.query.filter_by(id=dehumanize(booking_id)).options(joinedload(Booking.individualBooking)).first_or_404()
    )
    booking.userId = booking.individualBooking.userId

    return jsonify(as_dict(booking, includes=WEBAPP_GET_BOOKING_INCLUDES)), 200
예제 #2
0
def post_create_venue():
    validate_coordinates(request.json.get("latitude", None),
                         request.json.get("longitude", None))

    venue = create_venue(venue_properties=request.json, save=repository.save)

    return jsonify(as_dict(venue, includes=VENUE_INCLUDES)), 201
예제 #3
0
def is_algolia_indexing(previous_venue: Venue, payload: Dict) -> bool:
    previous_venue_as_dict = as_dict(previous_venue)
    for field in VENUE_ALGOLIA_INDEXED_FIELDS:
        if field in payload.keys(
        ) and previous_venue_as_dict[field] != payload[field]:
            return True
    return False
예제 #4
0
def signup_webapp():
    objects_to_save = []
    check_valid_signup_webapp(request)

    new_user = User(from_dict=request.json)
    new_user.email = sanitize_email(new_user.email)
    new_user.notificationSubscriptions = asdict(
        NotificationSubscriptions(marketing_email=bool(request.json.get("contact_ok")))
    )

    if settings.IS_INTEGRATION:
        objects_to_save.append(payments_api.create_deposit(new_user, "test"))
    else:
        authorized_emails, departement_codes = get_authorized_emails_and_dept_codes(ttl_hash=get_ttl_hash())
        departement_code = _get_departement_code_when_authorized_or_error(authorized_emails, departement_codes)
        new_user.departementCode = departement_code

    new_user.remove_admin_role()
    new_user.remove_beneficiary_role()
    new_user.isEmailValidated = True
    new_user.needsToFillCulturalSurvey = False
    new_user.hasSeenTutorials = True
    objects_to_save.append(new_user)

    repository.save(*objects_to_save)

    update_external_user(new_user)

    return jsonify(as_dict(new_user, includes=BENEFICIARY_INCLUDES)), 201
예제 #5
0
def signup_pro():
    objects_to_save = []
    app_origin_url = request.headers.get("origin")

    check_valid_signup_pro(request)
    new_user = User(from_dict=request.json)

    existing_offerer = Offerer.query.filter_by(siren=request.json["siren"]).first()

    if existing_offerer:
        user_offerer = _generate_user_offerer_when_existing_offerer(new_user, existing_offerer)
        offerer = existing_offerer
    else:
        offerer = _generate_offerer(request.json)
        user_offerer = offerer.give_rights(new_user, RightsType.editor)
        digital_venue = create_digital_venue(offerer)
        objects_to_save.extend([digital_venue, offerer])
    objects_to_save.append(user_offerer)
    new_user.isBeneficiary = False
    new_user.isAdmin = False
    new_user.needsToFillCulturalSurvey = False
    new_user = _set_offerer_departement_code(new_user, offerer)

    new_user.generate_validation_token()
    objects_to_save.append(new_user)

    repository.save(*objects_to_save)

    try:
        send_user_validation_email(new_user, send_raw_email, app_origin_url, is_webapp=False)
        subscribe_newsletter(new_user)
    except MailServiceException:
        logger.exception("Mail service failure")

    return jsonify(as_dict(new_user, includes=USER_INCLUDES)), 201
예제 #6
0
def get_user_offerer(offerer_id):
    user_offerers = UserOfferer.query.filter_by(
        user=current_user, offererId=dehumanize(offerer_id)).all()
    return jsonify([
        as_dict(user_offerer, includes=USER_OFFERER_INCLUDES)
        for user_offerer in user_offerers
    ]), 200
예제 #7
0
def get_offerer_helper(offerer):
    return dict(
        as_dict(offerer),
        **{
            "latitude": "48.9281995",
            "longitude": "2.4579903",
        },
    )
예제 #8
0
def get_booking_helper(booking):
    return dict(
        as_dict(booking),
        **{
            "eventOrThingName": booking.stock.offer.product.name,
            "venueName": booking.venue.name,
        },
    )
예제 #9
0
def delete_favorite(offer_id):
    dehumanized_offer_id = dehumanize(offer_id)

    favorite = find_favorite_for_offer_and_user(dehumanized_offer_id, current_user.id).first_or_404()

    repository.delete(favorite)

    return jsonify(as_dict(favorite)), 200
예제 #10
0
    def test_returns_humanized_ids_for_primary_keys(self, app):
        # given
        user = create_user(idx=12, postal_code=None)

        # when
        dict_result = as_dict(user, includes=[])

        # then
        assert dict_result["id"] == "BQ"
    def test_returns_humanized_ids_for_primary_keys(self, app):
        # given
        user = users_factories.UserFactory.build(id=12, postalCode=None)

        # when
        dict_result = as_dict(user, includes=[])

        # then
        assert dict_result["id"] == "BQ"
예제 #12
0
def get_beneficiary_helper(user):
    return dict(
        as_dict(user, includes=BENEFICIARY_INCLUDES),
        **{
            "resetPasswordToken": _get_reset_password_token(user),
            "password": users_factories.DEFAULT_PASSWORD,
            "validationToken": user.validationToken,
        },
    )
예제 #13
0
def list_providers():
    providers = get_enabled_providers_for_pro()
    result = []
    for provider in providers:
        p_dict = as_dict(provider)
        del p_dict["apiKey"]
        del p_dict["apiKeyGenerationDate"]
        result.append(p_dict)
    return jsonify(result)
예제 #14
0
def get_offer_helper(offer):
    return dict(
        as_dict(offer),
        **{
            "venueCity": offer.venue.city,
            "venueName": offer.venue.name,
            "thingName": offer.product.name,
            "status": offer.status.name,
        },
    )
예제 #15
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
    def test_returns_humanized_ids_for_foreign_keys(self, app):
        # given
        user = users_factories.BeneficiaryGrant18Factory(id=12)
        individual_booking = booking_factories.IndividualBookingFactory(
            individualBooking__user=user).individualBooking

        # when
        dict_result = as_dict(individual_booking, includes=[])

        # then
        assert dict_result["userId"] == "BQ"
예제 #17
0
def activate_venue_offers(venue_id):
    venue = load_or_404(Venue, venue_id)
    check_user_has_access_to_offerer(current_user, venue.managingOffererId)
    offers = venue.offers
    activated_offers = update_is_active_status(offers, True)
    repository.save(*activated_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 activated_offers
    ]), 200
예제 #18
0
    def test_returns_humanized_ids_for_foreign_keys(self, app):
        # given
        user = create_user(idx=12, postal_code=None)
        booking = create_booking(user=user, stock=Stock(), idx=13)
        booking.userId = user.id

        # when
        dict_result = as_dict(booking, includes=[])

        # then
        assert dict_result["userId"] == "BQ"
    def test_does_not_return_excluded_keys(self, app):
        # given
        user = users_factories.UserFactory.build(postalCode=None)
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer)
        repository.save(user_offerer)
        USER_INCLUDES = ["-password"]

        # when
        dict_result = as_dict(user, includes=USER_INCLUDES)

        # then
        assert "password" not in dict_result
    def test_returns_included_properties(self, app):
        # given
        user = users_factories.UserFactory.build(postalCode=None)
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer)
        repository.save(user_offerer)
        USER_INCLUDES = ["hasPhysicalVenues"]

        # when
        dict_result = as_dict(user, includes=USER_INCLUDES)

        # then
        assert "hasPhysicalVenues" in dict_result
예제 #21
0
def list_venue_providers():
    venue_id = request.args.get("venueId")
    if venue_id is None:
        e = ApiErrors()
        e.add_error("venueId",
                    "Vous devez obligatoirement fournir le paramètre venueId")
        return jsonify(e.errors), 400

    vp_query = VenueProvider.query.filter_by(venueId=dehumanize(venue_id))
    return jsonify([
        as_dict(venue_provider, includes=VENUE_PROVIDER_INCLUDES)
        for venue_provider in vp_query.all()
    ])
예제 #22
0
def edit_venue(venue_id: str, body: EditVenueBodyModel) -> GetVenueResponseModel:
    venue = load_or_404(Venue, venue_id)

    check_user_has_access_to_offerer(current_user, venue.managingOffererId)
    not_venue_fields = {
        "isAccessibilityAppliedOnAllOffers",
        "isEmailAppliedOnAllOffers",
        "isWithdrawalAppliedOnAllOffers",
        "contact",
    }
    update_venue_attrs = body.dict(exclude=not_venue_fields, exclude_unset=True)
    venue_attrs = as_dict(venue)
    accessibility_fields = [
        "audioDisabilityCompliant",
        "mentalDisabilityCompliant",
        "motorDisabilityCompliant",
        "visualDisabilityCompliant",
    ]
    have_accessibility_changes = any(
        (field in update_venue_attrs and update_venue_attrs[field] != venue_attrs[field])
        for field in accessibility_fields
    )
    have_withdrawal_details_changes = body.withdrawalDetails != venue.withdrawalDetails
    venue = offerers_api.update_venue(venue, body.contact, **update_venue_attrs)
    venue_attrs = as_dict(venue)

    if have_accessibility_changes and body.isAccessibilityAppliedOnAllOffers:
        edited_accessibility = {field: venue_attrs[field] for field in accessibility_fields}
        update_all_venue_offers_accessibility_job.delay(venue, edited_accessibility)

    if FeatureToggle.ENABLE_VENUE_WITHDRAWAL_DETAILS.is_active():
        if have_withdrawal_details_changes and body.isWithdrawalAppliedOnAllOffers:
            update_all_venue_offers_withdrawal_details_job.delay(venue, body.withdrawalDetails)

    if body.bookingEmail and body.isEmailAppliedOnAllOffers:
        update_all_venue_offers_email_job.delay(venue, body.bookingEmail)

    return GetVenueResponseModel.from_orm(venue)
예제 #23
0
    def test_does_not_return_excluded_keys(self, app):
        # given
        user = create_user(postal_code=None)
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer)
        repository.save(user_offerer)
        USER_INCLUDES = ["-password", "-resetPasswordToken"]

        # when
        dict_result = as_dict(user, includes=USER_INCLUDES)

        # then
        assert "password" not in dict_result
        assert "resetPasswordToken" not in dict_result
예제 #24
0
    def test_does_not_return_properties_by_default(self, app):
        # given
        user = create_user(postal_code=None)
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer)
        repository.save(user_offerer)
        USER_INCLUDES = []

        # when
        dict_result = as_dict(user, includes=USER_INCLUDES)

        # then
        assert "hasPhysicalVenues" not in dict_result
        assert "hasOffers" not in dict_result
예제 #25
0
    def test_returns_model_keys(self, app):
        # given
        user = create_user(postal_code=None)
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer)
        repository.save(user_offerer)
        USER_INCLUDES = []

        # when
        dict_result = as_dict(user, includes=USER_INCLUDES)

        # then
        assert "publicName" in dict_result
        assert "lastName" in dict_result
        assert "firstName" in dict_result
예제 #26
0
    def test_returns_included_properties_on_joined_relationships(self, app):
        # given
        offerer = create_offerer()
        venue = create_venue(offerer)
        event_product = create_product_with_event_type(event_name="My Event")
        offer = create_offer_with_event_product(venue, product=event_product)
        mediation = create_mediation(offer)
        repository.save(mediation)
        EVENT_INCLUDES = [{"key": "mediations", "includes": ["thumbUrl"]}]

        # when
        dict_result = as_dict(offer, includes=EVENT_INCLUDES)

        # then
        assert "thumbUrl" in dict_result["mediations"][0]
예제 #27
0
    def test_returns_model_keys_on_joined_relationships(self, app):
        # given
        user = create_user()
        offerer = create_offerer()
        user_offerer = create_user_offerer(user, offerer)
        repository.save(user_offerer)
        USER_INCLUDES = ["offerers"]

        # when
        dict_result = as_dict(user, includes=USER_INCLUDES)

        # then
        assert "offerers" in dict_result
        assert "name" in dict_result["offerers"][0]
        assert "siren" in dict_result["offerers"][0]
예제 #28
0
def get_providers_by_venue(venue_id: str):
    venue = load_or_404(VenueSQLEntity, venue_id)
    has_allocine_pivot = has_allocine_pivot_for_venue(venue)
    if has_allocine_pivot:
        providers = get_enabled_providers_for_pro()
    else:
        allocine_local_class = AllocineStocks.__name__
        providers = get_providers_enabled_for_pro_excluding_specific_provider(
            allocine_local_class)
    result = []
    for provider in providers:
        provider_dict = as_dict(provider)
        del provider_dict["apiKey"]
        del provider_dict["apiKeyGenerationDate"]
        result.append(provider_dict)
    return jsonify(result)
    def test_does_not_return_excluded_keys_on_joined_relationships(self, app):
        # given
        offerer = create_offerer()
        venue = create_venue(offerer)
        event_product = create_product_with_event_subcategory(
            event_name="My Event")
        offer = create_offer_with_event_product(venue, product=event_product)
        mediation = create_mediation(offer)
        repository.save(mediation)
        EVENT_INCLUDES = [{"key": "mediations", "includes": ["-isActive"]}]

        # when
        dict_result = as_dict(offer, includes=EVENT_INCLUDES)

        # then
        assert "isActive" not in dict_result["mediations"][0]
예제 #30
0
def get_providers_by_venue(venue_id: str):
    venue = load_or_404(Venue, venue_id)
    has_allocine_pivot = has_allocine_pivot_for_venue(venue)
    if has_allocine_pivot:
        providers = get_enabled_providers_for_pro()
    else:
        allocine_local_class = AllocineStocks.__name__
        providers = get_providers_enabled_for_pro_excluding_specific_provider(
            allocine_local_class)
    result = []
    for provider in providers:
        provider_dict = as_dict(provider)
        del provider_dict["apiUrl"]
        del provider_dict["authToken"]
        del provider_dict["pricesInCents"]
        result.append(provider_dict)
    return jsonify(result)