Skip to content

Commit

Permalink
(PC-33115)[API] feat: Googl image sync and has banner url based on is…
Browse files Browse the repository at this point in the history
…OpenToPublic instead of isPermanent attribut
  • Loading branch information
pcharlet-pass authored and ogeber-pass committed Dec 13, 2024
1 parent 18a8ac7 commit 972a80f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
6 changes: 5 additions & 1 deletion api/src/pcapi/core/external/attributes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ def get_pro_attributes(email: str) -> models.ProAttributes:

has_individual_offers = offerers_repository.venues_have_offers(*venues)

if FeatureToggle.WIP_IS_OPEN_TO_PUBLIC.is_active():
has_banner_url = all(venue._bannerUrl for venue in venues if venue.isOpenToPublic)
else:
has_banner_url = all(venue._bannerUrl for venue in venues if venue.isPermanent)
attributes.update(
{
"dms_application_submitted": any(venue.hasPendingBankAccountApplication for venue in venues),
Expand All @@ -325,7 +329,7 @@ def get_pro_attributes(email: str) -> models.ProAttributes:
"has_offers": has_individual_offers or has_collective_offers,
"has_individual_offers": has_individual_offers,
"has_bookings": bookings_repository.venues_have_bookings(*venues),
"has_banner_url": all(venue._bannerUrl for venue in venues if venue.isPermanent),
"has_banner_url": has_banner_url,
}
)

Expand Down
2 changes: 1 addition & 1 deletion api/src/pcapi/core/external/attributes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ProAttributes:
has_individual_offers: bool | None = None # At least one venue has at least one active offer
has_offers: bool | None = None # has_collective_offers or has_individual_offers
has_banner_url: bool | None = (
None # Set to False when at least one permanent venue doesn't have a banner URL, True otherwise
None # Set to False when at least one venue, open to public if FF IS_OPEN_TO_PUBLIC is activated, permanent if not, doesn't have a banner URL, True otherwise
)
is_eac_meg: bool | None = None # At least one collective offer with 'Marseille en Grand'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pcapi.core.search import IndexationReason
from pcapi.core.search import async_index_venue_ids
from pcapi.models import db
from pcapi.models.feature import FeatureToggle
from pcapi.utils import image_conversion


Expand Down Expand Up @@ -55,17 +56,30 @@ def get_venues_without_photo(frequency: int) -> list[offerers_models.Venue]:
# x % SHORTEST_MONTH_LENGTH is always < SHORTEST_MONTH_LENGTH
return []

