Skip to content

feat(availability): let coordinators add and clear past leave - #401

Merged
lowicz merged 6 commits into
mainfrom
fm/oncall-leave-u-step3
Dec 2, 2026
Merged

lowicz merged 6 commits into
mainfrom
fm/oncall-leave-u-step3

Conversation

@lowicz

@lowicz lowicz commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Intent

The oncall project gained a new preference kind "U" (urlop, leave). The captain approved a 5-step plan; steps 1 (PR 399) and 2 (PR 400, panel Urlopy) are merged. This is STEP 3: past leave (D7-B, with D12-A): a coordinator or admin, entering on behalf with the U brush, can add leave in the past up to 12 months back, also for themself; the entry is shown to the team with the tag "dopisany po fakcie". The approved design and decisions are in the scout report (sections 4.5, 5 D7 and D12, 6.2 step 3, 9, 11), with the critique evidence beside it. Leave is team-visible only as "urlop", never with a reason or note (D14).

What those sections of the approved design say, in substance:

  • D7, chosen option B: coordinators and admins may add or correct U in the past; members cannot change their own past. It applies to U only. Reason given: leave days, like N, lower a person's expected share in the 12-month fairness window, so whoever can add leave in the past changes a fairness balance. Options not chosen: nothing in the past at all (A), and everyone correcting their own U up to 30 days back (C).
  • D12, chosen option A: a coordinator may add past leave for themself as well; it is allowed and visible. Every past entry is in the audit and is shown to the team as "dopisany po fakcie" with who and when, taken from the entry itself so it survives audit retention. Options not chosen: a coordinator cannot do it for themself (B), only admins add past leave (C).
  • D14, chosen option A: "urlop" is any whole day away from work; the team sees only "urlop", never a reason, and the app does not ask for one.
  • Section 4.5, past leave: a coordinator or admin, entering on behalf with the U brush, can paint past days up to 12 months back (the fairness window). The other brushes keep past days disabled, and the line under the calendar says why: "Urlop można dopisać także wstecz, do 12 miesięcy. Pozostałe wpisy tylko od dziś." A member's own past stays closed, with "Dni, które minęły, poprawia koordynator." A past day on which the person has a served duty is refused: "18 lis: w tym dniu jest odbyty dyżur (PRIMARY). Urlopu nie da się tu dopisać. Najpierw popraw obsadę tego dnia w grafiku." Saving says what it changes: "Zmieni to oczekiwany udział tej osoby w oknie 12 miesięcy." No collision e-mail for past days. The entry is shown to the team as "dopisany po fakcie · Anna Kowalska, 2 gru", derived from created_at and created_by_user_id on the availability row, not from the audit trail, which expires. Past leave tiles render at full opacity in this mode. A coordinator may do this for themself as well (D12-A); the tag is what keeps it honest.
  • Section 6.2, step 3: the rule that refuses an entry in the past gets one exception: kind leave, actor coordinator or admin, at most 12 months back, no served duty of that person on the day. No collision e-mail for past days. Frontend: past tiles enabled for the U brush in on-behalf mode, the "dopisany po fakcie" tag from created_at and created_by_user_id (the calendar payload gains those fields for leave entries). Docs: the generator page (fairness) and the availability page, in both languages.
  • Sections 9 and 11: the captain answered D7 with B in round 1 and D12 with A in round 2, both as recommended, and ended the review of the complete design with "ok". The UX/CX assessment added the guards that are part of the approved design: the U brush only, 12 months and no further, refusal on a served-duty day (the assignment is corrected first), the fairness sentence at the moment of saving, the reason said under the calendar for days that are closed, the refusal for a past day as an alert, and the tag.
  • Because D7-B says "add or correct", a leave added in the past can also be taken back: a coordinator or admin can clear a leave from past days with the eraser, U only (other kinds on past days stay as they are), and the lines under the calendar say what is true.

Steps 4 (overlap warning) and 5 (morning e-mail) are separate later work and are not part of this change.

What Changed

  • Past leave rules (API): coordinators and admins can add or clear leave, for others or for themselves, up to 12 months back. All other changes to past days are refused, including deleting an entry that began before today and a member's Undo that would change a past day. When a coordinator clears a range, only leave comes off its past days. Adding leave on a day when the person served a duty returns 409, naming the day and the role. Past days trigger no collision e-mail, and the on-behalf e-mail for past leave tells the person to contact a coordinator.
  • "Dopisany po fakcie" tag: leave written after its first day shows this tag in the Schedule day panel, with who wrote it and when. The calendar API returns this as backfilled_by and backfilled_on, read from the entry itself so it outlasts the audit trail. Cutting an entry or undoing a change keeps its original date. The audit summary for past leave says "dopisany po fakcie" too.
  • Availability calendar and docs: for coordinators and admins, the leave brush opens past days, and the eraser opens only past days that hold leave. A line under the calendar explains which past days are closed. Saving or clearing past leave says the expected share in the 12-month window changes, and a served-duty refusal appears as an alert. The Polish and English docs describe these rules.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The server enforces the past-day rule on every way of writing availability (create, paint, erase, delete, undo), it matches the approved design, and the last fix is one small focus check with a test that would fail without it.

