dawarich/spec
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
..
channels Add incremental track generation 2025-07-07 21:48:07 +02:00
factories Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
fixtures Fix import detection 2025-08-23 16:07:15 +02:00
jobs Update stuff, fix stuff 2025-09-29 22:27:07 +02:00
lib Update json_stream_handler_spec.rb path and remove tmp.json 2025-10-05 21:01:34 +02:00
mailers Update onborading popup 2025-09-18 18:29:46 +02:00
models Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
policies Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
queries Reimplement hexagons with H3 2025-09-17 01:55:42 +02:00
requests Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
serializers Update stuff, fix stuff 2025-09-29 22:27:07 +02:00
services Remember enabled map layers for users 2025-10-20 20:11:28 +02:00
support Clean up some mess 2025-07-20 18:57:53 +02:00
swagger/api/v1 Add swagger spec for visits api 2025-08-21 20:53:23 +02:00
system Update onborading popup 2025-09-18 18:29:46 +02:00
tasks Fix failed specs 2025-01-21 19:32:12 +01:00
rails_helper.rb Clean up some mess 2025-07-20 18:57:53 +02:00
spec_helper.rb Add spec for CheckAppVersion service 2024-04-25 22:40:51 +02:00
swagger_helper.rb Add swagger along with api/v1/points swagger doc 2024-05-18 13:35:48 +02:00