Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ COPY server ./server
# Code the web server shares with the app (server/dockerfile.test.ts checks the list)
COPY src/lib/markdown.ts ./src/lib/markdown.ts
COPY src/shared/productLinks.ts ./src/shared/productLinks.ts
COPY src/shared/appRoutes.ts ./src/shared/appRoutes.ts
COPY src/shared/eventJsonLd.ts ./src/shared/eventJsonLd.ts
COPY --from=builder /app/dist ./dist

USER node
Expand Down
3 changes: 3 additions & 0 deletions backend/migrations/0015_event_address.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Address of the venue next to the free-text location (its name, e.g. "Turnhalle Nord"):
-- search engines show an event in their event results only with a postal address.
ALTER TABLE events ADD COLUMN street text, ADD COLUMN postal_code text, ADD COLUMN city text;
2 changes: 2 additions & 0 deletions backend/migrations/0016_event_country.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Country of the venue's address (ISO 3166-1 alpha-2, e.g. DE, AT, CH); empty is Germany.
ALTER TABLE events ADD COLUMN country text;
17 changes: 16 additions & 1 deletion backend/src/modules/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ pub struct Event {
pub cover_image: Option<Uuid>,
pub event_map_image: Option<Uuid>,
pub location: String,
/// Address of the venue; `location` is its name or, in older events, all of it
pub street: Option<String>,
pub postal_code: Option<String>,
pub city: Option<String>,
/// ISO 3166-1 alpha-2; none is Germany
pub country: Option<String>,
#[serde(with = "ms")]
pub start_date: DateTime<Utc>,
#[serde(with = "ms")]
Expand Down Expand Up @@ -181,6 +187,10 @@ struct EventRow {
cover_image_id: Option<Uuid>,
map_image_id: Option<Uuid>,
location: String,
street: Option<String>,
postal_code: Option<String>,
city: Option<String>,
country: Option<String>,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
contact_info: String,
Expand Down Expand Up @@ -242,6 +252,10 @@ impl From<EventRow> for Event {
cover_image: row.cover_image_id,
event_map_image: row.map_image_id,
location: row.location,
street: row.street,
postal_code: row.postal_code,
city: row.city,
country: row.country,
start_date: row.start_date,
end_date: row.end_date,
contact_info: row.contact_info,
Expand Down Expand Up @@ -276,7 +290,8 @@ impl From<EventRow> for Event {

/// SELECT list of the events table aliased `e`.
pub const EVENT_COLUMNS: &str = "e.id, e.created_at, e.title, e.description, e.cover_image_id,
e.map_image_id, e.location, e.start_date, e.end_date, e.contact_info,
e.map_image_id, e.location, e.street, e.postal_code, e.city, e.country,
e.start_date, e.end_date, e.contact_info,
ARRAY(SELECT c.category_id FROM event_categories c WHERE c.event_id = e.id ORDER BY c.position)
AS categories,
e.services::text[] AS services, e.visibility::text AS visibility, e.is_approved,
Expand Down
72 changes: 69 additions & 3 deletions backend/src/modules/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,52 @@ struct Logistics {
note: Option<String>,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct AddressArgs {
street: Option<String>,
postal_code: Option<String>,
city: Option<String>,
country: Option<String>,
}

/// Street, postal code and town of the venue; empty parts are stored as NULL.
struct Address {
street: Option<String>,
postal_code: Option<String>,
city: Option<String>,
country: Option<String>,
}

/// Countries the address form offers (ISO 3166-1 alpha-2).
const COUNTRIES: [&str; 5] = ["DE", "AT", "CH", "LI", "LU"];

fn sanitize_address(args: Option<AddressArgs>) -> AppResult<Address> {
let part = |value: Option<String>, max: usize| -> AppResult<Option<String>> {
let value = value.map(|v| v.trim().to_owned()).filter(|v| !v.is_empty());
if value.as_ref().is_some_and(|v| v.chars().count() > max) {
return Err(AppError::bad_request("event.addressTooLong"));
}
Ok(value)
};
let args = args.unwrap_or(AddressArgs {
street: None,
postal_code: None,
city: None,
country: None,
});
let country = part(args.country, 2)?.map(|c| c.to_ascii_uppercase());
if country.as_deref().is_some_and(|c| !COUNTRIES.contains(&c)) {
return Err(AppError::bad_request("event.countryUnknown"));
}
Ok(Address {
street: part(args.street, 200)?,
postal_code: part(args.postal_code, 10)?,
city: part(args.city, 100)?,
country,
})
}

/// Checks the hand-in and pickup times; empty fields are dropped.
fn sanitize_logistics(args: LogisticsArgs) -> AppResult<Logistics> {
for (label, start, end) in [
Expand Down Expand Up @@ -857,6 +903,7 @@ struct CreateArgs {
cover_image: Option<Id>,
event_map_image: Option<Id>,
location: String,
address: Option<AddressArgs>,
start_date: f64,
end_date: f64,
contact_info: String,
Expand Down Expand Up @@ -890,13 +937,15 @@ async fn create_event(ctx: &mut Ctx, args: CreateArgs) -> AppResult<Uuid> {
.transpose()?;
let logistics = args.seller_logistics.map(sanitize_logistics).transpose()?;
let logistics = logistics.as_ref();
let address = sanitize_address(args.address)?;
let id: Uuid = sqlx::query_scalar(
"INSERT INTO events (title, description, cover_image_id, map_image_id, location, start_date,
end_date, contact_info, services, visibility, is_approved, approval_status, access_code,
vendor_limit, commission, features, dropoff_start, dropoff_end, pickup_start, pickup_end,
logistics_note, organizer_id)
logistics_note, organizer_id, street, postal_code, city, country)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9::event_service[], $10::event_visibility, $11,
$12::approval_status, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
$12::approval_status, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25,
$26)
RETURNING id",
)
.bind(&args.title)
Expand All @@ -921,6 +970,10 @@ async fn create_event(ctx: &mut Ctx, args: CreateArgs) -> AppResult<Uuid> {
.bind(logistics.and_then(|l| l.pickup_end))
.bind(logistics.and_then(|l| l.note.clone()))
.bind(user)
.bind(&address.street)
.bind(&address.postal_code)
.bind(&address.city)
.bind(&address.country)
.fetch_one(ctx.conn())
.await?;
set_categories(ctx, id, &args.categories).await?;
Expand All @@ -941,6 +994,8 @@ struct EditArgs {
cover_image: Option<Id>,
event_map_image: Option<Id>,
location: String,
/// Absent (older apps): the stored address stays
address: Option<AddressArgs>,
start_date: f64,
end_date: f64,
categories: Vec<Id>,
Expand Down Expand Up @@ -1022,6 +1077,8 @@ async fn edit_event(ctx: &mut Ctx, args: EditArgs) -> AppResult<()> {
let logistics = args.seller_logistics.map(sanitize_logistics).transpose()?;
let keep_logistics = logistics.is_none();
let logistics = logistics.as_ref();
let keep_address = args.address.is_none();
let address = sanitize_address(args.address)?;
sqlx::query(
"UPDATE events SET title = $2, description = $3,
cover_image_id = CASE WHEN $4 THEN NULL ELSE COALESCE($5, cover_image_id) END,
Expand All @@ -1037,7 +1094,11 @@ async fn edit_event(ctx: &mut Ctx, args: EditArgs) -> AppResult<()> {
pickup_end = CASE WHEN $20 THEN pickup_end ELSE $24 END,
logistics_note = CASE WHEN $20 THEN logistics_note ELSE $25 END,
is_approved = CASE WHEN $26 THEN false ELSE is_approved END,
approval_status = CASE WHEN $26 THEN 'pending' ELSE approval_status END
approval_status = CASE WHEN $26 THEN 'pending' ELSE approval_status END,
street = CASE WHEN $27 THEN street ELSE $28 END,
postal_code = CASE WHEN $27 THEN postal_code ELSE $29 END,
city = CASE WHEN $27 THEN city ELSE $30 END,
country = CASE WHEN $27 THEN country ELSE $31 END
WHERE id = $1",
)
.bind(event.id)
Expand Down Expand Up @@ -1066,6 +1127,11 @@ async fn edit_event(ctx: &mut Ctx, args: EditArgs) -> AppResult<()> {
.bind(logistics.and_then(|l| l.pickup_end))
.bind(logistics.and_then(|l| l.note.clone()))
.bind(making_public)
.bind(keep_address)
.bind(&address.street)
.bind(&address.postal_code)
.bind(&address.city)
.bind(&address.country)
.execute(ctx.conn())
.await?;
set_categories(ctx, event.id, &args.categories).await?;
Expand Down
53 changes: 53 additions & 0 deletions backend/tests/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,65 @@ async fn edit_args(app: &TestApp, session: &str, id: Uuid) -> Value {
})
}

async fn get_event(app: &TestApp, session: &str, id: Uuid) -> Value {
app.query("events.getEvent", json!({ "id": id }), Some(session))
.await
.body["value"]
.clone()
}

async fn single_mode_app(db: &PgPool) -> TestApp {
let mut config = Config::for_tests("");
config.mode = InstanceMode::Single;
TestApp::with_config(db.clone(), config)
}

#[sqlx::test(migrator = "bazarpro_backend::MIGRATOR")]
async fn the_address_is_stored_kept_by_older_apps_and_cleared(db: PgPool) {
let app = TestApp::new(db.clone());
let organizer = fixtures::user(&db, "Orga").await;
let session = fixtures::session(&db, organizer).await;
let mut args = event_args("Kinderbasar", "logged-in");
args["location"] = json!("Turnhalle Nord");
args["address"] = json!({ "street": " Hauptstr. 5 ", "postalCode": "6020", "city": "Innsbruck", "country": "at" });
let id = create(&app, &session, args).await;
let stored = get_event(&app, &session, id).await;
assert_eq!(
(&stored["street"], &stored["postalCode"], &stored["city"]),
(&json!("Hauptstr. 5"), &json!("6020"), &json!("Innsbruck"))
);
assert_eq!(stored["country"], "AT");

// An app from before the address sends none: it stays
let reply = app
.mutation(
"events.editEvent",
edit_args(&app, &session, id).await,
Some(&session),
)
.await;
assert_eq!(reply.status, StatusCode::OK, "{}", reply.body);
assert_eq!(get_event(&app, &session, id).await["city"], "Innsbruck");

// Empty parts clear it; an event without address leaves the fields out
let mut args = edit_args(&app, &session, id).await;
args["address"] = json!({ "street": "", "postalCode": " ", "city": null });
let reply = app.mutation("events.editEvent", args, Some(&session)).await;
assert_eq!(reply.status, StatusCode::OK, "{}", reply.body);
let cleared = get_event(&app, &session, id).await;
assert!(cleared.get("street").is_none() && cleared.get("country").is_none());

for address in [
json!({ "postalCode": "1".repeat(11) }),
json!({ "city": "Paris", "country": "FR" }),
] {
let mut args = edit_args(&app, &session, id).await;
args["address"] = address;
let reply = app.mutation("events.editEvent", args, Some(&session)).await;
assert_eq!(reply.status, StatusCode::BAD_REQUEST, "{}", reply.body);
}
}

#[sqlx::test(migrator = "bazarpro_backend::MIGRATOR")]
async fn creating_an_event_makes_the_creator_organizer(db: PgPool) {
let app = TestApp::new(db.clone());
Expand Down
4 changes: 4 additions & 0 deletions backend/tests/api/reminders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ fn pickup_text_with_a_fee_to_pay_and_a_long_item_list() {
cover_image: None,
event_map_image: None,
location: "Halle".into(),
street: None,
postal_code: None,
city: None,
country: None,
start_date: time("2026-10-17T08:00:00Z"),
end_date: time("2026-10-17T12:00:00Z"),
contact_info: String::new(),
Expand Down
Binary file added public/images/covers/bike.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/covers/clothing.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/covers/kids.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/covers/market.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/covers/pattern.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/covers/ski.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions scripts/event-covers/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<style>
body {
margin: 0;
}
.cover {
position: relative;
width: 1600px;
height: 900px;
overflow: hidden;
color: #27272a;
}
.cover svg {
display: block;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="./scenes.tsx"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions scripts/event-covers/render.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Renders the scenes to public/images/covers/<id>.webp: node scripts/event-covers/render.mjs
import { mkdirSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { chromium } from 'playwright';
import { createServer } from 'vite';

const output = resolve('public/images/covers');
mkdirSync(output, { recursive: true });

const server = await createServer({ server: { port: 5199 }, logLevel: 'error' });
await server.listen();
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
await page.goto('http://localhost:5199/scripts/event-covers/index.html');
await page.waitForSelector('[data-cover]');

for (const cover of await page.locator('[data-cover]').all()) {
const id = await cover.getAttribute('data-cover');
const png = (await cover.screenshot()).toString('base64');
const webp = await page.evaluate(async (data) => {
const image = new Image();
image.src = `data:image/png;base64,${data}`;
await image.decode();
const canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext('2d').drawImage(image, 0, 0);
return canvas.toDataURL('image/webp', 0.85).split(',')[1];
}, png);
writeFileSync(resolve(output, `${id}.webp`), Buffer.from(webp, 'base64'));
console.log(id, Math.round((webp.length * 0.75) / 1024), 'KB');
}

await browser.close();
await server.close();
Loading
Loading