Testing

I ran the built app with its real API, worker, PostgreSQL and a test mail server, and drove it in Chromium as coordinator, admin and member, on desktop and phone. I also tried to break the rules through the API. Everything passed, with screenshots, logs and e-mail texts saved. No existing test suite was run in this step. Two limits: the window-switch check used simulated blur events, and the author and time of restored leave were read from printed database and API values, because that check in the script could not fail. The first run of the desktop script stopped on a wrong column name in the script; I fixed it and reran on clean data.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Coordinator adds past leave for Anna: it is saved, the fairness sentence shows, and Anna's expected share changes ✅ pass live ui.log A2, A3, B1-B4 (expected share 9.5 to 9.44); 03-past-leave-saved.png
Limits: the other three brushes keep past days closed, and leave reaches back exactly 12 months (365 days works, 366 is refused) ✅ pass live ui.log A1, A4; ui2.log H1-H4, H6, H7; 02-twelve-month-boundary.png
Leave on a day with a served duty is refused with an alert, and nothing is saved ✅ pass live ui.log C1, C2; ui2.log H5; 04-served-duty-refused.png; 13-english-refusal.png
A coordinator adds past leave for themself, and an admin outside the rotation adds it for someone else ✅ pass live ui2.log G1, G2; 07-coordinator-own-past-leave.png
A teammate sees 'dopisany po fakcie · Marek Nowak, 3 gru' and no note, even with an empty audit trail ✅ pass live ui2.log L1, L2; ui3.log M0-M2; 09-team-tag.png; 10-team-tag-phone.png
A member cannot change their own past, in the screen or through the API ✅ pass live ui2.log J1-J10; 08-member-past-closed.png
Eraser clears only leave from past days, and Undo puts back exactly what was there ✅ pass live ui.log E1-E4b; ui2.log I1-I5 and the creation times printed on the I6 lines; 05-eraser-only-leave-open.png; 06-eraser-toast.png
Changing the brush cannot drag another kind back into the past (Shift+click, and two taps on a phone) ✅ pass live ui.log D1, D2; ui3.log N1-N3; 11-phone-first-tap.png; 12-phone-past-leave-saved.png
Keyboard keeps working after the eraser closes a day, also after the window loses focus ✅ pass live ui.log F1, F2
E-mails: past leave sends no duty-collision e-mail, and the member is told only to contact a coordinator ✅ pass live ui2.log K1, K2; emails.txt
Availability and generator documentation pages describe past leave in Polish and English ✅ pass live ui3.log P lines; 14-docs-past-leave.png

Leave brush opens past days

12-month limit: 2 Dec 2025 closed, 3 Dec 2025 open

Past leave saved, with the fairness sentence

Day with a served duty refused

Eraser opens only past days with leave

Message after clearing past leave, with Undo

Coordinator's own past leave

Member's past is closed

Team sees the tag

Team sees the tag on a phone

Phone: first tap on a past day

Phone: past leave saved

Refusal in English

Documentation section on past leave

Evidence: Coordinator desktop log
PASS - A1 brush "nie mogę" leaves all of November closed 
PASS - A1 brush "wolę nie" leaves all of November closed 
PASS - A1 brush "chętnie" leaves all of November closed 
PASS - A2 leave brush opens all 30 passed days 
PASS - A3 line under calendar 
PASS - A4 12 months: 02-12-2025 closed, 03-12-2025 open 03-12-2025
PASS - B1 fairness sentence shown on save 
PASS - B2 row stored leave 2026-11-09 2026-11-11
PASS - B3 passed leave tile at full opacity 
PASS - B4 expected share changed 
   before {"oncall":{"actual":2,"expected":9.5,"deviation":-7.5}}
   after  {"oncall":{"actual":2,"expected":9.44,"deviation":-7.44}}