query = (
offerers_models.Venue.query.join(offerers_models.Offerer)
.filter(
offerers_models.Venue.isPermanent.is_(True),
offerers_models.Venue.bannerUrl.is_(None), # type: ignore[attr-defined]
offerers_models.Venue.venueTypeCode != "Lieu administratif",
offerers_models.Offerer.isActive.is_(True),
offerers_models.Venue.id % (SHORTEST_MONTH_LENGTH // frequency) == (day - 1) // frequency,
if FeatureToggle.WIP_IS_OPEN_TO_PUBLIC.is_active():
query = (
offerers_models.Venue.query.join(offerers_models.Offerer)
.filter(
offerers_models.Venue.isOpenToPublic.is_(True),
offerers_models.Venue.bannerUrl.is_(None), # type: ignore[attr-defined]
offerers_models.Venue.venueTypeCode != "Lieu administratif",
offerers_models.Offerer.isActive.is_(True),
offerers_models.Venue.id % (SHORTEST_MONTH_LENGTH // frequency) == (day - 1) // frequency,
)
.order_by(offerers_models.Venue.id)
)
else:
query = (
offerers_models.Venue.query.join(offerers_models.Offerer)
.filter(
offerers_models.Venue.isPermanent.is_(True),
offerers_models.Venue.bannerUrl.is_(None), # type: ignore[attr-defined]
offerers_models.Venue.venueTypeCode != "Lieu administratif",
offerers_models.Offerer.isActive.is_(True),
offerers_models.Venue.id % (SHORTEST_MONTH_LENGTH // frequency) == (day - 1) // frequency,
)
.order_by(offerers_models.Venue.id)
)
.order_by(offerers_models.Venue.id)
)
return query.all()


Expand Down
2 changes: 2 additions & 0 deletions api/src/pcapi/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class FeatureToggle(enum.Enum):
WIP_ENABLE_CHRONICLES_IN_BO = "Activer les chroniques du Book Club dans le BO"
WIP_ENABLE_CLICKHOUSE_IN_BO = "Utiliser Clickhouse pour les statistiques des acteurs culturels dans le BO"
WIP_HEADLINE_OFFER = "Activer l'offre à la une"
WIP_IS_OPEN_TO_PUBLIC = "Activer l'utilisation du critère 'ouvert au public' pour les synchro"

def is_active(self) -> bool:
if flask.has_request_context():
Expand Down Expand Up @@ -216,6 +217,7 @@ def nameKey(self) -> str:
FeatureToggle.WIP_ENABLE_PRO_ONBOARDING,
FeatureToggle.WIP_ENABLE_REMINDER_MARKETING_MAIL_METADATA_DISPLAY,
FeatureToggle.WIP_HEADLINE_OFFER,
FeatureToggle.WIP_IS_OPEN_TO_PUBLIC,
FeatureToggle.WIP_OFFERER_STATS_V2,
FeatureToggle.WIP_SUGGESTED_SUBCATEGORIES,
FeatureToggle.WIP_UBBLE_V2,
Expand Down
19 changes: 13 additions & 6 deletions api/tests/core/external/external_pro_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
# 2 extra SQL queries: select exists on offer and booking tables
# 1 extra query to check if the venue has any related collective offer with 'marseille en grand'
# 1 check if the venue is concerned with marseille_en_grand
EXPECTED_PRO_ATTR_NUM_QUERIES = 6
# 1 check if FF WIP_IS_OPEN_TO_PUBLIC is active
EXPECTED_PRO_ATTR_NUM_QUERIES = 7


def _build_params(subs, virt, perman, draft, accep, offer, book, attach, colloff, tploff, megoff):
Expand Down Expand Up @@ -333,7 +334,8 @@ def _check_user_without_validated_offerer(user):
email = user.email

# no booking or offer to check without offerer
with assert_num_queries(EXPECTED_PRO_ATTR_NUM_QUERIES - 2):
# no check for FF WIP_IS_OPEN_TO_PUBLIC
with assert_num_queries(EXPECTED_PRO_ATTR_NUM_QUERIES - 3):
attributes = get_pro_attributes(email)

assert attributes.is_pro is True
Expand Down Expand Up @@ -375,10 +377,12 @@ def test_update_external_pro_booking_email_attributes():
bookingEmail=email,
siret="12345678900001",
isPermanent=True,
isOpenToPublic=True,
venueTypeCode=VenueTypeCode.MUSEUM,
)

with assert_num_queries(5):
# 1 check if FF WIP_IS_OPEN_TO_PUBLIC is active
with assert_num_queries(6):
attributes = get_pro_attributes(email)

assert attributes.is_pro is True
Expand Down Expand Up @@ -424,7 +428,8 @@ def test_update_external_pro_booking_email_attributes_for_permanent_venue_with_b
_bannerUrl="https://example.net/banner.jpg",
)

with assert_num_queries(5):
# 1 check if FF WIP_IS_OPEN_TO_PUBLIC is active
with assert_num_queries(6):
attributes = get_pro_attributes(email)
assert attributes.isPermanent is True
assert attributes.has_banner_url is True
Expand All @@ -445,7 +450,8 @@ def test_update_external_pro_booking_email_attributes_for_non_permanent_venue_wi
_bannerUrl="https://example.net/banner.jpg",
)

with assert_num_queries(5):
# 1 check if FF WIP_IS_OPEN_TO_PUBLIC is active
with assert_num_queries(6):
attributes = get_pro_attributes(email)
assert attributes.isPermanent is False
assert attributes.has_banner_url is True
Expand All @@ -465,7 +471,8 @@ def test_update_external_pro_booking_email_attributes_for_non_permanent_venue_wi
venueTypeCode=VenueTypeCode.MUSEUM,
)

with assert_num_queries(5):
# 1 check if FF WIP_IS_OPEN_TO_PUBLIC is active
with assert_num_queries(6):
attributes = get_pro_attributes(email)
assert attributes.isPermanent is False
assert attributes.has_banner_url is True
Expand Down

0 comments on commit 972a80f

Please sign in to comment.