Repository navigation
feat(availability): let coordinators add and clear past leave - #401
Merged
Merged
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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:
Steps 4 (overlap warning) and 5 (morning e-mail) are separate later work and are not part of this change.
What Changed
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.backfilled_byandbackfilled_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.🤖 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.
Evidence: Coordinator desktop log
Evidence: Guards, API and team data log
Evidence: Tag, phone, English and docs log
Evidence: E-mails received
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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
lastPaintedholds that past day. They switch to "nie mogę" and Shift+click (or Shift+Enter) 8 Dec. The save is 10 Nov - 8 Decunavailable. 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:
_cut_rangeviacleared_from: any painted kind cuts past days (date.min).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.Remedy: in
_validate_range, teststarts_on < todayfor 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_rangenow 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 nokept_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
paintedLeavein the paint'sonError, 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
paintedLeavein the paint'sonError, 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 turnsdisabled. 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 withgrid.focusCell, or keep the focused day focusable witharia-disabledinstead ofdisabled. 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
paintedLeavein the paint'sonError, 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 turnsdisabled. 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 withgrid.focusCell, or keep the focused day focusable witharia-disabledinstead ofdisabled. 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,onBlursetsfocusedto null, and the button becomesdisabled. 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 stilldocument.activeElement. Add a test that blurs the window and then uses an arrow key. Line 342 is the only place that clearsfocused.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.
Built the frontend withnpm run buildand ran it withvite preview. Behind it ran the real API (uvicorn oncall.main:app), the realoncall.worker, a throwaway PostgreSQL 18.7 and a throwaway mail server (Mailpit).Set up data withalembic upgrade head,python -m oncall.seed_demoandseed-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.