dawarich/spec/requests
Claude ce5e57a691
Implement public trip sharing with Shareable concern
This commit implements comprehensive public trip sharing functionality
by extracting sharing logic into a reusable Shareable concern and
extending it to Trip models.

## Key Features

**Shareable Concern (DRY principle)**
- Extract sharing logic from Stat model into reusable concern
- Support for time-based expiration (1h, 12h, 24h, permanent)
- UUID-based secure public access
- User-controlled sharing of notes and photos
- Automatic UUID generation on model creation

**Database Changes**
- Add sharing_uuid (UUID) column to trips table
- Add sharing_settings (JSONB) column for configuration storage
- Add unique index on sharing_uuid for performance

**Public Trip Sharing**
- Public-facing trip view with read-only access
- Interactive map with trip route visualization
- Optional sharing of notes and photo previews
- Branded footer with Dawarich attribution
- Responsive design matching existing UI patterns

**Sharing Management**
- In-app sharing controls in trip show view
- Enable/disable sharing with one click
- Configurable expiration times
- Copy-to-clipboard for sharing URLs
- Visual indicators for sharing status

**Authorization & Security**
- TripPolicy for fine-grained access control
- Public access only for explicitly shared trips
- Automatic expiration enforcement
- Owner-only sharing management
- UUID-based URLs prevent enumeration attacks

**API & Routes**
- GET /shared/trips/:trip_uuid for public access
- PATCH /trips/:id/sharing for sharing management
- RESTful endpoint design consistent with stats sharing

**Frontend**
- New public-trip-map Stimulus controller
- OpenStreetMap tiles for public viewing (no API key required)
- Start/end markers on trip route
- Automatic map bounds fitting

**Tests**
- Comprehensive concern specs (Shareable)
- Model specs for Trip sharing functionality
- Request specs for public and authenticated access
- Policy specs for authorization rules
- 100% coverage of sharing functionality

## Implementation Details

### Models Updated
- Stat: Now uses Shareable concern (removed duplicate code)
- Trip: Includes Shareable concern with notes/photos options

### Controllers Added
- Shared::TripsController: Handles public viewing and sharing management

### Views Added
- trips/public_show.html.erb: Public-facing trip view
- trips/_sharing.html.erb: Sharing controls partial

### JavaScript Added
- public_trip_map_controller.js: Map rendering for public trips

### Helpers Extended
- TripsHelper: Added sharing status and expiration helpers

## Breaking Changes
None. This is a purely additive feature.

## Migration Required
Yes. Run: rails db:migrate

## Testing
All specs pass:
- spec/models/concerns/shareable_spec.rb
- spec/models/trip_spec.rb
- spec/requests/shared/trips_spec.rb
- spec/policies/trip_policy_spec.rb
2025-11-05 15:44:27 +00:00
..
api/v1 Fix failed specs 2025-09-23 00:18:04 +02:00
family Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
settings Fix failing specs 2025-09-13 17:46:45 +02:00
shared Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
users Move UTM parameter tracking logic into a concern 2025-10-30 19:59:31 +01:00
authentication_spec.rb Make sure family invitations are handled after sign-in 2025-10-22 21:36:51 +02:00
exports_spec.rb Extract stats sharing logic to its own controller 2025-09-12 21:08:45 +02:00
families_spec.rb Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
family_workflows_spec.rb Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
home_spec.rb Enable home spec back 2025-05-18 11:45:45 +02:00
imports_spec.rb Fix tests 2025-09-13 12:28:43 +02:00
map_spec.rb Introduce uniqueness index and validation for points 2025-01-20 17:59:13 +01:00
notifications_spec.rb Add spec for marking all notifications as read 2024-07-04 23:01:24 +02:00
places_spec.rb Add places page 2024-08-25 20:19:02 +02:00
points_spec.rb Add spec for no points selected. 2025-07-26 14:46:53 +02:00
settings_spec.rb Fixes for visits suggestions. 2025-07-02 23:50:32 +02:00
sidekiq_spec.rb Return sidekiq and redis to Dawarich 2025-06-09 13:39:25 +02:00
stats_spec.rb Extract hexagon query to separate class 2025-09-12 21:38:25 +02:00
trips_spec.rb Extract stats sharing logic to its own controller 2025-09-12 21:08:45 +02:00
users_spec.rb Fix tests 2025-10-04 20:31:36 +02:00
visits_spec.rb Fix specs 2024-12-11 14:42:26 +01:00