Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad

### Upgrading

- **API break: `is_public` is gone.** Event types now expose `visibility`
(`public` | `unlisted` | `private`) instead of the `is_public` boolean, in both REST and
MCP payloads. An external client reading `is_public` will get `undefined` and must
switch to `visibility`. Migration `00079` backfills `is_public = 0` to `private`, so
event types that were unpublished stay unbookable — nothing becomes public by
upgrading. A fourth value, `internal`, exists in the schema but cannot be set yet.

- **Back up the database before upgrading.** This release includes a migration (`00072`)
that renames two columns on `bookings` and adds one. Migrations run automatically at
boot, so the upgrade is the moment to want a restore point that predates it.
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type EventType = {
// duration on create; editable so a 45-minute meeting can still be offered on the hour.
slot_interval_minutes: number;
is_active: boolean;
is_public: boolean;
visibility: 'public' | 'unlisted' | 'private' | 'internal';
/** Show already-booked times struck through on the booking page instead of hiding
* them. Off by default: the slots endpoint is public, so this makes the host's
* booked hours visible to anyone with the link. */
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,9 @@
"active": "Active",
"inactive": "Inactive",
"listed": "Listed",
"unlisted": "Unlisted (link only)"
"unlisted": "Unlisted (link only)",
"private": "Private",
"internal": "Internal"
},
"durationSuffix": " min"
},
Expand Down Expand Up @@ -1648,7 +1650,11 @@
"showTakenWarning": "Anyone with the booking link can see which hours are taken.",
"showNextAvailable": "Show the next available time",
"showNextAvailableHint": "Adds a button above the time list, such as \"Next available: Wed, Nov 18, 10:00 AM\", that opens that day. It uses the same times a visitor can already see.",
"allowPhoneCall": "Let invitees choose a phone call by entering their number"
"allowPhoneCall": "Let invitees choose a phone call by entering their number",
"visibilityPublic": "Public (listed and bookable)",
"visibilityUnlisted": "Unlisted (link only)",
"visibilityPrivate": "Private (not bookable)",
"visibilityInternal": "Internal (not available yet)"
},
"location": {
"section": "Location",
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,9 @@
"active": "Actif",
"inactive": "Inactif",
"listed": "Répertorié",
"unlisted": "Non répertorié (lien uniquement)"
"unlisted": "Non répertorié (lien uniquement)",
"private": "Privé",
"internal": "Interne"
},
"durationSuffix": " min"
},
Expand Down Expand Up @@ -1648,7 +1650,11 @@
"showTakenWarning": "Quiconque dispose du lien de réservation peut voir quels horaires sont pris.",
"showNextAvailable": "Afficher le prochain horaire disponible",
"showNextAvailableHint": "Ajoute au-dessus de la liste des horaires un bouton, par exemple « Prochain créneau disponible : mer. 18 nov., 10:00 », qui ouvre ce jour. Il utilise les mêmes horaires que ceux déjà visibles par un visiteur.",
"allowPhoneCall": "Permettre aux invités de choisir un appel téléphonique en saisissant leur numéro"
"allowPhoneCall": "Permettre aux invités de choisir un appel téléphonique en saisissant leur numéro",
"visibilityPublic": "Public (listé et réservable)",
"visibilityUnlisted": "Non listé (lien uniquement)",
"visibilityPrivate": "Privé (non réservable)",
"visibilityInternal": "Interne (pas encore disponible)"
},
"location": {
"section": "Lieu",
Expand Down
41 changes: 32 additions & 9 deletions frontend/src/routes/event-types/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,29 @@
// Any location that produces a join link the booker has to receive somehow.
const isOnlineLocation = (t: string) => isOnlineMeeting(t) || t === 'zoom' || t === 'livekit';

// Visibility is a closed set (#272). The read-only view labels all four in case a
// row arrives with a state this build cannot set (internal, until step 2).
function visibilityLabel(v: EventType['visibility']) {
switch (v) {
case 'unlisted': return $t('eventTypeEditor.readOnly.status.unlisted');
case 'private': return $t('eventTypeEditor.readOnly.status.private');
case 'internal': return $t('eventTypeEditor.readOnly.status.internal');
default: return $t('eventTypeEditor.readOnly.status.listed');
}
}
function visibilityKey(v: EventType['visibility']) {
switch (v) {
case 'unlisted': return 'eventTypeEditor.general.visibilityUnlisted';
case 'private': return 'eventTypeEditor.general.visibilityPrivate';
case 'internal': return 'eventTypeEditor.general.visibilityInternal';
default: return 'eventTypeEditor.general.visibilityPublic';
}
}

let form = $state({
display_order: 0,
name: '', slug: '', description: '', duration_minutes: 30, slot_interval_minutes: 30,
is_active: true, is_public: true, show_taken_slots: false, show_next_available: false,
is_active: true, visibility: 'public' as EventType['visibility'], show_taken_slots: false, show_next_available: false,
invite_delivery: 'calendar' as EventType['invite_delivery'],
location_type: 'link', location_value: '',
buffer_before_minutes: 0, buffer_after_minutes: 0,
Expand Down Expand Up @@ -334,7 +353,7 @@
duration_minutes: et.duration_minutes,
slot_interval_minutes: et.slot_interval_minutes,
is_active: et.is_active,
is_public: et.is_public,
visibility: et.visibility,
show_taken_slots: et.show_taken_slots ?? false,
show_next_available: et.show_next_available ?? false,
invite_delivery: et.invite_delivery ?? 'calendar',
Expand Down Expand Up @@ -396,7 +415,7 @@
duration_minutes: Number(form.duration_minutes),
slot_interval_minutes: Number(form.slot_interval_minutes),
is_active: form.is_active,
is_public: form.is_public,
visibility: form.visibility,
show_taken_slots: form.show_taken_slots,
show_next_available: form.show_next_available,
invite_delivery: form.invite_delivery,
Expand Down Expand Up @@ -614,7 +633,7 @@
{/if}
<dt class="text-muted-foreground">{$t('eventTypeEditor.readOnly.labels.location')}</dt><dd>{LOCATION_TYPES.find((l) => l.value === et?.location_type)?.label ?? et.location_type}{#if et.location_value} · {et.location_value}{/if}</dd>
<dt class="text-muted-foreground">{$t('eventTypeEditor.readOnly.labels.routing')}</dt><dd class="capitalize">{et.routing_mode.replace('_', ' ')}</dd>
<dt class="text-muted-foreground">{$t('eventTypeEditor.readOnly.labels.status')}</dt><dd>{et.is_active ? $t('eventTypeEditor.readOnly.status.active') : $t('eventTypeEditor.readOnly.status.inactive')} · {et.is_public ? $t('eventTypeEditor.readOnly.status.listed') : $t('eventTypeEditor.readOnly.status.unlisted')}</dd>
<dt class="text-muted-foreground">{$t('eventTypeEditor.readOnly.labels.status')}</dt><dd>{et.is_active ? $t('eventTypeEditor.readOnly.status.active') : $t('eventTypeEditor.readOnly.status.inactive')} · {visibilityLabel(et.visibility)}</dd>
<dt class="text-muted-foreground">{$t('eventTypeEditor.readOnly.labels.bookingPage')}</dt><dd><a href="/book/{et.slug}" target="_blank" rel="noopener" class="text-primary underline">/book/{et.slug}</a></dd>
</dl>
</div>
Expand Down Expand Up @@ -684,11 +703,15 @@
</div>
</div>
<div class="space-y-1.5">
<p class="text-sm font-medium">{$t('eventTypeEditor.general.visibility')}</p>
<div class="flex items-center gap-2">
<Checkbox id="is-public" bind:checked={form.is_public} />
<Label for="is-public" class="cursor-pointer font-normal">{$t('eventTypeEditor.general.public')}</Label>
</div>
<Label for="visibility">{$t('eventTypeEditor.general.visibility')}</Label>
<Select.Root type="single" bind:value={form.visibility}>
<Select.Trigger id="visibility" class="w-full">{$t(visibilityKey(form.visibility))}</Select.Trigger>
<Select.Content>
<Select.Item value="public" label={$t('eventTypeEditor.general.visibilityPublic')}>{$t('eventTypeEditor.general.visibilityPublic')}</Select.Item>
<Select.Item value="unlisted" label={$t('eventTypeEditor.general.visibilityUnlisted')}>{$t('eventTypeEditor.general.visibilityUnlisted')}</Select.Item>
<Select.Item value="private" label={$t('eventTypeEditor.general.visibilityPrivate')}>{$t('eventTypeEditor.general.visibilityPrivate')}</Select.Item>
</Select.Content>
</Select.Root>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions internal/db/constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func TestConstraintPredicates(t *testing.T) {
t.Run("foreign key on delete restrict", func(t *testing.T) {
const etID = "et-restrict"
if _, err := database.Exec(
`INSERT INTO event_types (id, user_id, slug, name, duration_minutes, slot_interval_minutes, location_type, is_active, is_public, archived_at)
VALUES (?, ?, 'restrict-et', 'Restrict ET', 30, 30, 'in_person', 1, 1, NULL)`,
`INSERT INTO event_types (id, user_id, slug, name, duration_minutes, slot_interval_minutes, location_type, is_active, visibility, archived_at)
VALUES (?, ?, 'restrict-et', 'Restrict ET', 30, 30, 'in_person', 1, 'public', NULL)`,
etID, userID); err != nil {
t.Fatalf("seed event type: %v", err)
}
Expand Down
23 changes: 23 additions & 0 deletions internal/db/migrations/00079_event_type_visibility.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- +goose Up
-- Event-type visibility (#272): replace the is_public boolean with a four-state column.
--
-- is_public=1 -> public, is_public=0 -> private. Existing drafts must stay unbookable:
-- nothing is reinterpreted as unlisted or internal.
--
-- 'internal' is allowed by the CHECK now even though nothing may set it yet (the API
-- rejects it until optional authentication lands, step 2 / #269). Including it here
-- avoids a table rebuild later, which in SQLite means recreating the table and every
-- index on it.
ALTER TABLE event_types ADD COLUMN visibility TEXT NOT NULL DEFAULT 'public'
CHECK (visibility IN ('public', 'unlisted', 'internal', 'private'));

UPDATE event_types SET visibility = CASE WHEN is_public = 1 THEN 'public' ELSE 'private' END;

ALTER TABLE event_types DROP COLUMN is_public;

-- +goose Down
-- Lossy by nature: unlisted and internal have no is_public equivalent, so both collapse
-- to not-public (=0). Documented rather than pretended away.
ALTER TABLE event_types ADD COLUMN is_public INTEGER NOT NULL DEFAULT 0;
UPDATE event_types SET is_public = CASE WHEN visibility = 'public' THEN 1 ELSE 0 END;
ALTER TABLE event_types DROP COLUMN visibility;
4 changes: 2 additions & 2 deletions internal/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func Seed(ctx context.Context, db *sql.DB) error {
INSERT INTO event_types
(id, user_id, team_id, slug, name, description, duration_minutes,
location_type, location_value, routing_mode, min_notice_minutes,
max_future_days, is_active, is_public)
VALUES (?, ?, ?, ?, ?, ?, ?, 'link', 'https://example.com/demo-meeting', ?, ?, ?, 1, 1)`,
max_future_days, is_active, visibility)
VALUES (?, ?, ?, ?, ?, ?, ?, 'link', 'https://example.com/demo-meeting', ?, ?, ?, 1, 'public')`,
et.id, OwnerUserID, teamVal, et.slug, et.name, et.description, et.durationMinutes,
routingMode, et.minNoticeMinutes, et.maxFutureDays); err != nil {
return fmt.Errorf("demo seed: event type %s: %w", et.slug, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (h *Handler) PublicEventType(w http.ResponseWriter, r *http.Request) {
et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent, et.show_next_available
FROM event_types et
JOIN users u ON u.id = et.user_id
WHERE et.slug = ? AND et.is_active = 1 AND et.is_public = 1`,
WHERE et.slug = ? AND et.is_active = 1 AND et.visibility IN ('public', 'unlisted')`,
slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, &currency, &msgGreeting, &allowPhoneCall, &accentColor, &showNext)
if errors.Is(err, sql.ErrNoRows) {
h.writeError(w, http.StatusNotFound, "event type not found")
Expand Down Expand Up @@ -483,7 +483,7 @@ func (h *Handler) BookPage(w http.ResponseWriter, r *http.Request) {
et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent, et.show_next_available
FROM event_types et
JOIN users u ON u.id = et.user_id
WHERE et.slug = ? AND et.is_active = 1 AND et.is_public = 1`,
WHERE et.slug = ? AND et.is_active = 1 AND et.visibility IN ('public', 'unlisted')`,
slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, &currency, &msgGreeting, &allowPhoneCall, &accentColor, &showNext)

if errors.Is(err, sql.ErrNoRows) {
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ func TestBookPage_privateEventType_returns404(t *testing.T) {
slug, _ := seedEventTypeHTTP(t, h, apiKey)

// Make the event type private.
patchReq := authReq(http.MethodPatch, "/v1/event-types/"+slug, `{"is_public":false}`, apiKey)
patchReq := authReq(http.MethodPatch, "/v1/event-types/"+slug, `{"visibility":"private"}`, apiKey)
patchReq.SetPathValue("slug", slug)
patchRec := httptest.NewRecorder()
h.RequireAuth(h.PatchEventType)(patchRec, patchReq)
if patchRec.Code != http.StatusOK {
t.Fatalf("patch is_public=false: got %d — %s", patchRec.Code, patchRec.Body.String())
t.Fatalf("patch visibility=private: got %d — %s", patchRec.Code, patchRec.Body.String())
}

req := httptest.NewRequest(http.MethodGet, "/book/"+slug, nil)
Expand Down
16 changes: 12 additions & 4 deletions internal/handler/booking_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ type bookableEventType struct {
BufferAfterMinutes int
MinNoticeMinutes int
MaxFutureDays int
Visibility Visibility
MaxActiveBookings int
PriceCents int
Currency string
Expand All @@ -535,20 +536,27 @@ type bookableEventType struct {
// everywhere, not just hidden from its own page.
func (h *Handler) loadBookableEventType(ctx context.Context, slug string) (*bookableEventType, error) {
var et bookableEventType
var isActive, isPublic, showTaken int
var isActive, showTaken int
var visibilityRaw string
err := h.db.QueryRowContext(ctx, `
SELECT id, user_id, name, duration_minutes, slot_interval_minutes,
location_type, location_value, allow_phone_call, routing_mode, rr_strategy,
buffer_before_minutes, buffer_after_minutes, min_notice_minutes, max_future_days,
is_active, is_public, show_taken_slots, max_active_bookings, price_cents, currency,
is_active, visibility, show_taken_slots, max_active_bookings, price_cents, currency,
invite_delivery
FROM event_types WHERE slug = ?`, slug).
Scan(&et.ID, &et.UserID, &et.Name, &et.DurationMinutes, &et.SlotIntervalMinutes,
&et.LocationType, &et.LocationValue, &et.AllowPhoneCall, &et.RoutingMode, &et.RRStrategy,
&et.BufferBeforeMinutes, &et.BufferAfterMinutes, &et.MinNoticeMinutes, &et.MaxFutureDays,
&isActive, &isPublic, &showTaken, &et.MaxActiveBookings, &et.PriceCents, &et.Currency,
&isActive, &visibilityRaw, &showTaken, &et.MaxActiveBookings, &et.PriceCents, &et.Currency,
&et.InviteDelivery)
if err != nil || isActive == 0 || isPublic == 0 {
if err != nil || isActive == 0 {
return nil, errEventTypeNotFound
}
// Step 1 (#272): no caller of this gate is authenticated yet, so "internal" is not
// reachable here. Step 2 (#269) threads an authenticated flag through instead.
et.Visibility = parseVisibility(visibilityRaw)
if !et.Visibility.Bookable(false) {
return nil, errEventTypeNotFound
}
et.ShowTakenSlots = showTaken != 0
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (h *Handler) PersonPage(w http.ResponseWriter, r *http.Request) {
brand := h.loadBranding(r.Context())
loc := h.resolveLocaleWithFallback(r, brand.FallbackLocale)
items, err := h.directoryItems(r.Context(), loc,
`et.is_public = 1 AND et.is_active = 1 AND (et.user_id = ? OR EXISTS
`et.visibility = 'public' AND et.is_active = 1 AND (et.user_id = ? OR EXISTS
(SELECT 1 FROM event_type_hosts hh WHERE hh.event_type_id = et.id AND hh.user_id = ?))`,
userID, userID)
if err != nil {
Expand Down Expand Up @@ -206,7 +206,7 @@ func (h *Handler) TeamPage(w http.ResponseWriter, r *http.Request) {
brand := h.loadBranding(r.Context())
loc := h.resolveLocaleWithFallback(r, brand.FallbackLocale)
items, err := h.directoryItems(r.Context(), loc,
`et.team_id = ? AND et.is_public = 1 AND et.is_active = 1`, teamID)
`et.team_id = ? AND et.visibility = 'public' AND et.is_active = 1`, teamID)
if err != nil {
h.logger.ErrorContext(r.Context(), "team page: load event types", "error", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/directory_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestDirectories_displayOrder(t *testing.T) {
for _, slug := range []string{"hidden", "inactive", "unrelated"} {
mustExec(t, database, `INSERT INTO event_types (id,user_id,team_id,slug,name,duration_minutes,display_order) VALUES (?,?,'order-team',?, ?,30,-100)`, slug, ownerID, slug, slug)
}
mustExec(t, database, `UPDATE event_types SET is_public = 0 WHERE slug = 'hidden'`)
mustExec(t, database, `UPDATE event_types SET visibility = 'private' WHERE slug = 'hidden'`)
mustExec(t, database, `UPDATE event_types SET is_active = 0 WHERE slug = 'inactive'`)
mustExec(t, database, `UPDATE event_types SET user_id = 'other-owner', team_id = NULL WHERE slug = 'unrelated'`)
checkPages := func(want []string) {
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func TestPersonPage_listsPublicActiveEventTypes(t *testing.T) {
}
slugVisible, _ := seedEventTypeHTTP(t, h, key)
slugHidden, _ := seedEventTypeHTTP(t, h, key)
// Hide one via is_public.
req := authReq(http.MethodPatch, "/v1/event-types/"+slugHidden, `{"is_public":false}`, key)
// Hide one via visibility.
req := authReq(http.MethodPatch, "/v1/event-types/"+slugHidden, `{"visibility":"private"}`, key)
req.SetPathValue("slug", slugHidden)
rec := httptest.NewRecorder()
h.RequireAuth(h.PatchEventType)(rec, req)
Expand Down
Loading
Loading