Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ committed booking) — which is why the reconciler (§11) exists.

## 10. Calendar integration (provider abstraction)

The connected-provider lookup prefers the destination connection. A conflict-only connection must not select the provider used when deciding how to generate a meeting link.

Calnode talks to calendars through a **provider abstraction**, not a single vendor:

- **`internal/calendar`** defines the `Provider` interface (Name, InvitesGuests,
Expand Down
2 changes: 1 addition & 1 deletion internal/calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *Service) providerForDestination(ctx context.Context, userID string) Pro
func (s *Service) Connected(ctx context.Context, userID string) (bool, string, error) {
var name string
err := s.db.QueryRowContext(ctx,
`SELECT provider FROM calendar_connections WHERE user_id = ? LIMIT 1`, userID).Scan(&name)
`SELECT provider FROM calendar_connections WHERE user_id = ? ORDER BY is_destination DESC, created_at ASC LIMIT 1`, userID).Scan(&name)
if err == sql.ErrNoRows {
return false, "", nil
}
Expand Down
46 changes: 46 additions & 0 deletions internal/calendar/destination_provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package calendar

import (
"context"
"testing"

"github.com/calnode/calnode/internal/db"
)

func TestConnectedPrefersDestinationOverOlderCalDAV(t *testing.T) {
database, err := db.Open("sqlite://:memory:")
if err != nil {
t.Fatal(err)
}
defer database.Close()
if err := db.Migrate(database); err != nil {
t.Fatal(err)
}
if _, err := database.Exec(`INSERT INTO users (id, email, name, iana_timezone, is_admin, created_at)
VALUES ('host', 'host@example.com', 'Host', 'Europe/Amsterdam', 0, '2026-09-20T00:00:00Z')`); err != nil {
t.Fatal(err)
}
for _, provider := range []string{"caldav", "google"} {
destination := 0
if provider == "google" {
destination = 1
}
if _, err := database.Exec(`INSERT INTO calendar_connections
(id, user_id, provider, access_token_enc, calendar_id, check_conflicts, is_destination, created_at)
VALUES (?, 'host', ?, 'encrypted', 'primary', 1, ?, '2026-09-20T00:00:00Z')`, provider, provider, destination); err != nil {
t.Fatal(err)
}
}
svc := NewService(database)
connected, provider, err := svc.Connected(context.Background(), "host")
if err != nil || !connected || provider != "google" {
t.Fatalf("connected=%v provider=%q error=%v; want Google destination", connected, provider, err)
}
if err := svc.SetDestination(context.Background(), "host", "caldav", ""); err != nil {
t.Fatal(err)
}
_, provider, err = svc.Connected(context.Background(), "host")
if err != nil || provider != "caldav" {
t.Fatalf("provider=%q error=%v; want changed destination", provider, err)
}
}
Loading