dawarich/spec/models
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
..
concerns Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
family Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
area_spec.rb Add Visit model and associations 2024-07-21 20:32:29 +02:00
country_spec.rb Clean up specs a bit 2025-06-26 19:48:42 +02:00
export_spec.rb Fix specs 2025-06-26 20:05:26 +02:00
family_spec.rb Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
import_spec.rb Update error message 2025-09-23 21:16:25 +02:00
notification_spec.rb Fix tests after updating rubyzip 2025-09-26 23:31:45 +02:00
place_spec.rb Add a STORE_GEODATA environment variable to control whether to store geodata in the database. 2025-05-12 22:33:47 +02:00
place_visit_spec.rb Add lots of logic 2024-08-12 22:18:11 +02:00
point_spec.rb Fix failing model spec 2025-09-19 22:12:34 +02:00
stat_spec.rb Fix minor bugs in Stat model related to sharing settings 2025-10-07 21:24:38 +02:00
track_spec.rb Store distance in meters in the database and convert to user's preferred unit on the fly. 2025-07-08 18:10:10 +02:00
trip_spec.rb Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
user_family_spec.rb Refactor family invitations and memberships into separate models and controllers 2025-10-07 18:38:06 +02:00
user_spec.rb Add specs for hexagon API and public sharing; remove debug logs 2025-09-12 20:44:53 +02:00
visit_spec.rb Extract visit creation to a service 2025-08-21 18:58:59 +02:00