Gate the registration seat bump on the holder's role (Gamze's find)
Browse files at this commitaf331ecc8a4a0c661bcdbc905b95bb2cf77a72deParent: dab83cb- fix
- gate the registration seat bump on the holder's role (Gamze's find)
7 changed files +49 -9
- .sqlx/query-00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c.json +23 -0
- .sqlx/query-07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7.json → .sqlx/query-9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.json +2 -2
- .sqlx/query-92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477.json → .sqlx/query-ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b.json +2 -3
- .sqlx/query-da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116.json → .sqlx/query-d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd.json +2 -2
- .sqlx/query-f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1.json +14 -0
- .sqlx/query-df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f.json → .sqlx/query-f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0.json +2 -2
- src/db/registration.rs +4 -0
.sqlx/query-00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c.jsonadded+23 -0
| @@ -0,0 +1,23 @@ | ||
| 1 | +{ | |
| 2 | + "db_name": "PostgreSQL", | |
| 3 | + "query": "SELECT 1 AS deletable FROM menu WHERE id = $1 AND seats_booked = 0 FOR UPDATE", | |
| 4 | + "describe": { | |
| 5 | + "columns": [ | |
| 6 | + { | |
| 7 | + "ordinal": 0, | |
| 8 | + "name": "deletable", | |
| 9 | + "type_info": "Int4", | |
| 10 | + "origin": "Expression" | |
| 11 | + } | |
| 12 | + ], | |
| 13 | + "parameters": { | |
| 14 | + "Left": [ | |
| 15 | + "Text" | |
| 16 | + ] | |
| 17 | + }, | |
| 18 | + "nullable": [ | |
| 19 | + null | |
| 20 | + ] | |
| 21 | + }, | |
| 22 | + "hash": "00af80234ae32f16458bf08eb38ade45f01805c8d1d5d523082a8ca90840a40c" | |
| 23 | +} |
.sqlx/query-07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7.json → .sqlx/query-9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b.jsonrenamed+2 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "db_name": "PostgreSQL", |
| 3 | - "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\"", | |
| 3 | + "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", | |
| 4 | 4 | "describe": { |
| 5 | 5 | "columns": [ |
| 6 | 6 | { |
| @@ -96,5 +96,5 @@ | ||
| 96 | 96 | true |
| 97 | 97 | ] |
| 98 | 98 | }, |
| 99 | - "hash": "07c76d04dc27e98446cd6f8be79267ce82f37763281be7dd44f8787c50f86da7" | |
| 99 | + "hash": "9f1e912082c61931ac4b9a0f1d23270e2e7f10a342cbb7b4e4ebaaf7cb3f3b4b" | |
| 100 | 100 | } |
.sqlx/query-92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477.json → .sqlx/query-ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b.jsonrenamed+2 -3
| @@ -1,16 +1,15 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "db_name": "PostgreSQL", |
| 3 | - "query": "UPDATE homework_submission SET graded_by_result = NULL\n WHERE homework = $1 AND app_user = $2 AND graded_by_result = $3", | |
| 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)", | |
| 4 | 4 | "describe": { |
| 5 | 5 | "columns": [], |
| 6 | 6 | "parameters": { |
| 7 | 7 | "Left": [ |
| 8 | - "Uuid", | |
| 9 | 8 | "Uuid", |
| 10 | 9 | "Uuid" |
| 11 | 10 | ] |
| 12 | 11 | }, |
| 13 | 12 | "nullable": [] |
| 14 | 13 | }, |
| 15 | - "hash": "92ce049ca042d406dd4b4271bd1af9c09879245425fd8a0b863b22a8463df477" | |
| 14 | + "hash": "ad1364869335c3002f06a079c0060bf25312bd2749d712cd3d9c68d7a0d9c95b" | |
| 16 | 15 | } |
.sqlx/query-da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116.json → .sqlx/query-d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd.jsonrenamed+2 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "db_name": "PostgreSQL", |
| 3 | - "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\"", | |
| 3 | + "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\"", | |
| 4 | 4 | "describe": { |
| 5 | 5 | "columns": [ |
| 6 | 6 | { |
| @@ -50,5 +50,5 @@ | ||
| 50 | 50 | false |
| 51 | 51 | ] |
| 52 | 52 | }, |
| 53 | - "hash": "da37b88a2b20ef07d12c5d4912e3a2c46a548948f3c4d92b18f2e7a23bb16116" | |
| 53 | + "hash": "d12a287b9327e990350afa3555430b67c83f94001ffe99b28fafbf2a137e31cd" | |
| 54 | 54 | } |
.sqlx/query-f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1.jsonadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +{ | |
| 2 | + "db_name": "PostgreSQL", | |
| 3 | + "query": "DELETE FROM homework_submission WHERE id = $1", | |
| 4 | + "describe": { | |
| 5 | + "columns": [], | |
| 6 | + "parameters": { | |
| 7 | + "Left": [ | |
| 8 | + "Uuid" | |
| 9 | + ] | |
| 10 | + }, | |
| 11 | + "nullable": [] | |
| 12 | + }, | |
| 13 | + "hash": "f394a745bdcd9796b42a6ce417d0c379c321ddb8fb743c6b35367cc8ac9774f1" | |
| 14 | +} |
.sqlx/query-df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f.json → .sqlx/query-f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0.jsonrenamed+2 -2
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "db_name": "PostgreSQL", |
| 3 | - "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\"", | |
| 3 | + "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\"", | |
| 4 | 4 | "describe": { |
| 5 | 5 | "columns": [ |
| 6 | 6 | { |
| @@ -96,5 +96,5 @@ | ||
| 96 | 96 | false |
| 97 | 97 | ] |
| 98 | 98 | }, |
| 99 | - "hash": "df805341cc2335a4a2167b41d5739322505953c3b4cfcf818ff0b9ab89af353f" | |
| 99 | + "hash": "f81cadd9716849756ac7d2710b6e9bfd592cce8eedeacd043e7e4d7f4eb58ea0" | |
| 100 | 100 | } |
src/db/registration.rsmodified+4 -0
| @@ -73,6 +73,10 @@ pub async fn claim_seat( | ||
| 73 | 73 | UPDATE event SET registration_count = registration_count + 1 |
| 74 | 74 | WHERE id = $1 |
| 75 | 75 | AND (audience_capacity IS NULL OR registration_count < audience_capacity) |
| 76 | + -- The role gate rides the bump's WHERE: a data-modifying CTE | |
| 77 | + -- executes even when the INSERT below matches nothing, so the | |
| 78 | + -- count must refuse exactly when the seat refuses. | |
| 79 | + AND EXISTS (SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent') | |
| 76 | 80 | RETURNING 1), |
| 77 | 81 | person AS ( |
| 78 | 82 | SELECT 1 FROM app_user WHERE id = $2 AND role IS DISTINCT FROM 'parent' |