audit: availability.created_on_behalf | Marek Nowak w imieniu Anna Kowalska: urlop 2026-11-09 – 2026-11-11, dopisany po fakcie
PASS - C1 served duty refused as alert "Nie dopisano urlopu: 17 – 19 lis\n18-11-2026: w tym dniu jest odbyty dyżur (PRIMARY). Urlopu nie da się tu dopisać. Najpierw popraw obsadę tego dnia w grafiku."
PASS - C2 nothing saved, no saved box 
PASS - D1 single passed day saved 
PASS - D2 Shift after brush change does not reach back to the passed day leave 2026-11-09 2026-11-11; leave 2026-11-24 2026-11-24; unavailable 2026-12-10 2026-12-10
PASS - E1 eraser opens only passed leave days 09-11-2026,10-11-2026,11-11-2026,24-11-2026
PASS - E2 eraser clears the passed leave, the rest stays leave 2026-11-11 2026-11-11; unavailable 2026-11-12 2026-11-13; leave 2026-11-24 2026-11-24; unavailable 2026-12-10 2026-12-10
PASS - E3 toast says the share changes 
after undo: leave 2026-11-09 2026-11-10; leave 2026-11-11 2026-11-11; unavailable 2026-11-12 2026-11-13; leave 2026-11-24 2026-11-24; unavailable 2026-12-10 2026-12-10
PASS - E4 Undo brings the days back 2026-11-09,2026-11-10,2026-11-11,2026-11-24
PASS - E4b 2-day "nie mogę" untouched 
PASS - F1 focus stays on the day just cleared pon 09-11-2026
PASS - F2 arrow moves on after a window blur wt 10-11-2026, Urlop, notatka: TAJNA-NOTATKA, wpis: Marek Nowak
Evidence: Guards, API and team data log
PASS - G1 coordinator adds own past leave leave 2026-11-20 2026-11-20
PASS - G2 admin adds past leave for someone leave 2026-10-06 2026-10-06
PASS - H1 coordinator: leave 366 days back refused 422 {"detail":"Urlop można dopisać albo usunąć najwyżej 12 miesięcy wstecz"}
PASS - H2 coordinator: leave from 366 days back to today refused 422 {"detail":"Urlop można dopisać albo usunąć najwyżej 12 miesięcy wstecz"}
PASS - H3 coordinator: past unavailable refused 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - H4 coordinator: unavailable from past to future refused 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - H3 coordinator: past prefer refused 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - H4 coordinator: prefer from past to future refused 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - H3 coordinator: past prefer_not refused 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - H4 coordinator: prefer_not from past to future refused 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - H5 coordinator: leave straddling a served duty to future refused 409 {"detail":"18-11-2026: w tym dniu jest odbyty dyżur (PRIMARY). Urlopu nie da się tu dopisać. Najpierw popraw obsadę tego dnia w grafiku."}
PASS - H6 refusals changed nothing 
PASS - H7 exactly 365 days back accepted 200 {"id":"5de5bfaf-fac4-4b10-a17d-07b425bed12b","kind":"leave","starts_on":"2025-12-03","ends_on":"2025-12-03","note":null,"created_at":"2026-12-02T23:37:25.671547Z","warning":null,"created_by_name":"Mar
PASS - I1 clear mixed range 200 null
PASS - I2 only leave went leave 2025-12-03 2025-12-03; unavailable 2026-11-12 2026-11-13; unavailable 2026-12-10 2026-12-10
PASS - I3 undo 204 
PASS - I4 undo restores exactly leave 2025-12-03 2025-12-03; leave 2026-11-10 2026-11-10; leave 2026-11-11 2026-11-11; unavailable 2026-11-12 2026-11-13; leave 2026-11-24 2026-11-24; unavailable 2026-12-10 2026-12-10
   audit tail:
   Administrator w imieniu Piotr Zieliński: urlop 2026-10-06 – 2026-10-06, dopisany po fakcie
   Marek Nowak w imieniu Anna Kowalska: urlop 2025-12-03 – 2025-12-03, dopisany po fakcie
   Marek Nowak w imieniu Anna Kowalska: usunięto „urlop” 2026-11-10 – 2026-11-10
   Marek Nowak w imieniu Anna Kowalska: usunięto „urlop” 2026-11-11 – 2026-11-11
   Marek Nowak w imieniu Anna Kowalska: usunięto „urlop” 2026-11-24 – 2026-11-24
   Marek Nowak w imieniu Anna Kowalska: przywrócono „urlop” 2026-11-10 – 2026-11-10
   Marek Nowak w imieniu Anna Kowalska: przywrócono „urlop” 2026-11-11 – 2026-11-11
   Marek Nowak w imieniu Anna Kowalska: przywrócono „urlop” 2026-11-24 – 2026-11-24
PASS - I5 audit never claims the past "nie mogę" was touched 
PASS - I6 restored leave keeps author and moment 2025-12-03 2026-12-02 23:37:25.671547+00
2026-11-10 2026-12-02 23:36:29.858075+00
2026-11-11 2026-12-02 23:36:29.858075+00
2026-11-24 2026-12-02 23:36:33.108906+00
PASS - I7 shorten a planned leave by its first day 200 null
PASS - J1 member, "nie mogę": all passed days closed 
PASS - J1 member, "urlop": all passed days closed 
PASS - J1 member, "wolę nie": all passed days closed 
PASS - J1 member, "chętnie": all passed days closed 
PASS - J1 member, "clear": all passed days closed 
PASS - J2 member reads who corrects passed days 
PASS - J3 member API: past leave 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - J4 member API: leave past to future 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - J5 member API: paint prefer over past leave 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - J6 member API: clear past leave 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - J7 member API: DELETE past leave 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - J8 member API: entry for someone else 403 {"detail":"Nie masz uprawnień do tej operacji"}
PASS - J9 member API: POST past leave 422 {"detail":"Dostępności nie można zmieniać w dniach, które minęły"}
PASS - J10 nothing changed 
PASS - K1 leave straddling today 200 {"id":"f2f85545-ea68-4c25-841f-a244936d07ad","kind":"leave","starts_on":"2026-12-01","ends_on":"2026-12-04","note":null,"created_at":"2026-12-02T23:37:29.846514Z","warning":"Anna Kowalska ma w tym cza
PASS - K2 leave only in past 200 {"id":"302a17d6-9d6b-4d04-96cd-5c922af99c41","kind":"leave","starts_on":"2026-11-26","ends_on":"2026-11-27","note":null,"created_at":"2026-12-02T23:37:29.869990Z","warning":null,"created_by_name":"Mar
   outbox:
sent | availability_created_on_behalf | Wpisano urlop w Twoim imieniu: 09-11-2026 – 11-11-2026
sent | availability_created_on_behalf | Wpisano urlop w Twoim imieniu: 24-11-2026 – 24-11-2026
sent | availability_duty_conflict | Niedostępność koliduje z dyżurem: Anna Kowalska
sent | availability_duty_conflict | Niedostępność koliduje z dyżurem: Anna Kowalska
sent | availability_created_on_behalf | Zgłoszono dostępność w Twoim imieniu: 10-12-2026 – 10-12-2026
claimed | availability_created_on_behalf | Wpisano urlop w Twoim imieniu: 06-10-2026 – 06-10-2026
claimed | availability_created_on_behalf | Wpisano urlop w Twoim imieniu: 03-12-2025 – 03-12-2025
claimed | availability_duty_conflict | Urlop koliduje z dyżurem: Anna Kowalska
claimed | availability_duty_conflict | Urlop koliduje z dyżurem: Anna Kowalska
claimed | availability_created_on_behalf | Wpisano urlop w Twoim imieniu: 01-12-2026 – 04-12-2026
claimed | availability_created_on_behalf | Wpisano urlop w Twoim imieniu: 26-11-2026 – 27-11-2026
   team payload: [{"entry_starts_on":"2026-11-26","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Marek Nowak"},{"entry_starts_on":"2026-12-01","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Marek Nowak"},{"entry_starts_on":"2026-11-24","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Marek Nowak"},{"entry_starts_on":"2026-11-11","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Marek Nowak"},{"entry_starts_on":"2026-11-10","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Marek Nowak"},{"entry_starts_on":"2026-11-20","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Marek Nowak"},{"entry_starts_on":"2026-11-03","note":null,"backfilled_on":null,"backfilled_by":null},{"entry_starts_on":"2026-10-06","note":null,"backfilled_on":"2026-12-03","backfilled_by":"Administrator"}]
PASS - L1 team payload carries no note 
PASS - L2 a planned leave, shortened later, has no tag 
   grafik url http://localhost:4173/grafik []
Evidence: Tag, phone, English and docs log
PASS - M0 audit trail has no availability entries, as after retention 
PASS - M1 09-team-tag: tag "dopisany po fakcie - Marek Nowak, 3 gru" 
PASS - M2 09-team-tag: no note on screen 
   [
  'na urlopie',
  'Urlop',
  'Urlop',
  'Urlop',
  'Urlop',
  'Urlop',
  'Marek Nowak: Urlop (20 lis)',
  'dopisany po fakcie · Marek Nowak, 3 gru'
]
PASS - M1 10-team-tag-phone: tag "dopisany po fakcie - Marek Nowak, 3 gru" 
PASS - M2 10-team-tag-phone: no note on screen 
   [
  'Na urlopie: Marek Nowak',
  'Na urlopie: Anna Kowalska',
  'Na urlopie: Anna Kowalska',
  'Na urlopie: Anna Kowalska',
  'Urlop',
  'Marek Nowak: Urlop (20 lis)',
  'dopisany po fakcie · Marek Nowak, 3 gru'
]
PASS - N1 phone: the passed first tap is dropped with the brush, nothing saved yet leave 2025-12-03 2025-12-03; leave 2026-11-10 2026-11-10; leave 2026-11-11 2026-11-11; unavailable 2026-11-12 2026-11-13; leave 2026-11-24 2026-11-24; leave 2026-11-26 2026-11-27; leave 2026-12-01 2026-12-04; unavailable 2026-12-10 2026-12-10
PASS - N2 phone: the range then holds the future day only 2026-12-04; unavailable 2026-12-10 2026-12-10; unavailable 2026-12-18 2026-12-18
PASS - N3 phone: two taps save a past leave 
   EN: ["26","L","27","L","28","29","30","Click a day or drag across several. We save straight away. Shift+click or Shift+Enter marks a range. Legend","Leave can also be added, or removed with the eraser, for past days, up to 12 months back. Other entries only from today.","Filing on behalf of: Anna Kowalska · they will be notified and can remove the entry from days that have not passed.","Leave not added: Wed 18 Nov","18-11-2026: a duty was served on this day (PRIMARY). Leave cannot be added here. Correct who held this day in the schedule first."]
PASS - O1 English refusal 
PASS - P /docs/uzytkownik/dostepnosc documents past leave 
PASS - P /docs/produkt/generator documents past leave 
PASS - P /docs/en/uzytkownik/dostepnosc documents past leave 
PASS - P /docs/en/produkt/generator documents past leave 
Evidence: E-mails received
To: anna@example.com | Subject: Wpisano urlop w Twoim imieniu: 26-11-2026 – 27-11-2026
Marek Nowak zapisał(a) w Twoim imieniu: „urlop” od 26-11-2026 do 27-11-2026.

Jeśli to się nie zgadza, skontaktuj się z koordynatorem.

Moja dostępność: http://localhost:4173/#moje

----------------------------------------
To: marek@example.com | Subject: Urlop koliduje z dyżurem: Anna Kowalska
Anna Kowalska wpisał(a) urlop obejmujący istniejące dyżury:
- czw 03-12-2026 · PRIMARY

Sprawdź grafik i uzgodnij zmianę obsady: http://localhost:4173/

----------------------------------------
To: admin@example.com | Subject: Urlop koliduje z dyżurem: Anna Kowalska
Anna Kowalska wpisał(a) urlop obejmujący istniejące dyżury:
- czw 03-12-2026 · PRIMARY

Sprawdź grafik i uzgodnij zmianę obsady: http://localhost:4173/

----------------------------------------

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • 🚨 backend/src/oncall/domain/availability/use_cases.py:74 - The rule that closes past days only checks ranges that END before today (if ends_on < today:). A range that starts in the past and ends today or later skips all three checks: kind, role and 12 months. This contradicts the intent: "applies to U only", "members cannot change their own past", "The other brushes keep past days disabled".

Reachable in the UI: a coordinator paints leave on 10 Nov, so lastPainted holds that past day. They switch to "nie mogę" and Shift+click (or Shift+Enter) 8 Dec. The save is 10 Nov - 8 Dec unavailable. It ends in the future, so the server accepts it. It overwrites every past entry in between, including leave and its "dopisany po fakcie" tag, and changes the expected share. The phone flow does the same: tap a past day with the leave brush, switch brush, tap a future day.

Reachable by API: a member sends PUT /availability/me/range with kind=leave from 300 days ago to today, or paints kind=prefer over their own past leave.

Other places with the same gap:

  • use_cases.py:240 _cut_range via cleared_from: any painted kind cuts past days (date.min).
  • use_cases.py:298 withdraw_availability: DELETE /availability/me/{id} has no past check, so a member can delete a past leave a coordinator added. A coordinator can delete past entries of other kinds, or ones older than 12 months.
  • Mine.tsx:333 and Mine.tsx:352: the Shift anchor is not checked against the current brush.
  • Mine.tsx:345-346: the phone pick anchor survives a brush change.
  • 12-month limit: today-366..today passes (MAX_ENTRY_DAYS is 366), one day too far.

Remedy: in _validate_range, test starts_on < today for painted kinds, keep today's clamping for clears, and apply the same rule in withdraw. In the UI, drop an anchor that is closed for the current brush. Two new tests deliberately keep the ranges that start in the past (test_a_served_duty_is_not_a_collision_to_announce, test_an_entry_written_ahead_of_its_first_day_carries_no_mark), so the author must confirm.

  • ⚠️ backend/src/oncall/domain/availability/use_cases.py:205 - When clearing, _cut_range now leaves past days of other kinds alone, but it still returns every overlapping entry. The snapshot (line 258) therefore stores the untouched parts too, and the undo (line 291) cuts the whole range with no kept_before.

Example: a coordinator erases 1-4 Nov, where 1 and 4 Nov are leave and 2-3 Nov are "nie mogę". The clear leaves 2-3 Nov alone. Pressing Undo then deletes and re-creates those two days and writes audit entries saying the coordinator removed ("usunięto") and restored ("przywrócono") a past "nie mogę" they never touched. An untouched entry that extends beyond the stroke is also split into up to three rows.

Fix: make the undo act only on what the stroke cut, for example by not cutting or re-recording entries the stroke left in place. Assert the audit rows after Undo: the existing undo test checks only the final list.

  • ⚠️ frontend/src/screens/Mine.tsx:808 - The "Zapisano … / Zmieni to oczekiwany udział" box does not depend on the save having succeeded. It appears whenever some confirmed leave already covers the painted range (savedLeave, line 692).

Example: Beata has leave 10-20 Nov but still served a duty on 13 Nov. A coordinator repaints 12-14 Nov with leave, for example to add a note. The server answers 409. The screen then shows both "Nie dopisano urlopu: 12-14 lis" and "Zapisano: 12-14 lis", plus the claim that the share changes. After any other failure the box likewise stays next to the error toast. While the save is still running it already says "saved".

Fix: clear paintedLeave in the paint's onError, or set it only on success. The weekend offer just below uses the same value.

  • ⚠️ backend/src/oncall/infrastructure/sqlalchemy/availability.py:188 - The on-behalf e-mail is now also sent for leave added in the past. Its text still tells the member to open "Moja dostępność" and remove the entry ("usuń wpis albo skontaktuj się z koordynatorem", notifications/templates.py:751 and 781). For past days the member cannot do that: their calendar is closed and the range endpoint refuses. The change corrected the same sentence under the calendar (onBehalfAfter) and in the docs, but not in the e-mail. Decide the wording: for past leave, say only "contact a coordinator".
  • ℹ️ backend/src/oncall/domain/calendar/models.py:103 - Tradeoff of reading the tag from the row: repainting a leave that was planned in advance makes it look added after the fact. Example: Anna's leave 30 Nov - 6 Dec was entered in October. On 3 Dec a coordinator drags 30 Nov - 10 Dec with the leave brush to extend it. The new row is created on 3 Dec, so the whole leave, future days included, reads "dopisany po fakcie · coordinator, 3 gru". This follows the approved derivation (created_at and created_by_user_id on the row).

🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:

  • ⚠️ frontend/src/screens/Mine.tsx:808 - The "Zapisano … / Zmieni to oczekiwany udział" box does not depend on the save having succeeded. It appears whenever some confirmed leave already covers the painted range (savedLeave, line 692).

Example: Beata has leave 10-20 Nov but still served a duty on 13 Nov. A coordinator repaints 12-14 Nov with leave, for example to add a note. The server answers 409. The screen then shows both "Nie dopisano urlopu: 12-14 lis" and "Zapisano: 12-14 lis", plus the claim that the share changes. After any other failure the box likewise stays next to the error toast. While the save is still running it already says "saved".

Fix: clear paintedLeave in the paint's onError, or set it only on success. The weekend offer just below uses the same value.

  • ℹ️ backend/src/oncall/domain/calendar/models.py:103 - Tradeoff of reading the tag from the row: repainting a leave that was planned in advance makes it look added after the fact. Example: Anna's leave 30 Nov - 6 Dec was entered in October. On 3 Dec a coordinator drags 30 Nov - 10 Dec with the leave brush to extend it. The new row is created on 3 Dec, so the whole leave, future days included, reads "dopisany po fakcie · coordinator, 3 gru". This follows the approved derivation (created_at and created_by_user_id on the row).
  • ℹ️ frontend/src/screens/Mine.tsx:331 - Keyboard focus is lost after clearing a past leave day. Example: a coordinator picks the eraser, moves with the arrow keys to 2 Sep (leave, already passed) and presses Enter. The stroke is drawn at once, so the day no longer holds a leave, closedDay (line 215) becomes true, and the focused button turns disabled. A disabled button gets no key events, so the arrow keys stop working, and the grid's only tab stop jumps to the first open day of the month. Clearing several past days one by one means re-entering the grid after each one. Before this change no stroke could close the day it was made on. Fix: after such a stroke, move focus to the nearest open day with grid.focusCell, or keep the focused day focusable with aria-disabled instead of disabled. The existing eraser tests use mouse-style clicks only and do not check focus.

🔧 Fix applied.
5 issues (1 warning, 4 infos) still open:

  • ⚠️ frontend/src/screens/Mine.tsx:808 - The "Zapisano … / Zmieni to oczekiwany udział" box does not depend on the save having succeeded. It appears whenever some confirmed leave already covers the painted range (savedLeave, line 692).

Example: Beata has leave 10-20 Nov but still served a duty on 13 Nov. A coordinator repaints 12-14 Nov with leave, for example to add a note. The server answers 409. The screen then shows both "Nie dopisano urlopu: 12-14 lis" and "Zapisano: 12-14 lis", plus the claim that the share changes. After any other failure the box likewise stays next to the error toast. While the save is still running it already says "saved".

Fix: clear paintedLeave in the paint's onError, or set it only on success. The weekend offer just below uses the same value.

  • ℹ️ backend/src/oncall/domain/calendar/models.py:103 - Tradeoff of reading the tag from the row: repainting a leave that was planned in advance makes it look added after the fact. Example: Anna's leave 30 Nov - 6 Dec was entered in October. On 3 Dec a coordinator drags 30 Nov - 10 Dec with the leave brush to extend it. The new row is created on 3 Dec, so the whole leave, future days included, reads "dopisany po fakcie · coordinator, 3 gru". This follows the approved derivation (created_at and created_by_user_id on the row).
  • ℹ️ frontend/src/screens/Mine.tsx:331 - Keyboard focus is lost after clearing a past leave day. Example: a coordinator picks the eraser, moves with the arrow keys to 2 Sep (leave, already passed) and presses Enter. The stroke is drawn at once, so the day no longer holds a leave, closedDay (line 215) becomes true, and the focused button turns disabled. A disabled button gets no key events, so the arrow keys stop working, and the grid's only tab stop jumps to the first open day of the month. Clearing several past days one by one means re-entering the grid after each one. Before this change no stroke could close the day it was made on. Fix: after such a stroke, move focus to the nearest open day with grid.focusCell, or keep the focused day focusable with aria-disabled instead of disabled. The existing eraser tests use mouse-style clicks only and do not check focus.
  • ℹ️ frontend/src/screens/Mine.tsx:342 - The round 2 focus fix (eraser-focus-lost) misses one case: switching to another window or tab. Example: a coordinator picks the eraser, presses Enter on 2 Sep (a passed leave day) and the day closes but keeps the focus. They switch to their mail to check the next date. The browser sends a blur to the day button, onBlur sets focused to null, and the button becomes disabled. Back in the app, that button gets no key events, so the arrow keys do nothing, and the grid's tab stop has moved to the first open day. This is the same dead keyboard the fix was meant to remove. Fix: ignore a blur that only means the window lost focus, e.g. onBlur={(event) => { if (document.activeElement !== event.currentTarget) setFocused(null) }}, because on a window blur the button is still document.activeElement. Add a test that blurs the window and then uses an arrow key. Line 342 is the only place that clears focused.
  • ℹ️ backend/src/oncall/domain/availability/errors.py:42 - The design's example of the served-duty refusal starts with "18 lis:". The code prints "18-11-2026:", the project's DD-MM-RRRR date format, and the docs in both languages quote that form. The rest of the sentence matches the design. The long form also shows the year, which helps because the range reaches 12 months back. I read this as a date notation choice, not a missing behavior, so no change is needed.

🔧 Fix applied.
2 infos still open:

  • ℹ️ backend/src/oncall/domain/calendar/models.py:103 - Tradeoff of reading the tag from the row: repainting a leave that was planned in advance makes it look added after the fact. Example: Anna's leave 30 Nov - 6 Dec was entered in October. On 3 Dec a coordinator drags 30 Nov - 10 Dec with the leave brush to extend it. The new row is created on 3 Dec, so the whole leave, future days included, reads "dopisany po fakcie · coordinator, 3 gru". This follows the approved derivation (created_at and created_by_user_id on the row).
  • ℹ️ backend/src/oncall/domain/availability/errors.py:42 - The design's example of the served-duty refusal starts with "18 lis:". The code prints "18-11-2026:", the project's DD-MM-RRRR date format, and the docs in both languages quote that form. The rest of the sentence matches the design. The long form also shows the year, which helps because the range reaches 12 months back. I read this as a date notation choice, not a missing behavior, so no change is needed.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 11 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Coordinator adds past leave for Anna: it is saved, the fairness sentence shows, and Anna's expected share changes ✅ pass live ui.log A2, A3, B1-B4 (expected share 9.5 to 9.44); 03-past-leave-saved.png
Limits: the other three brushes keep past days closed, and leave reaches back exactly 12 months (365 days works, 366 is refused) ✅ pass live ui.log A1, A4; ui2.log H1-H4, H6, H7; 02-twelve-month-boundary.png
Leave on a day with a served duty is refused with an alert, and nothing is saved ✅ pass live ui.log C1, C2; ui2.log H5; 04-served-duty-refused.png; 13-english-refusal.png
A coordinator adds past leave for themself, and an admin outside the rotation adds it for someone else ✅ pass live ui2.log G1, G2; 07-coordinator-own-past-leave.png
A teammate sees 'dopisany po fakcie · Marek Nowak, 3 gru' and no note, even with an empty audit trail ✅ pass live ui2.log L1, L2; ui3.log M0-M2; 09-team-tag.png; 10-team-tag-phone.png
A member cannot change their own past, in the screen or through the API ✅ pass live ui2.log J1-J10; 08-member-past-closed.png
Eraser clears only leave from past days, and Undo puts back exactly what was there ✅ pass live ui.log E1-E4b; ui2.log I1-I5 and the creation times printed on the I6 lines; 05-eraser-only-leave-open.png; 06-eraser-toast.png
Changing the brush cannot drag another kind back into the past (Shift+click, and two taps on a phone) ✅ pass live ui.log D1, D2; ui3.log N1-N3; 11-phone-first-tap.png; 12-phone-past-leave-saved.png
Keyboard keeps working after the eraser closes a day, also after the window loses focus ✅ pass live ui.log F1, F2
E-mails: past leave sends no duty-collision e-mail, and the member is told only to contact a coordinator ✅ pass live ui2.log K1, K2; emails.txt
Availability and generator documentation pages describe past leave in Polish and English ✅ pass live ui3.log P lines; 14-docs-past-leave.png
  • Built the frontend with npm run build and ran it with vite preview. Behind it ran the real API (uvicorn oncall.main:app), the real oncall.worker, a throwaway PostgreSQL 18.7 and a throwaway mail server (Mailpit).
  • Set up data with alembic upgrade head, python -m oncall.seed_demo and seed-past.sql (made-up past duties; Marek made coordinator).
  • node ui.mjs: coordinator in desktop Chromium - leave brush, 12-month limit, served-duty refusal, Shift+click, eraser, Undo, keyboard focus.
  • node ui2.mjs: coordinator's own leave, admin, member's closed past, direct API attempts to break the rules, queued e-mails, what the team API returns.
  • node ui3.mjs: team tag on desktop and phone with an empty audit trail, phone taps, English refusal, built documentation pages.
  • python3 -I emails.py: read the e-mails that Mailpit received.
  • Looked by eye at the screenshots of the saved leave, refusal, eraser, toast, team tag and phone views.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A coordinator or an admin, with the leave brush, can write a leave on days
that have passed, for anyone including themself, as far back as the
12-month fairness window. Every other kind, the eraser and a member's own
past stay closed, and the line under the calendar says why.

- A leave is refused on a passed day with a served duty of that person;
  the refusal names the day and its roles and stays under the calendar.
- A duty on a passed day is never a collision to announce, so no e-mail
  goes out for it.
- The team reads 'dopisany po fakcie', who and when, in the day panel. It
  is derived from the entry's created_at and author, so it outlives the
  audit trail; the calendar payload gains backfilled_on and backfilled_by.
- A piece cut from an entry keeps the moment the entry was written, so
  clearing part of a leave never makes the rest look written afterwards.
- The audit summary of such a leave says 'dopisany po fakcie'.
- The save says it changes the expected share in the 12-month window.

Docs in both languages; the person select gains a name attribute.
Adding a leave after the fact had no way back once the Undo window closed.
A coordinator or an admin can now clear one with the eraser, as far back as
the same 12-month window.

- The eraser reaches into days that have passed only for a leave: a stroke
  that also covers other entries leaves their passed days as they are, on
  the server and in what the calendar draws while the save runs.
- With the eraser picked, only the passed days that hold a leave open.
- The toast of such a clear says it changes the expected share too.
- The lines under the calendar say what is true: leave can be added or
  removed for past days, and the person can remove an entry only from days
  that have not passed.

Docs in both languages.
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@lowicz
lowicz merged commit c2fb32f into main Dec 2, 2026
18 checks passed
@lowicz
lowicz deleted the fm/oncall-leave-u-step3 branch December 2, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant