From af331ecc8a4a0c661bcdbc905b95bb2cf77a72de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 12 Sep 2026 18:32:09 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20gate=20the=20registration?= =?UTF-8?q?=20seat=20bump=20on=20the=20holder's=20role=20(Gamze's=20find)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ade45f01805c8d1d5d523082a8ca90840a40c.json | 23 +++++++++++++++++++ ...270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.json} | 4 ++-- ...0bf25312bd2749d712cd3d9c68d7a0d9c95b.json} | 5 ++-- ...0b67c83f94001ffe99b28fafbf2a137e31cd.json} | 4 ++-- ...0c379c321ddb8fb743c6b35367cc8ac9774f1.json | 14 +++++++++++ ...9bfd592cce8eedeacd043e7e4d7f4eb58ea0.json} | 4 ++-- src/db/registration.rs | 4 ++++ 7 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .sqlx/query-00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c.json rename .sqlx/{query-07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7.json => query-9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.json} (75%) rename .sqlx/{query-92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477.json => query-ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b.json} (61%) rename .sqlx/{query-da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116.json => query-d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd.json} (55%) create mode 100644 .sqlx/query-f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1.json rename .sqlx/{query-df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f.json => query-f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0.json} (84%) diff --git a/.sqlx/query-00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c.json b/.sqlx/query-00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c.json new file mode 100644 index 0000000..8c946f4 --- /dev/null +++ b/.sqlx/query-00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT 1 AS deletable FROM menu WHERE id = $1 AND seats_booked = 0 FOR UPDATE", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "deletable", + "type_info": "Int4", + "origin": "Expression" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c" +} diff --git a/.sqlx/query-07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7.json b/.sqlx/query-9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.json similarity index 75% rename from .sqlx/query-07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7.json rename to .sqlx/query-9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.json index a11329b..7571208 100644 --- a/.sqlx/query-07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7.json +++ b/.sqlx/query-9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "DELETE FROM homework_submission\n WHERE id = $1 AND graded_by_result IS NULL\n RETURNING id AS \"id: HomeworkSubmissionId\",\n homework AS \"homework: HomeworkId\",\n app_user AS \"user: UserId\",\n text AS \"text: SubmissionText\",\n submitted_at AS \"submitted_at: Timestamp\",\n updated_at AS \"updated_at: Timestamp\",\n counted_on_time AS \"counted_on_time: bool\"", + "query": "SELECT id AS \"id: HomeworkSubmissionId\",\n homework AS \"homework: HomeworkId\",\n app_user AS \"user: UserId\",\n text AS \"text: SubmissionText\",\n submitted_at AS \"submitted_at: Timestamp\",\n updated_at AS \"updated_at: Timestamp\",\n counted_on_time AS \"counted_on_time: bool\"\n FROM homework_submission\n WHERE id = $1 AND graded_by_result IS NULL\n FOR UPDATE", "describe": { "columns": [ { @@ -96,5 +96,5 @@ true ] }, - "hash": "07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7" + "hash": "9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b" } diff --git a/.sqlx/query-92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477.json b/.sqlx/query-ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b.json similarity index 61% rename from .sqlx/query-92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477.json rename to .sqlx/query-ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b.json index 59b281d..fd2c79a 100644 --- a/.sqlx/query-92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477.json +++ b/.sqlx/query-ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b.json @@ -1,16 +1,15 @@ { "db_name": "PostgreSQL", - "query": "UPDATE homework_submission SET graded_by_result = NULL\n WHERE homework = $1 AND app_user = $2 AND graded_by_result = $3", + "query": "UPDATE homework_submission SET graded_by_result = NULL\n WHERE homework = $1 AND app_user = $2 AND graded_by_result IN (\n SELECT id FROM homework_result WHERE homework = $1 AND app_user = $2)", "describe": { "columns": [], "parameters": { "Left": [ - "Uuid", "Uuid", "Uuid" ] }, "nullable": [] }, - "hash": "92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477" + "hash": "ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b" } diff --git a/.sqlx/query-da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116.json b/.sqlx/query-d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd.json similarity index 55% rename from .sqlx/query-da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116.json rename to .sqlx/query-d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd.json index c13e693..2c829cc 100644 --- a/.sqlx/query-da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116.json +++ b/.sqlx/query-d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "WITH seat AS (\n UPDATE event SET registration_count = registration_count + 1\n WHERE id = $1\n AND (audience_capacity IS NULL OR registration_count < audience_capacity)\n RETURNING 1),\n person AS (\n SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent'\n FOR NO KEY UPDATE)\n INSERT INTO registration (event, app_user, registered_by)\n SELECT $1, $2, $3\n WHERE EXISTS (SELECT 1 FROM seat) AND EXISTS (SELECT 1 FROM person)\n RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", registered_by AS \"registered_by: UserId\"", + "query": "WITH seat AS (\n UPDATE event SET registration_count = registration_count + 1\n WHERE id = $1\n AND (audience_capacity IS NULL OR registration_count < audience_capacity)\n -- The role gate rides the bump's WHERE: a data-modifying CTE\n -- executes even when the INSERT below matches nothing, so the\n -- count must refuse exactly when the seat refuses.\n AND EXISTS (SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent')\n RETURNING 1),\n person AS (\n SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent'\n FOR NO KEY UPDATE)\n INSERT INTO registration (event, app_user, registered_by)\n SELECT $1, $2, $3\n WHERE EXISTS (SELECT 1 FROM seat) AND EXISTS (SELECT 1 FROM person)\n RETURNING event AS \"event: EventId\", app_user AS \"user: UserId\", registered_by AS \"registered_by: UserId\"", "describe": { "columns": [ { @@ -50,5 +50,5 @@ false ] }, - "hash": "da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116" + "hash": "d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd" } diff --git a/.sqlx/query-f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1.json b/.sqlx/query-f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1.json new file mode 100644 index 0000000..5872e83 --- /dev/null +++ b/.sqlx/query-f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM homework_submission WHERE id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [] + }, + "hash": "f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1" +} diff --git a/.sqlx/query-df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f.json b/.sqlx/query-f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0.json similarity index 84% rename from .sqlx/query-df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f.json rename to .sqlx/query-f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0.json index bdb2b86..8bc2bcf 100644 --- a/.sqlx/query-df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f.json +++ b/.sqlx/query-f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "DELETE FROM menu WHERE id = $1 AND seats_booked = 0\n RETURNING id AS \"id: MenuId\", date AS \"date: MenuDate\", slot AS \"slot: MenuSlot\", capacity, version, created_by AS \"created_by: UserId\", created_at AS \"created_at: Timestamp\"", + "query": "DELETE FROM menu WHERE id = $1\n RETURNING id AS \"id: MenuId\", date AS \"date: MenuDate\", slot AS \"slot: MenuSlot\", capacity, version, created_by AS \"created_by: UserId\", created_at AS \"created_at: Timestamp\"", "describe": { "columns": [ { @@ -96,5 +96,5 @@ false ] }, - "hash": "df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f" + "hash": "f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0" } diff --git a/src/db/registration.rs b/src/db/registration.rs index ea4634e..028c728 100644 --- a/src/db/registration.rs +++ b/src/db/registration.rs @@ -73,6 +73,10 @@ pub async fn claim_seat( UPDATE event SET registration_count = registration_count + 1 WHERE id = $1 AND (audience_capacity IS NULL OR registration_count < audience_capacity) + -- The role gate rides the bump's WHERE: a data-modifying CTE + -- executes even when the INSERT below matches nothing, so the + -- count must refuse exactly when the seat refuses. + AND EXISTS (SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent') RETURNING 1), person AS ( SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent'