Skip to content

Commit 84c0bda

Browse files
uppertoeclaude
andcommitted
still-to-try: read the Guests lines from the grant rows, not the change log
The change log is pruned at 90 days and postdates some accounts, so a household that printed a QR and sent a pass months ago was still told to try both. The three Guests lines now read the durable guest_grant rows by kind, with the log as a second opinion. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0121j6qgGwUSLGQ48jWZN98F
1 parent 0a7a04f commit 84c0bda

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

internal/server/checklist.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ func (s *Server) checklistFor(ctx context.Context, owner, user string, isPrimary
7070
{Label: "Add an email, so they are told when their rego goes on the permit", Href: "#add", Done: email},
7171
}
7272
case "guests":
73+
// The grant rows outlive the change log (pruned at 90 days, and younger than
74+
// some accounts), so each line reads the durable row first and the log only
75+
// as a second opinion.
76+
passes, printed, shown, _ := s.store.GuestGrantKinds(ctx, owner)
7377
items = []checkItem{
74-
{Label: "Show a visitor QR to someone at the door", Href: "#now", Done: did(store.ActionDoorQRShow)},
75-
{Label: "Send a guest pass to a household that visits often", Href: "#new", Done: did(store.ActionGuestCreate)},
76-
{Label: "Print a QR that pings your phone when it is used", Href: "#now", Done: did(store.ActionDoorQRCreate)},
78+
{Label: "Show a visitor QR to someone at the door", Href: "#now", Done: shown > 0 || did(store.ActionDoorQRShow)},
79+
{Label: "Send a guest pass to a household that visits often", Href: "#new", Done: passes > 0 || did(store.ActionGuestCreate)},
80+
{Label: "Print a QR that pings your phone when it is used", Href: "#now", Done: printed > 0 || did(store.ActionDoorQRCreate)},
7781
}
7882
case "settings":
7983
permits, _ := s.store.ListPermitsFor(ctx, owner)

internal/store/guests.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,18 @@ WHERE gv.grant_id = ? ORDER BY v.label, v.registration`, gc.Grant.ID)
365365
}
366366

367367
// ListGuestGrants returns the owner's grants with their cars and recipient tokens.
368+
// GuestGrantKinds counts the account's grants by kind: emailed passes, printed
369+
// (request-only) QRs and on-screen visitor QRs. The rows are durable where the
370+
// change log is pruned, so "has this household ever used X" is read from here.
371+
func (s *Store) GuestGrantKinds(ctx context.Context, owner string) (passes, printed, onScreen int, err error) {
372+
err = s.db.QueryRowContext(ctx, `
373+
SELECT COALESCE(SUM(on_screen = 0 AND request_only = 0), 0),
374+
COALESCE(SUM(request_only = 1), 0),
375+
COALESCE(SUM(on_screen = 1), 0)
376+
FROM guest_grant WHERE owner = ?`, owner).Scan(&passes, &printed, &onScreen)
377+
return
378+
}
379+
368380
func (s *Store) ListGuestGrants(ctx context.Context, owner string) ([]GuestGrantDetail, error) {
369381
rows, err := s.db.QueryContext(ctx,
370382
`SELECT id, permit_id, label, allow_overnight, enabled, created_at FROM guest_grant WHERE owner = ? AND on_screen = 0 AND request_only = 0 ORDER BY id DESC`, owner)

0 commit comments

Comments
 (0)