Public read-only share link (#41)
Build image / build-and-push (push) Successful in 8s
Gadfly review (reusable) / review (pull_request) Successful in 10m11s
Adversarial Review (Gadfly) / review (pull_request) Successful in 10m11s

A per-garden public link anyone can open read-only, with no login and no OIDC.

Backend:
- Migration 0004 adds gardens.public_token (nullable, unique over non-NULL).
- Owner-only management: GET/POST/DELETE /gardens/:id/share-link (state /
  enable-or-rotate / disable). The token is stored raw (it must be shown back
  to the owner) and never selected into the normal garden payload.
- Unauthenticated GET /api/v1/public/gardens/:token returns the read-only /full
  payload — the token is the capability, so no requireAuth and no redirect. The
  public view drops MyRole and OwnerID to minimize what an anonymous viewer
  learns. Unknown/rotated/disabled tokens are masked as 404.
- assembleFull is extracted from GardenFull so both reads return one shape.

Frontend:
- /g/$token route with NO auth guard (SPA fallback already serves it), rendering
  GardenCanvas read-only via usePublicGarden.
- Share dialog gains a Public link section: create, copy, regenerate, turn off.

Tests: service lifecycle + ACL (owner-only, non-owner masked, rotate/disable
invalidation) and the HTTP surface incl. the cookieless public read.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdQpdYYsTgtkJBxbcpAszi
This commit is contained in:
2026-07-19 02:04:11 -04:00
co-authored by Claude Opus 4.8
parent fef3f601bf
commit f3b0ca572d
14 changed files with 750 additions and 9 deletions
+11 -3
View File
@@ -164,15 +164,23 @@ func (s *Service) GardenFull(ctx context.Context, actorID, gardenID int64) (*Ful
if err != nil {
return nil, err
}
objects, err := s.store.ListObjectsForGarden(ctx, gardenID)
return s.assembleFull(ctx, g)
}
// assembleFull builds the read-only /full payload for an already-authorized
// garden: its objects, active plops (with DerivedCount filled in), and the
// plants those plops reference. Shared by the authenticated GardenFull and the
// unauthenticated PublicGarden read, so both return the identical shape.
func (s *Service) assembleFull(ctx context.Context, g *domain.Garden) (*FullGarden, error) {
objects, err := s.store.ListObjectsForGarden(ctx, g.ID)
if err != nil {
return nil, err
}
plantings, err := s.store.ListActivePlantingsForGarden(ctx, gardenID)
plantings, err := s.store.ListActivePlantingsForGarden(ctx, g.ID)
if err != nil {
return nil, err
}
plants, err := s.store.ListReferencedPlants(ctx, gardenID)
plants, err := s.store.ListReferencedPlants(ctx, g.ID)
if err != nil {
return nil, err
}