From 69f04a81bb366760d372a8138c975f4a8de65cd6 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 3 Dec 2026 02:06:20 -0600 Subject: [PATCH] =?UTF-8?q?v2.9287=20=E2=80=94=20Bids=20of=20the=20day:=20?= =?UTF-8?q?whoever=20can=20open=20a=20bid=20may=20read=20who=20kept=20it?= =?UTF-8?q?=20(punch=20list=20#469,=20step=205;=20owes=20a=20db=20push)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One more read rule on bid_day_entries: a kept row is read by whoever can read its bid, whole. The person's answers of 2026-12-03: everyone who opens the page, and the times of day too. Co-Authored-By: Claude Fable 5.2 --- docs/ACCESS_CONTROL.md | 5 ++ .../20261203080345_bid_day_read_by_bid.md | 54 +++++++++++++++++++ docs/recent-features/v2.9287.md | 33 ++++++++++++ scripts/pgtest-bid-day.sh | 8 +-- src/content/releaseNotes/v2.9287.ts | 15 ++++++ .../20261203080345_bid_day_read_by_bid.sql | 28 ++++++++++ supabase/tests/bid_day/20_scenario.sql | 32 +++++++---- 7 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 docs/migrations/20261203080345_bid_day_read_by_bid.md create mode 100644 docs/recent-features/v2.9287.md create mode 100644 src/content/releaseNotes/v2.9287.ts create mode 100644 supabase/migrations/20261203080345_bid_day_read_by_bid.sql diff --git a/docs/ACCESS_CONTROL.md b/docs/ACCESS_CONTROL.md index b722b3ead5..a007e5d0ab 100644 --- a/docs/ACCESS_CONTROL.md +++ b/docs/ACCESS_CONTROL.md @@ -2509,6 +2509,11 @@ A training-mode account cannot sign, since starting a paper is a write. - **The owner's answer** (2026-12-02, relayed whole by the managing session): asked on 2026-12-02 whether the office may read when in the day each kept bid was in front, and shown the pick *Yes: the times of the kept bids ride with the kept list* beside his answer of 2026-11-25, the owner typed "h3 its pick" in the managing session. - It narrows his pick of 2026-11-25 for kept bids alone: the office still does not read the trace, and reads the times of the bids a person kept, as the person handed them in. - **Asked again before the migration merged** (2026-12-02, typed in the next run's managing session): to *may the office read what time of day each kept bid was in front?* the person typed "Yes, H3 stands". +- **Read by whoever can read the bid** (v2.9287, `20261203080345_bid_day_read_by_bid.sql`): a second read rule, `bid_day_entries_select_by_bid`, lets anyone who can read a row's bid read that row, whole, with its times of day. +- It asks `bids` under the caller's own policies, so a primary reads only the rows of their own bids, and a lead, a helper and a superintendent, who read no bid, read no row by it. +- Writes are unchanged, and the trace (`user_bid_activity`) is read by nobody new. +- **The person's answers** (2026-12-03, pressed in the `hours` thread's question windows): to *who should see another person's bids on a bid's page and the Schedule?* they pressed "Everyone who opens the page", and to *should the new read keep the times of day a bid was open with the office only?* they pressed "No, show everyone". +- These widen the picks of 2026-11-25 and 2026-12-02 above, which kept the list and its times of day to the person, a dev, payroll access and the office. - **Test**: `npm run test:pg:bid-day` (`supabase/tests/bid_day/`). ### Stripe out-of-band payment unwind (v2.362, refinements v2.363) diff --git a/docs/migrations/20261203080345_bid_day_read_by_bid.md b/docs/migrations/20261203080345_bid_day_read_by_bid.md new file mode 100644 index 0000000000..c2782bcf57 --- /dev/null +++ b/docs/migrations/20261203080345_bid_day_read_by_bid.md @@ -0,0 +1,54 @@ +# 20261203080345_bid_day_read_by_bid.sql (2026-12-03, v2.9287) + +One more read rule on the kept list of the day's bids, so a bid can show who had it in front (punch list #469, step 5). A migration alone: no screen reads by bid yet. + +## What it does + +**`bid_day_entries_select_by_bid`**, a second `SELECT` policy on `bid_day_entries`, beside `bid_day_entries_select`: + +- A kept row is read by whoever can read the row's bid. +- The rule is a sub-select on `bids`, which runs under the caller's own policies on `bids`, as `bid_photos_select` does. So it follows the bid's read rule as it stands and as it changes: the roles that read a bid, a primary only on the bids they estimate, manage or made, and whatever fence `bids` itself carries. +- The row is read whole. The times of day a bid was in front (`seen`) and the tabs ride with it. + +It also rewrites the table's comment to say who reads it. + +## Who may do what, after it + +- **Read**: the person, a dev, payroll access and the office, as before. **New**: anyone who can read the row's bid. Today that is a dev, the owner, an assistant, the controller, an estimator, and a primary on their own bids. +- **Not new**: a role that reads no bid reads no row by this rule. A lead, a helper and a superintendent are as they were. +- **Write**: unchanged. A person writes only their own rows, for today or yesterday, and no one deletes a row. +- The table's restrictive fences stand over both read rules, the archived caller's among them. +- The trace under the list, `user_bid_activity`, is read by nobody new. + +## What it reaches that is already on screen + +`fetchKeptBidDays` asks for the kept rows of named people and days. It filters by person itself, so no read gains rows it did not ask for. But a reader who got none before now gets the rows of the bids they can read. So an owner without pay access, or an estimator, who opens a surface that draws another person's day as bids now sees those bids: People → Hours and a person's My Time section. + +`get_my_bid_day()` and `save_my_bid_day()` name the caller's own id in their statements. Neither reads another person's row under the wider rule. + +## The person's answers behind it + +Put to the person on 2026-12-03 in the `hours` thread's question windows, each with a pick: + +- *Who should see another person's bids on a bid's page and the Schedule?* Pressed: **"Everyone who opens the page"**. The pick put was to leave the rule. +- *Should the new read keep the times of day a bid was open with the office only?* Pressed: **"No, show everyone"**. The pick put was office only. + +This widens the owner's picks of 2026-11-25 and 2026-12-02, which kept the list and its times of day to the person, a dev, payroll access and the office. + +## Why a rule and not a function + +A function with the owner's rights cannot ask the caller's own policies on `bids`. It would need a helper that copies the bid's read rule, and the copy drifts when the rule changes. A row rule asks `bids` itself. The cost is that a row rule cannot leave a column out, and the second answer above says it need not. + +## Safety + +- Starts with `SET lock_timeout = '3s'`. `DROP POLICY IF EXISTS` then `CREATE POLICY`: a second run changes nothing. +- No table is created, so the four fence calls are not needed. No index: the table gains about a hundred rows a day at most. +- **Rollback**: `DROP POLICY IF EXISTS bid_day_entries_select_by_bid ON public.bid_day_entries;` + +## Test + +`npm run test:pg:bid-day` (`supabase/tests/bid_day/`). New cases: another estimator reads a person's whole list with its times of day and changes none of it, the owner reads it by its bids, a primary reads the rows of the bid they manage and no other, and a helper still reads none. The bed re-applies this file to prove a second run changes nothing. Not run on this Mac, where Docker was down: the SQL beds workflow runs it on the PR. + +## It owes prod + +`supabase db push`, after the merge, with the push slot. diff --git a/docs/recent-features/v2.9287.md b/docs/recent-features/v2.9287.md new file mode 100644 index 0000000000..3362df94f5 --- /dev/null +++ b/docs/recent-features/v2.9287.md @@ -0,0 +1,33 @@ +# v2.9287 — Bids of the day: whoever can open a bid may read who kept it (2026-12-03) + +Punch list #469, step 5, the read. A migration alone. No screen reads by bid yet, so no new screen. It owes a `supabase db push`. + +## Why + +The card's fifth step is a bid's own page: who had this bid in front, and on which days. The rows are the kept lists of the day's bids. Until now a kept list was read by the person, a dev, payroll access and the office. A bid opens for every estimator, so most people who open one could not read the rows. + +The call was put to the person on 2026-12-03 with the pick to leave the rule. They pressed **"Everyone who opens the page"**. Asked whether the times of day a bid was open should stay with the office, they pressed **"No, show everyone"**. + +## What ships + +[`20261203080345_bid_day_read_by_bid.sql`](../../supabase/migrations/20261203080345_bid_day_read_by_bid.sql), documented in [`docs/migrations/20261203080345_bid_day_read_by_bid.md`](../migrations/20261203080345_bid_day_read_by_bid.md): + +- One more read rule on `bid_day_entries`: a kept row is read by whoever can read its bid. It asks `bids` under the caller's own policies, so it follows the bid's read rule as it stands. +- The row is read whole, with the times of day a bid was in front. +- Writes are unchanged, and a role that reads no bid reads no row by this rule. + +## What changes on screen once it is pushed + +Nothing new is drawn. One thing widens: a surface that draws another person's day as bids, People → Hours and a person's My Time section, now draws those bids for an owner without pay access or an estimator who opens it, where it drew the office job before. + +## Tests + +`supabase/tests/bid_day/20_scenario.sql` has five new cases, and `scripts/pgtest-bid-day.sh` re-applies the new file. Docker was down on this Mac, so the bed was not run here: the SQL beds workflow runs it on the PR. + +## Words + +`docs/ACCESS_CONTROL.md`, under *The bids of the day*. + +## Next + +The History window's *On the clock* chip, which reads these rows by bid. It is client only and can merge before or after the push: before it, a reader outside the office sees only their own days. diff --git a/scripts/pgtest-bid-day.sh b/scripts/pgtest-bid-day.sh index 3a48416dd2..1ef21ee953 100755 --- a/scripts/pgtest-bid-day.sh +++ b/scripts/pgtest-bid-day.sh @@ -5,12 +5,12 @@ # npm run test:pg:bid-day # # The same bed as scripts/pgtest-bid-jobs-opened.sh: the Supabase Postgres image with every file in -# supabase/migrations applied in order, then the two bid-day migrations a second time, which must change nothing. The +# supabase/migrations applied in order, then the three bid-day migrations a second time, which must change nothing. The # scenario, inside one transaction that rolls back: beats add up in a five-minute bucket and stop at its cap; training # mode, a twin and nobody write none; the beat is read by the person, the owner, a dev and an app activity viewer; a # day's read holds the person's own changes with the app's writes counted apart; a list is kept, changed, refused for -# an old day and read by whoever reads the person's clock sessions; a list keeps where in the day each bid was seen -# (punch list #469). It raises on its first failed assertion and ends +# an old day and read by whoever reads the person's clock sessions and by whoever can read the row's bid; a list keeps +# where in the day each bid was seen (punch list #469). It raises on its first failed assertion and ends # with "bid_day PASSED". PGTEST_KEEP=1 leaves the container up. Needs docker; the SQL beds workflow runs it from # scripts/sql-beds.txt on a ready PR that touches a migration. Never touches prod. set -euo pipefail @@ -19,7 +19,7 @@ cd "$(dirname "$0")/.." PORT="${PGTEST_PORT:-55935}" NAME="pgtest-bid-day" IMAGE="${PGTEST_SUPABASE_IMAGE:-public.ecr.aws/supabase/postgres:17.6.1.071}" -WRITES="$(ls supabase/migrations/*_bid_day_ground.sql supabase/migrations/*_bid_day_entries_seen.sql)" +WRITES="$(ls supabase/migrations/*_bid_day_ground.sql supabase/migrations/*_bid_day_entries_seen.sql supabase/migrations/*_bid_day_read_by_bid.sql)" command -v docker >/dev/null || { echo "docker not on PATH"; exit 2; } docker info >/dev/null 2>&1 || { echo "docker is not running"; exit 2; } diff --git a/src/content/releaseNotes/v2.9287.ts b/src/content/releaseNotes/v2.9287.ts new file mode 100644 index 0000000000..c11a05e0a7 --- /dev/null +++ b/src/content/releaseNotes/v2.9287.ts @@ -0,0 +1,15 @@ +import type { ReleaseNote } from '../../lib/releaseNotes' + +const note: ReleaseNote = { + version: 'v2.9287', + date: '2026-12-03', + title: 'Bids of the day: whoever can open a bid may read who kept it', + kind: 'feature', + highlights: [ + 'Groundwork for a bid showing who had it in front, and on which days. No new screen yet.', + 'The list of bids a person keeps at clock out can now be read by anyone who can open those bids, not only by the office.', + 'So where a day at the office reads as its bids, on People → Hours and on a person’s My Time, an estimator or an owner who opens it now sees those bids too.', + ], +} + +export default note diff --git a/supabase/migrations/20261203080345_bid_day_read_by_bid.sql b/supabase/migrations/20261203080345_bid_day_read_by_bid.sql new file mode 100644 index 0000000000..ea1894d1dc --- /dev/null +++ b/supabase/migrations/20261203080345_bid_day_read_by_bid.sql @@ -0,0 +1,28 @@ +SET lock_timeout = '3s'; + +-- The bids of the day, read from the bid's side (punch list #469, step 5: a bid's own page). +-- +-- Until now a kept list was read by whoever reads the person's clock sessions: the person, a dev, payroll access and +-- the office (bid_day_entries_select, 20261125223610). A bid is to show who had it in front and on which days, in its +-- History window, to everyone who can open the bid. The person's two answers of 2026-12-03: "Everyone who opens the +-- page" sees the bids another person kept, and "No, show everyone" to keeping the times of day with the office. +-- +-- So one more read rule, beside the first: a kept row is read by whoever can read its bid. The sub-select on bids runs +-- under the caller's own policies on bids, as bid_photos_select does (20261110195527): the roles that read a bid, a +-- primary only on the bids they estimate, manage or made (primary_scope_bids), and whatever fence bids itself carries. +-- A role that reads no bid (a lead, a helper, a superintendent) reads no row by this rule. The table's own restrictive +-- fences still stand over both rules, the archived caller's among them (apply_archived_read_blocks). +-- +-- The row is read whole: the times of day (seen) and the tabs ride with it. Writes are untouched: a person still +-- writes only their own rows, for today or yesterday, and no one deletes one. The trace under the list +-- (user_bid_activity) is read by nobody new. +-- +-- Rollback: DROP POLICY IF EXISTS bid_day_entries_select_by_bid ON public.bid_day_entries; + +DROP POLICY IF EXISTS bid_day_entries_select_by_bid ON public.bid_day_entries; +CREATE POLICY bid_day_entries_select_by_bid ON public.bid_day_entries + FOR SELECT TO authenticated + USING (EXISTS (SELECT 1 FROM public.bids b WHERE b.id = bid_day_entries.bid_id)); + +COMMENT ON TABLE public.bid_day_entries IS + 'The bids of the day (punch list #445): the list a person left at clock out, one row a person, a company day and a bid, kept or taken off, read by the app or added by the person. A person writes their own rows for today or yesterday, through save_my_bid_day(). Read by whoever may read the person''s clock sessions, and since punch list #469''s step 5 by whoever can read the row''s bid.'; diff --git a/supabase/tests/bid_day/20_scenario.sql b/supabase/tests/bid_day/20_scenario.sql index 614bf68309..c6a468da90 100644 --- a/supabase/tests/bid_day/20_scenario.sql +++ b/supabase/tests/bid_day/20_scenario.sql @@ -3,13 +3,14 @@ -- a person in training mode, a twin and nobody write none; no client writes the beat's table; the beat is read by -- the person, the owner, a dev and an app activity viewer and by nobody else; the day's read holds the person's own -- changes and not another's, counts the app's own writes apart and leaves yesterday out; the list is kept, changed --- and read back, is refused for an old day, and is read by whoever reads the person's clock sessions. +-- and read back, is refused for an old day, and is read by whoever reads the person's clock sessions and by whoever +-- can read the row's bid (punch list #469, migration *_bid_day_read_by_bid). -- Everything rolls back. Raises on the first failed assertion; ends with "bid_day PASSED". See scripts/pgtest-bid-day.sh. Never against prod. \set ON_ERROR_STOP 1 BEGIN; -- Wendi and Kim (estimators), Rosa (assistant), Marcus (helper), Mo (the master), Dee (dev), Tess (an estimator in --- training mode), Robo (a twin with the estimator role). +-- training mode), Robo (a twin with the estimator role), Pat (a primary who manages the second bid and no other). INSERT INTO auth.users (id, email) VALUES ('00000000-0000-0000-0000-0000000bda01', 'wendi@bidday.test'), ('00000000-0000-0000-0000-0000000bda02', 'kim@bidday.test'), @@ -18,7 +19,8 @@ INSERT INTO auth.users (id, email) VALUES ('00000000-0000-0000-0000-0000000bda05', 'mo@bidday.test'), ('00000000-0000-0000-0000-0000000bda06', 'dee@bidday.test'), ('00000000-0000-0000-0000-0000000bda07', 'tess@bidday.test'), - ('00000000-0000-0000-0000-0000000bda08', 'robo@bidday.test'); + ('00000000-0000-0000-0000-0000000bda08', 'robo@bidday.test'), + ('00000000-0000-0000-0000-0000000bda09', 'pat@bidday.test'); INSERT INTO public.users (id, email, name, role, read_only, is_digital_twin) VALUES ('00000000-0000-0000-0000-0000000bda01', 'wendi@bidday.test', 'Bidday Wendi', 'estimator', false, false), ('00000000-0000-0000-0000-0000000bda02', 'kim@bidday.test', 'Bidday Kim', 'estimator', false, false), @@ -27,14 +29,15 @@ INSERT INTO public.users (id, email, name, role, read_only, is_digital_twin) VAL ('00000000-0000-0000-0000-0000000bda05', 'mo@bidday.test', 'Bidday Mo', 'master_technician', false, false), ('00000000-0000-0000-0000-0000000bda06', 'dee@bidday.test', 'Bidday Dee', 'dev', false, false), ('00000000-0000-0000-0000-0000000bda07', 'tess@bidday.test', 'Bidday Tess', 'estimator', true, false), - ('00000000-0000-0000-0000-0000000bda08', 'robo@bidday.test', 'Bidday Robo', 'estimator', false, true) + ('00000000-0000-0000-0000-0000000bda08', 'robo@bidday.test', 'Bidday Robo', 'estimator', false, true), + ('00000000-0000-0000-0000-0000000bda09', 'pat@bidday.test', 'Bidday Pat', 'primary', false, false) ON CONFLICT (id) DO UPDATE SET role = EXCLUDED.role, name = EXCLUDED.name, read_only = EXCLUDED.read_only, is_digital_twin = EXCLUDED.is_digital_twin; INSERT INTO public.service_types (id, name) VALUES ('00000000-0000-0000-0000-0000000bdb01', 'Bidday Plumbing'); INSERT INTO public.customers (id, master_user_id, name) VALUES ('00000000-0000-0000-0000-0000000bdc01', '00000000-0000-0000-0000-0000000bda05', 'Ridgeway Builders'); -INSERT INTO public.bids (id, created_by, estimator_id, service_type_id, project_name, bid_number, customer_id) VALUES - ('00000000-0000-0000-0000-0000000bdd01', '00000000-0000-0000-0000-0000000bda03', '00000000-0000-0000-0000-0000000bda01', '00000000-0000-0000-0000-0000000bdb01', 'Ridgeway Clinic', '412', '00000000-0000-0000-0000-0000000bdc01'), - ('00000000-0000-0000-0000-0000000bdd02', '00000000-0000-0000-0000-0000000bda03', '00000000-0000-0000-0000-0000000bda02', '00000000-0000-0000-0000-0000000bdb01', 'Harbor Lofts', '398', '00000000-0000-0000-0000-0000000bdc01'); +INSERT INTO public.bids (id, created_by, estimator_id, account_manager_id, service_type_id, project_name, bid_number, customer_id) VALUES + ('00000000-0000-0000-0000-0000000bdd01', '00000000-0000-0000-0000-0000000bda03', '00000000-0000-0000-0000-0000000bda01', NULL, '00000000-0000-0000-0000-0000000bdb01', 'Ridgeway Clinic', '412', '00000000-0000-0000-0000-0000000bdc01'), + ('00000000-0000-0000-0000-0000000bdd02', '00000000-0000-0000-0000-0000000bda03', '00000000-0000-0000-0000-0000000bda02', '00000000-0000-0000-0000-0000000bda09', '00000000-0000-0000-0000-0000000bdb01', 'Harbor Lofts', '398', '00000000-0000-0000-0000-0000000bdc01'); -- The ledger, written here as the trigger would write it. The bids rows above made rows of their own (changed_by -- null, since nobody is signed in yet), which belong to nobody's day. @@ -221,9 +224,20 @@ SELECT bdt.refused('a twin keeping a list', $$SELECT public.save_my_bid_day(publ SELECT bdt.as_user(NULL); SELECT bdt.refused('nobody keeping a list', $$SELECT public.save_my_bid_day(public.app_today(), '[]'::jsonb)$$, 'Sign in'); --- Who reads a kept list: whoever reads the person's clock sessions. +-- Who reads a kept list: whoever reads the person's clock sessions, and whoever can read the row's bid (punch list +-- #469, step 5). Her list holds three rows: the first bid today and yesterday, the second bid today. SELECT bdt.as_user('00000000-0000-0000-0000-0000000bda02'); -SELECT bdt.same('another estimator reads none of her list', bdt.lists(), 'none'); +SELECT bdt.same('another estimator, who reads every bid, reads her whole list', (SELECT count(*)::text FROM public.bid_day_entries), '3'); +SELECT bdt.same('... with the times of day a bid was seen', bdt.seen_of('00000000-0000-0000-0000-0000000bdd01'), '3600:300 3900:120'); +-- The write rules are as they were: her rows are not his to change, so the statement finds none. +UPDATE public.bid_day_entries SET state = 'off' WHERE user_id = '00000000-0000-0000-0000-0000000bda01'; +SELECT bdt.same('... and changes none of it', (SELECT count(*)::text FROM public.bid_day_entries WHERE state = 'kept'), '3'); +SELECT bdt.as_user('00000000-0000-0000-0000-0000000bda05'); +SELECT bdt.same('the master reads it by its bids, with or without pay access', (SELECT count(*)::text FROM public.bid_day_entries), '3'); +SELECT bdt.as_user('00000000-0000-0000-0000-0000000bda09'); +SELECT bdt.same('a primary reads the rows of the bid they manage and no other', (SELECT coalesce(string_agg('B' || right(k.bid_id::text, 1), ',' ORDER BY k.bid_id), 'none') FROM public.bid_day_entries k), 'B2'); +SELECT bdt.as_user('00000000-0000-0000-0000-0000000bda04'); +SELECT bdt.same('a helper, who reads no bid, still reads none', (SELECT count(*)::text FROM public.bid_day_entries), '0'); SELECT bdt.as_user('00000000-0000-0000-0000-0000000bda03'); SELECT bdt.same('the office reads it', (SELECT count(*)::text FROM public.bid_day_entries), '3'); SELECT bdt.as_user('00000000-0000-0000-0000-0000000bda06');