Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(cloud): constrain promotion durations and expiry hints

Timothy Yin445118aa1986
diff --git a/apps/cloud/app/pages/account/plan.vue b/apps/cloud/app/pages/account/plan.vue
index 03d485f0..77536e91 100644
--- a/apps/cloud/app/pages/account/plan.vue
+++ b/apps/cloud/app/pages/account/plan.vue
@@ -82,7 +82,10 @@ const date = (time: number) => new Date(time).toLocaleString(locale.value)
}}
</p>
<p
- v-if="data.subscription.source === 'promotion'"
+ v-if="
+ data.subscription.source === 'promotion' &&
+ data.subscription.expiresAt !== null
+ "
class="cf-field-hint"
>
{{ $t('cloud.billing.signupOffer') }}
diff --git a/packages/platform/migrations/0019_signup_promotions.sql b/packages/platform/migrations/0019_signup_promotions.sql
index 949aead0..6ced6bb9 100644
--- a/packages/platform/migrations/0019_signup_promotions.sql
+++ b/packages/platform/migrations/0019_signup_promotions.sql
@@ -10,7 +10,10 @@ CREATE TABLE platform_signup_promotions (
enabled INTEGER NOT NULL DEFAULT 1 CHECK(enabled IN(0,1)),
created_at INTEGER NOT NULL,
revision INTEGER NOT NULL DEFAULT 1,
- CHECK(starts_at IS NULL OR starts_at<ends_at)
+ CHECK(starts_at IS NULL OR starts_at<ends_at),
+ CHECK((duration_unit='permanent' AND duration_value IS NULL)
+ OR (duration_unit='days' AND duration_value IS NOT NULL AND typeof(duration_value)='integer' AND duration_value BETWEEN 1 AND 36500)
+ OR (duration_unit='months' AND duration_value IS NOT NULL AND typeof(duration_value)='integer' AND duration_value BETWEEN 1 AND 1200))
);
CREATE INDEX platform_signup_promotions_eligibility ON platform_signup_promotions(enabled,ends_at);
ALTER TABLE platform_users ADD COLUMN signup_offer TEXT;
diff --git a/tests/signup-promotions.test.ts b/tests/signup-promotions.test.ts
index d8703727..4c86fc4b 100644
--- a/tests/signup-promotions.test.ts
+++ b/tests/signup-promotions.test.ts
@@ -52,6 +52,26 @@ test('Signup promotions snapshot eligibility at actual registration, grant once
)
.bind(free.policy_json)
.run()
+ for (const [unit, value] of [
+ ['days', null],
+ ['days', 0],
+ ['days', -1],
+ ['days', 36501],
+ ['days', 1.5],
+ ['months', null],
+ ['months', 1201],
+ ['permanent', 14],
+ ]) {
+ await assert.rejects(
+ db
+ .prepare(
+ "INSERT INTO platform_signup_promotions(id,name,plan_id,ends_at,duration_unit,duration_value,created_at) VALUES('invalid','Invalid','trial',?,?,?,?)",
+ )
+ .bind(now + day, unit, value, now)
+ .run(),
+ /CHECK constraint failed/,
+ )
+ }
await db
.prepare(
"INSERT INTO platform_signup_promotions(id,name,plan_id,starts_at,ends_at,duration_unit,duration_value,priority,enabled,created_at) VALUES('before','Before cutoff','trial',NULL,?,'days',7,0,1,?),('trial14','14-day Trial','trial',?,?,'days',14,10,1,?),('off','Disabled','trial',NULL,?,'days',99,100,0,?)",