Main #28

Merged
sagifer merged 2 commits from main into prod 2026-11-20 08:01:13 +01:00
13 changed files with 76 additions and 11 deletions
Showing only changes of commit d9e71ed349 - Show all commits
+3
View File
@@ -88,6 +88,9 @@ services:
# Without the Stripe keys purchases are off; packages come from promo # Without the Stripe keys purchases are off; packages come from promo
# codes and admins (MOCK_PAYMENTS=true: pretend purchases). # codes and admins (MOCK_PAYMENTS=true: pretend purchases).
MOCK_PAYMENTS: ${MOCK_PAYMENTS:-false} MOCK_PAYMENTS: ${MOCK_PAYMENTS:-false}
# Stripe purchases for everyone (false: admins only, until the opening;
# with a test key always admins only).
PURCHASES_OPEN: ${PURCHASES_OPEN:-false}
# Users inviting others ("Meghívom"): shown but off until the launch. # Users inviting others ("Meghívom"): shown but off until the launch.
USER_INVITES: ${USER_INVITES:-false} USER_INVITES: ${USER_INVITES:-false}
# A new user from a shared link earns the sharer an analysis: off until sign-up opens. # A new user from a shared link earns the sharer an analysis: off until sign-up opens.
+3
View File
@@ -55,6 +55,9 @@ services:
PASSWORD_LOGIN: ${PASSWORD_LOGIN:-false} PASSWORD_LOGIN: ${PASSWORD_LOGIN:-false}
# Stand-in payment (adds an analysis unit at once) until Stripe is connected. # Stand-in payment (adds an analysis unit at once) until Stripe is connected.
MOCK_PAYMENTS: ${MOCK_PAYMENTS:-true} MOCK_PAYMENTS: ${MOCK_PAYMENTS:-true}
# Stripe purchases for everyone (false: admins only, until the opening;
# with a test key always admins only).
PURCHASES_OPEN: ${PURCHASES_OPEN:-false}
FREE_PERSON_SLOTS: ${FREE_PERSON_SLOTS:-0} FREE_PERSON_SLOTS: ${FREE_PERSON_SLOTS:-0}
# invite: new accounts need an invitation (admin page "Meghívók"); open: anyone. # invite: new accounts need an invitation (admin page "Meghívók"); open: anyone.
SIGNUP_MODE: ${SIGNUP_MODE:-invite} SIGNUP_MODE: ${SIGNUP_MODE:-invite}
+21
View File
@@ -0,0 +1,21 @@
# Arculat
- `sorsfonalak-ikon-512.png`: négyzetes ikon (512×512, sötét háttér, teljes kitöltés).
- `sorsfonalak-logo-sotet-hatterre.png`: logó átlátszó háttérrel, sötét felületre (1200×300).
- `sorsfonalak-logo-vilagos-hatterre.png`: ugyanez világos felületre.
A jel forrása: `services/frontend/src/app/icon.svg`.
## Színek
| Szerep | Szín |
|---|---|
| Háttér | `#0d1220` |
| Panel | `#111729` |
| Arany (kiemelés, gombok) | `#d9b46a` |
| Arany, világos háttéren | `#a7802f` |
| Szöveg sötét háttéren | `#ece6d8` |
| Szöveg világos háttéren | `#1b2236` |
| Gomb felirata arany gombon | `#141a2c` |
Stripe (Settings → Branding): Brand color `#0d1220`, Accent color `#d9b46a`, ikon és a sötét háttérre szánt logó.
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

