diff --git a/make_post_sell/lib/digest_sender.py b/make_post_sell/lib/digest_sender.py index e6804f0..8cb5c80 100644 --- a/make_post_sell/lib/digest_sender.py +++ b/make_post_sell/lib/digest_sender.py @@ -122,6 +122,7 @@ def run(env, frequency_str, dry_run=False): shops = ( dbsession.query(Shop) .filter(Shop.subscriptions_enabled == True) + .filter(Shop.environment == 0) # MPS-14: exclude non-production shops .all() ) diff --git a/make_post_sell/lib/karaoke.py b/make_post_sell/lib/karaoke.py index d861c2d..9cafc4e 100644 --- a/make_post_sell/lib/karaoke.py +++ b/make_post_sell/lib/karaoke.py @@ -362,6 +362,15 @@ def backfill_karaoke_async(shop_id, session_factory, app_settings): session = SASession(bind=engine) def _make_s3(): + # BYOB: use shop's own bucket if configured (MPS-16) + if shop and shop.has_primary_s3: + return boto3.session.Session().client( + "s3", + region_name=shop.primary_s3_region, + endpoint_url=shop.primary_s3_endpoint, + aws_access_key_id=shop.primary_s3_access_key, + aws_secret_access_key=shop.primary_s3_secret_key, + ) return boto3.session.Session().client( "s3", region_name=app_settings["bucket.secure_uploads.region"], @@ -370,14 +379,15 @@ def backfill_karaoke_async(shop_id, session_factory, app_settings): aws_secret_access_key=app_settings["bucket.secure_uploads.secret_key"], ) - s3 = _make_s3() - bucket = app_settings["bucket.secure_uploads"] - try: + # Must load shop before _make_s3 can check has_primary_s3 shop = session.get(Shop, shop_id) if not shop or not shop.unsandbox_public_key or not shop.unsandbox_secret_key: return + s3 = _make_s3() + bucket = shop.primary_s3_bucket if shop.has_primary_s3 else app_settings["bucket.secure_uploads"] + pk, sk = shop.unsandbox_public_key, shop.unsandbox_secret_key # Query account concurrency from unsandbox API — abort if keys are bad diff --git a/make_post_sell/lib/s3_mirror.py b/make_post_sell/lib/s3_mirror.py index ddd0729..343a0e7 100644 --- a/make_post_sell/lib/s3_mirror.py +++ b/make_post_sell/lib/s3_mirror.py @@ -229,7 +229,16 @@ def backfill_mirror_async(shop_id, session_factory, app_settings): engine = create_engine(db_url) session = SASession(bind=engine) - def _make_src(): + def _make_src(shop): + # BYOB: if shop has its own primary bucket, mirror from there (MPS-16) + if shop and shop.has_primary_s3: + return boto3.session.Session().client( + "s3", + region_name=shop.primary_s3_region, + endpoint_url=shop.primary_s3_endpoint, + aws_access_key_id=shop.primary_s3_access_key, + aws_secret_access_key=shop.primary_s3_secret_key, + ) return boto3.session.Session().client( "s3", region_name=app_settings["bucket.secure_uploads.region"], @@ -243,14 +252,14 @@ def backfill_mirror_async(shop_id, session_factory, app_settings): if not shop or not shop.has_s3_mirror: return - src = _make_src() + src = _make_src(shop) dst = _make_mirror_client( shop.mirror_s3_endpoint, shop.mirror_s3_region, shop.mirror_s3_access_key, shop.mirror_s3_secret_key, ) - src_bucket = app_settings["bucket.secure_uploads"] + src_bucket = shop.primary_s3_bucket if shop.has_primary_s3 else app_settings["bucket.secure_uploads"] dst_bucket = shop.mirror_s3_bucket # List all objects under the shop's prefix diff --git a/make_post_sell/models/product.py b/make_post_sell/models/product.py index 3fe1fc4..ca98ecc 100644 --- a/make_post_sell/models/product.py +++ b/make_post_sell/models/product.py @@ -677,9 +677,12 @@ def get_products_by_keywords(dbsession, keywords, shop=None): for keyword in keywords: keyword_filter = Product.title.ilike(f"%{keyword}%") # the product _must_ be public (1). - products = ( - product_query.filter(keyword_filter).filter(Product.visibility == 1).all() - ) + query = product_query.filter(keyword_filter).filter(Product.visibility == 1) + # Exclude non-production shops from search results (MPS-14) + if not shop: + from .shop import Shop + query = query.join(Shop, Product.shop_id == Shop.id).filter(Shop.environment == 0) + products = query.all() for product in products: if product.id not in scores: diff --git a/make_post_sell/templates/shop_settings.j2 b/make_post_sell/templates/shop_settings.j2 index 3e5c136..797bf8c 100644 --- a/make_post_sell/templates/shop_settings.j2 +++ b/make_post_sell/templates/shop_settings.j2 @@ -1212,6 +1212,10 @@ Existing sales honored for download buy purchasers.
Configure your own S3-compatible storage bucket. When enabled, all media uploads and CDN URLs will use your bucket instead of the default MPS storage.
+ {% if request.shop.is_trial_active %} +Trial tip: Setting up your own storage bucket during your trial ensures your media is always under your control. Any S3-compatible provider works (DigitalOcean Spaces, AWS S3, Backblaze B2, etc.).
+ {% endif %} +