Repository navigation
feat: Assign event types to availability rules - #248
Conversation
|
All contributors have signed the CLA. ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Caution
This PR removes day_of_week from the POST /v1/availability-rules body in addBlock, so every rule added from the weekly grid is now written to Sunday instead of the day the user clicked.
Reviewed changes
- Event-type assignment in the API —
PATCH /v1/availability-rules/{id}acceptsevent_type_id, with the literal string"null"meaning "clear it (make the rule global)", and the row pre-read switched fromsql.NullStringto the existing*stringfield onavailRuleJSON. - Event-type picker in the admin availability page — each weekly block gains a third
Selectlisting the user's event types plus "All", loaded from/v1/event-typeson mount and saved through the existingupdateBlock. - Note the schema, the UNIQUE index, slot generation (
loadHostSchedule) andPOST /v1/availability-rulesalready supportedevent_type_id, so the new surface area really is just these two paths.
deepseek-v4.1-flash | 𝕏
There was a problem hiding this comment.
ℹ️ Delta-only re-review: both commits pushed since the last review fix findings raised there and introduce nothing new. The four threads still open on this PR remain outstanding, so this is not an approval.
Reviewed changes
- Restored
day_of_weekin the rule create body —addBlocksends the clicked weekday again, so blocks added on Mon–Sat are no longer written to Sunday (frontend/src/routes/availability/+page.svelte:79). - Made the event-type list reactive —
eventTypesis now a$statearray assigned from a mapped array rather than a plainletmutated withpush, so the picker lists real names even when/v1/event-typesresolves after the weekly grid renders (frontend/src/routes/availability/+page.svelte:278-289).
deepseek-v4.1-flash | 𝕏
|
Heads up: your CI runs are failing to start, and it is not your code. Every workflow on this PR ended in Two things on our side, so you are not waiting on silence:
Could you rebase onto current If a fresh push still fails to start, tell me and I will keep digging, because that would point at something repo-level rather than at your branch. |
d243936 to
0409605
Compare
There was a problem hiding this comment.
Caution
The new payment webhook accepts forged notifications, so anyone can mark a pending booking paid without paying. The new internal/makecommerce package also fails its own tests and cannot be configured from the admin settings page.
Reviewed changes
- Restored the weekday and made the event-type list reactive —
addBlocksendsday_of_weekagain andeventTypesis a$statearray assigned frommap, so both earlier findings are fixed (re-applied here by the rebase). - Added a MakeCommerce payment client — a new
internal/makecommercepackage implements the Stripe-shaped surface (New,CreateCheckoutSession,GetCheckoutSession,Refund,VerifyWebhook), and every import ofinternal/stripenow points at it. - Rewrote checkout, webhook and refund wiring — checkout carries a per-transaction
NotificationURLwith?booking_id=, and the webhook reads that parameter while verifying a form-encoded MAC. - Added an unconditional client-IP resolver —
server.ClientIPand a duplicatehandler.clientIPread forwarded headers, and the access log now records that value. - Forced
et-EEformatting —book.htmlandembed.jsstop using the resolved locale for times and weekdays. - Smaller changes —
Europe/Tallinnadded toTIMEZONESand the booking card vertically centred.
⚠️ The PR now carries unrelated payment-provider and locale work
The branch was rebased onto a fork main that contains a MakeCommerce payment integration, an et-EE locale change and a timezone addition. Against upstream main that is over 1,300 new lines that have nothing to do with assigning event types to availability rules, which makes the feature impossible to review, revert or cherry-pick on its own, and puts payment code behind a PR description about a dropdown. Please rebase onto upstream main (or split the payment/locale commits into their own PR) before this is merged; the findings below are in that extra code.
Technical details
# Separate the availability feature from the payment work
## Affected sites
- `internal/makecommerce/` — new package (~600 lines + ~500 test lines).
- `internal/makecommerce/makecommerce_test.go` — new.
- `internal/handler/stripe_booking.go`, `internal/handler/stripe_settings.go`, `internal/handler/handler.go`, `internal/handler/stripe_refund_test.go`
- `internal/server/server.go`, `internal/server/middleware.go`
- `internal/handler/templates/book.html`, `internal/handler/embed.js`, `internal/frontend/src/lib/prefs.ts` — locale/timezone edits, unrelated to the rule picker.
## Required outcome
The PR diff contains only the availability-rule work; the payment provider swap and the locale override land (or are abandoned) separately, with their own review and tests.deepseek-v4.1-flash | 𝕏
0409605 to
cedb0bf
Compare
There was a problem hiding this comment.
ℹ️ Delta-only re-review: the new commits delete the unrelated payment, locale and client-IP work and change nothing in the availability feature itself. The four findings from the first review are unchanged and still need addressing, so this is not an approval.
Reviewed changes
- Removed the MakeCommerce payment integration —
internal/makecommerce(implementation plus tests) and every import of it are gone, so checkout, webhook, refund and settings code matchmainagain. - Reverted the forced
et-EEformatting —book.htmlandembed.jsformat with the request's resolved locale once more. - Reverted the unconditional client-IP resolver —
server.ClientIPand the duplicatehandler.clientIPare gone;TrustClientIPis the only resolver again. - Dropped the stray
Europe/Tallinntimezone and the booking-card CSS tweak —prefs.tsandbooking.cssmatchmain.
The PR is now the two intended files (availability.go, availability/+page.svelte), and the unrelated-work section from the previous review is resolved. I re-verified the delta locally: the tree matches main apart from those two files, no makecommerce/MK_*/et-EE references remain, go build ./internal/handler and go test ./internal/handler -run Availab pass, and gofmt is clean.
ℹ️ The removed test fixture still lives in the branch's earlier history
Deleting internal/makecommerce/makecommerce_test.go takes it out of the diff, but not out of git. Commit 0409605 — the head this branch had before the rebase, still linked from this PR's timeline — contains that file with the 64-character secret and the shop UUID. Anyone who can read the repository can still fetch them by SHA, so if that key was ever live it needs rotating regardless of the file being gone.
Technical details
# Removing a file is not purging a credential
## Affected sites
- `0409605:internal/makecommerce/makecommerce_test.go` — `TestSignatureCalculation` hardcodes
`pfOsGD9o…` (64 chars) and the shop UUID `f7741ab2-7445-45f9-9af4-0d0408ef1e4c`.
- Same UUID appears in the refund's `SetBasicAuth` in `makecommerce.go` at that commit.
## Evidence
`git grep -l pfOsGD9o… 0409605` matches `0409605:internal/makecommerce/makecommerce_test.go`;
the commit is unreferenced after the rebase but still retrievable by SHA.
## Required outcome
If the key was ever live, it is rotated in MakeCommerce, and the value is treated as public.
## Suggested approach
Rotation is the load-bearing step; rewriting the PR's old commits is optional and cannot be
relied on for secrecy on a public remote.deepseek-v4.1-flash | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — the delta fixes the wire-contract problem cleanly; one minor suggestion inline.
Reviewed changes
- Replaced the
"null"string sentinel with a real JSONnull—PATCH /v1/availability-rules/{id}now decodesevent_type_idasjson.RawMessage, so an omitted key leaves the assignment alone,nullclears it, and a non-string value is rejected with 400. Verified against a live handler: assign, omit and clear all behave as intended and persist. - Translated the event-type picker —
availability.eventTypes.appliesTo/allEventTypeswere added to both admin catalogues and used for the trigger text, the "all" item and the new "Applies to:" label;pnpm check:i18nandsvelte-checkboth pass. - Inverted the client-side conversion —
updateBlockmaps the UI's internal"null"value to a realnullin the request body rather than the other way round, which matches the new server contract.
deepseek-v4.1-flash | 𝕏
| if req.EventTypeId != nil { | ||
| var etId *string | ||
| if err := json.Unmarshal(req.EventTypeId, &etId); err != nil { | ||
| h.writeError(w, http.StatusBadRequest, "event_type_id must be a string") | ||
| return | ||
| } | ||
|
|
||
| current.EventTypeID = etId | ||
| } |
There was a problem hiding this comment.
The new absent-vs-null contract has no test. json.RawMessage is the only thing keeping the three cases apart — an omitted key stays nil, while an explicit null arrives as the four-byte literal and then unmarshals to a nil *string — and that is exactly the detail a later simplification back to *string would drop while every existing test stays green. availability_rule_test.go covers start_time, end_time, day_of_week, 404, 400 and 409 for this handler, but nothing sends event_type_id.
Technical details
# Cover the absent / null / string contract on PATCH
## Affected sites
- `internal/handler/availability.go:155-163` — `json.RawMessage` plus the second `json.Unmarshal` that turns it into `*string`.
- `internal/handler/availability_rule_test.go` — `updateTimes`, `updateDayOfWeek`, `notFound`, `invalidDayOfWeek`, `invalidHHMM`, `endNotAfterStart`, `conflictWith409`; none touches `event_type_id`.
## Evidence
Probed at `fe75122`: assign `{"event_type_id":"<id>"}` → 200 with the id; `{"start_time":"10:00"}` → assignment unchanged; `{"event_type_id":null}` → 200 with `event_type_id: null`, persisted by `GET /v1/availability-rules`.
## Required outcome
All three cases pinned by tests, so the raw-message handling cannot be reduced back to `*string` (which silently reintroduces "clear does nothing") without a red test.|
@shockalotti I might need those workflow approvals again. |

This PR adds a dropdown to assign events to the availability blocks.
Given the following availability rules:

All event types receive slots on Sunday from 0600 to 0630.
The event type

Mondays onlyreceives slots on Monday from 1600 to 1700;The event type

Wednesdays onlyreceives slots on Wednesdays from 1600 to 1700;The event type

Weekendsreceives slots on Saturday and Sunday from 1600 to 1700;