+3 -2
View File
@@ -22,8 +22,9 @@ STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_... STRIPE_WEBHOOK_SECRET=whsec_...
``` ```
- **Teszt kulccsal (`sk_test_…`) csak az adminok vásárolhatnak**, a többieknek a gombok „Hamarosan” feliratúak maradnak; így senki nem jut csomaghoz a Stripe tesztkártyáival. Tesztkártya: `4242 4242 4242 4242`, bármilyen jövőbeli lejárat és CVC. - **A megnyitásig csak az adminok vásárolhatnak** (`PURCHASES_OPEN=false`, az alapértelmezés), a többieknek a gombok „Hamarosan” feliratúak; így senki nem ad meg valódi kártyát egy teszt- vagy félkész beállításnál.
- Élő kulccsal (`sk_live_…`) mindenki vásárolhat. - Teszt kulccsal (`sk_test_…`) `PURCHASES_OPEN=true` mellett is csak adminok vásárolhatnak (a Stripe tesztkártyáival senki nem jut csomaghoz). Tesztkártya: `4242 4242 4242 4242`, bármilyen jövőbeli lejárat és CVC.
- Élő kulccsal és `PURCHASES_OPEN=true` mellett mindenki vásárolhat (megnyitáskor, a `.env`-ben).
- Kulcs nélkül nincs vásárlás (helyben a `MOCK_PAYMENTS=true` próbafizetés működik; a Stripe-kulcs ezt felülírja). - Kulcs nélkül nincs vásárlás (helyben a `MOCK_PAYMENTS=true` próbafizetés működik; a Stripe-kulcs ezt felülírja).
A Stripe felületén: A Stripe felületén:
+7 -1
View File
@@ -46,8 +46,12 @@ pub struct Config {
/// analysis unit at once, until Stripe is connected. /// analysis unit at once, until Stripe is connected.
pub mock_payments: bool, pub mock_payments: bool,
/// Stripe Checkout, when `STRIPE_SECRET_KEY` is set (it wins over /// Stripe Checkout, when `STRIPE_SECRET_KEY` is set (it wins over
/// `MOCK_PAYMENTS`). With a test key only admins can buy. /// `MOCK_PAYMENTS`).
pub stripe: Option<StripeConfig>, pub stripe: Option<StripeConfig>,
/// `PURCHASES_OPEN` (default `false`): everyone may buy through Stripe.
/// Until the opening only admins can (and with a test key always only
/// admins), so nobody types a real card into a test or unfinished setup.
pub purchases_open: bool,
/// `USER_INVITES` (default `false`): users may invite others ("how /// `USER_INVITES` (default `false`): users may invite others ("how
/// compatible are we?" links, which also let the invitee sign up). Off /// compatible are we?" links, which also let the invitee sign up). Off
/// until the launch; admins may always. /// until the launch; admins may always.
@@ -166,6 +170,7 @@ impl Config {
.trim_end_matches('/') .trim_end_matches('/')
.to_string(), .to_string(),
}), }),
purchases_open: parsed("PURCHASES_OPEN", false)?,
user_invites: parsed("USER_INVITES", false)?, user_invites: parsed("USER_INVITES", false)?,
referral_rewards: parsed("REFERRAL_REWARDS", false)?, referral_rewards: parsed("REFERRAL_REWARDS", false)?,
google_client_ids: list("GOOGLE_CLIENT_IDS"), google_client_ids: list("GOOGLE_CLIENT_IDS"),
@@ -206,6 +211,7 @@ impl Config {
password_login: true, password_login: true,
mock_payments: true, mock_payments: true,
stripe: None, stripe: None,
purchases_open: true,
user_invites: true, user_invites: true,
referral_rewards: true, referral_rewards: true,
google_client_ids: vec!["test-client.apps.googleusercontent.com".into()], google_client_ids: vec!["test-client.apps.googleusercontent.com".into()],
+3 -1
View File
@@ -165,8 +165,10 @@ async fn public_config(State(state): St) -> Json<Value> {
"locales": c.supported_locales, "locales": c.supported_locales,
"password_login": c.password_login, "password_login": c.password_login,
"mock_payments": payments::method(c) == Some("mock"), "mock_payments": payments::method(c) == Some("mock"),
// "stripe", "mock" or null; with a Stripe test key only admins can buy. // "stripe", "mock" or null; Stripe purchases are for admins only
// until PURCHASES_OPEN (and always with a test key).
"payments": payments::method(c), "payments": payments::method(c),
"payments_admins_only": payments::admins_only(c),
"payments_test": c.stripe.as_ref().is_some_and(|s| s.test_mode()), "payments_test": c.stripe.as_ref().is_some_and(|s| s.test_mode()),
"user_invites": c.user_invites, "user_invites": c.user_invites,
"referral_rewards": c.referral_rewards, "referral_rewards": c.referral_rewards,
+9 -3
View File
@@ -84,11 +84,17 @@ pub fn method(config: &crate::config::Config) -> Option<&'static str> {
} }
} }
/// Stripe, if this user may pay through it (with a test key: admins only, so /// Only admins can buy through Stripe: until purchases open, and always with a
/// nobody gets packages with Stripe's test cards). /// test key (nobody gets packages with Stripe's test cards, nobody types a
/// real card into a test page).
pub fn admins_only(config: &crate::config::Config) -> bool {
!config.purchases_open || config.stripe.as_ref().is_some_and(StripeConfig::test_mode)
}
/// Stripe, if this user may pay through it.
fn stripe_for<'a>(state: &'a AppState, auth: &AuthUser) -> Result<&'a StripeConfig, ApiError> { fn stripe_for<'a>(state: &'a AppState, auth: &AuthUser) -> Result<&'a StripeConfig, ApiError> {
let config = state.config.stripe.as_ref().ok_or(ApiError::NotFound("payment method"))?; let config = state.config.stripe.as_ref().ok_or(ApiError::NotFound("payment method"))?;
if config.test_mode() && !auth.user.has_role(Role::Admin) { if admins_only(&state.config) && !auth.user.has_role(Role::Admin) {
return Err(ApiError::Forbidden("purchases are being tested; they open soon".into())); return Err(ApiError::Forbidden("purchases are being tested; they open soon".into()));
} }
Ok(config) Ok(config)
+18
View File
@@ -2375,6 +2375,7 @@ async fn stripe_test_mode_is_for_admins_only(pool: PgPool) {
let r = app.get("/v1/config", None).await; let r = app.get("/v1/config", None).await;
assert_eq!(r.body["payments"], "stripe"); assert_eq!(r.body["payments"], "stripe");
assert_eq!(r.body["payments_test"], true); assert_eq!(r.body["payments_test"], true);
assert_eq!(r.body["payments_admins_only"], true);
let anna = app.register("anna@example.com", "Anna").await; let anna = app.register("anna@example.com", "Anna").await;
let r = app.post("/v1/payments/checkout", Some(&anna), json!({"package": "single"})).await; let r = app.post("/v1/payments/checkout", Some(&anna), json!({"package": "single"})).await;
assert_eq!(r.status, StatusCode::FORBIDDEN); assert_eq!(r.status, StatusCode::FORBIDDEN);
@@ -2383,3 +2384,20 @@ async fn stripe_test_mode_is_for_admins_only(pool: PgPool) {
let r = app.post("/v1/payments/checkout", Some(&admin), json!({"package": "single"})).await; let r = app.post("/v1/payments/checkout", Some(&admin), json!({"package": "single"})).await;
assert_eq!(r.body["error"]["code"], "payment_unavailable", "{}", r.body); assert_eq!(r.body["error"]["code"], "payment_unavailable", "{}", r.body);
} }
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn stripe_purchases_wait_for_the_opening(pool: PgPool) {
let app = TestApp::with_config(pool, |c| {
with_stripe(c, "sk_live_fake");
c.purchases_open = false;
})
.await;
let r = app.get("/v1/config", None).await;
assert_eq!((&r.body["payments_test"], &r.body["payments_admins_only"]), (&json!(false), &json!(true)));
let anna = app.register("anna@example.com", "Anna").await;
let r = app.post("/v1/payments/checkout", Some(&anna), json!({"package": "single"})).await;
assert_eq!(r.status, StatusCode::FORBIDDEN);
let admin = app.register("admin@example.com", "Admin").await;
let r = app.post("/v1/payments/checkout", Some(&admin), json!({"package": "single"})).await;
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
}
+6 -3
View File
@@ -1,9 +1,12 @@
import type { Me, PayMethod, PublicConfig } from "./types"; import type { Me, PayMethod, PublicConfig } from "./types";
/** How this user can buy packages (with a Stripe test key: admins only). */ /**
* How this user can buy packages. Until purchases open (and with a Stripe
* test key) only admins can; everyone else sees "soon".
*/
export function payMethod(config: PublicConfig | null | undefined, me: Me): PayMethod | null { export function payMethod(config: PublicConfig | null | undefined, me: Me): PayMethod | null {
if (config?.payments === "mock") return "mock"; if (config?.payments === "mock") return "mock";
if (config?.payments !== "stripe") return null; if (config?.payments !== "stripe") return null;
if (!config.payments_test) return "stripe"; if (config.payments_admins_only && !me.user.roles.includes("admin")) return null;
return me.user.roles.includes("admin") ? "stripe_test" : null; return config.payments_test ? "stripe_test" : "stripe";
} }
+3 -1
View File
@@ -94,7 +94,9 @@ export interface PublicConfig {
mock_payments: boolean; mock_payments: boolean;
/** How packages are paid: Stripe Checkout, the stand-in, or not at all. */ /** How packages are paid: Stripe Checkout, the stand-in, or not at all. */
payments: "stripe" | "mock" | null; payments: "stripe" | "mock" | null;
/** Stripe has a test key: only admins can buy. */ /** Only admins can buy through Stripe (until the opening, and with a test key). */
payments_admins_only: boolean;
/** Stripe has a test key (test cards work, no real money). */
payments_test: boolean; payments_test: boolean;
/** "invite": new accounts need an invitation. */ /** "invite": new accounts need an invitation. */
signup_mode: "invite" | "open"; signup_mode: "invite" | "open";