Skip to content

feat: Assign event types to availability rules - #248

Merged
shockalotti merged 5 commits into
Calnode:mainfrom
kpalang:feature/assign-availability-rules
Nov 17, 2026
Merged

shockalotti merged 5 commits into
Calnode:mainfrom
kpalang:feature/assign-availability-rules

Conversation

@kpalang

@kpalang kpalang commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

This PR adds a dropdown to assign events to the availability blocks.

Given the following availability rules:
availability

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

The event type Mondays only receives slots on Monday from 1600 to 1700;
mondays

The event type Wednesdays only receives slots on Wednesdays from 1600 to 1700;
wednesdays

The event type Weekends receives slots on Saturday and Sunday from 1600 to 1700;
weekends

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@kpalang kpalang changed the title Feature/assign availability rules Assign event types to availability rules Nov 11, 2026
@kpalang

kpalang commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Nov 11, 2026
@kpalang kpalang changed the title Assign event types to availability rules feat: Assign event types to availability rules Nov 11, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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} accepts event_type_id, with the literal string "null" meaning "clear it (make the rule global)", and the row pre-read switched from sql.NullString to the existing *string field on availRuleJSON.
  • Event-type picker in the admin availability page — each weekly block gains a third Select listing the user's event types plus "All", loaded from /v1/event-types on mount and saved through the existing updateBlock.
  • Note the schema, the UNIQUE index, slot generation (loadHostSchedule) and POST /v1/availability-rules already supported event_type_id, so the new surface area really is just these two paths.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/handler/availability.go Resolved
Comment thread internal/handler/availability.go Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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_week in the rule create body — addBlock sends 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 — eventTypes is now a $state array assigned from a mapped array rather than a plain let mutated with push, so the picker lists real names even when /v1/event-types resolves after the weekly grid renders (frontend/src/routes/availability/+page.svelte:278-289).

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

@shockalotti

Copy link
Copy Markdown
Contributor

Heads up: your CI runs are failing to start, and it is not your code. Every workflow on this PR ended in startup_failure with zero jobs, including on a rerun. I checked the usual causes and none apply: the PR merges cleanly, the workflows at the merge ref pass actionlint, and GitHub is reporting operational. So the runs never initialised.

Two things on our side, so you are not waiting on silence:

  • I approved the fork runs (they need maintainer approval because of the first-time-contributor policy), and the approvals did not help. The edited job names showed up for the pullfrog bot, which is a different app and works.
  • That leaves a stale run queue as the likely cause, which only a new commit clears.

Could you rebase onto current main and push? That does two useful things at once: it creates fresh runs that should start properly, and your branch is 5 commits behind, including a Go toolchain security bump and the Node 26 move.

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.

@kpalang
kpalang force-pushed the feature/assign-availability-rules branch from d243936 to 0409605 Compare November 12, 2026 21:17
@kpalang kpalang closed this Nov 12, 2026
@kpalang kpalang reopened this Nov 12, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — addBlock sends day_of_week again and eventTypes is a $state array assigned from map, so both earlier findings are fixed (re-applied here by the rebase).
  • Added a MakeCommerce payment client — a new internal/makecommerce package implements the Stripe-shaped surface (New, CreateCheckoutSession, GetCheckoutSession, Refund, VerifyWebhook), and every import of internal/stripe now points at it.
  • Rewrote checkout, webhook and refund wiring — checkout carries a per-transaction NotificationURL with ?booking_id=, and the webhook reads that parameter while verifying a form-encoded MAC.
  • Added an unconditional client-IP resolver — server.ClientIP and a duplicate handler.clientIP read forwarded headers, and the access log now records that value.
  • Forced et-EE formatting — book.html and embed.js stop using the resolved locale for times and weekdays.
  • Smaller changes — Europe/Tallinn added to TIMEZONES and 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread internal/makecommerce/makecommerce.go Resolved
Comment thread internal/handler/stripe_booking.go Resolved
Comment thread internal/makecommerce/makecommerce.go Resolved
Comment thread internal/makecommerce/makecommerce.go Resolved
Comment thread internal/server/middleware.go Resolved
Comment thread internal/handler/templates/book.html Resolved
@kpalang
kpalang force-pushed the feature/assign-availability-rules branch from 0409605 to cedb0bf Compare November 12, 2026 21:45

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 match main again.
  • Reverted the forced et-EE formatting — book.html and embed.js format with the request's resolved locale once more.
  • Reverted the unconditional client-IP resolver — server.ClientIP and the duplicate handler.clientIP are gone; TrustClientIP is the only resolver again.
  • Dropped the stray Europe/Tallinn timezone and the booking-card CSS tweak — prefs.ts and booking.css match main.

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.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 JSON null — PATCH /v1/availability-rules/{id} now decodes event_type_id as json.RawMessage, so an omitted key leaves the assignment alone, null clears 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 / allEventTypes were added to both admin catalogues and used for the trigger text, the "all" item and the new "Applies to:" label; pnpm check:i18n and svelte-check both pass.
  • Inverted the client-side conversion — updateBlock maps the UI's internal "null" value to a real null in the request body rather than the other way round, which matches the new server contract.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment on lines +155 to 163
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kpalang

kpalang commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@shockalotti I might need those workflow approvals again.

@shockalotti
shockalotti merged commit eb67e2d into Calnode:main Nov 17, 2026
9 checks passed
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.

2 participants