dawarich/app/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 Fix some minor stuff 2025-10-11 14:17:48 +02:00
application_record.rb Initial Rails 7.0.2.3 template w/ rspec, tailwind, and devise user 2022-04-06 22:46:10 +04:00
area.rb Fix some more tests and rework visit_suggesting_job a bit 2025-03-09 15:37:32 +01:00
country.rb Optimize stats page performance 2025-07-22 19:17:28 +02:00
export.rb Add tests 2025-06-26 19:24:40 +02:00
family.rb Fix some minor stuff 2025-10-11 14:17:48 +02:00
import.rb Update error message 2025-09-23 21:16:25 +02:00
notification.rb Add new notification to the list right away 2024-11-07 19:00:11 +01:00
place.rb Replace stubs with Geocoder search 2025-05-13 20:21:18 +02:00
place_visit.rb Add lots of logic 2024-08-12 22:18:11 +02:00
point.rb Implement real-time family member location updates via ActionCable 2025-10-13 14:10:36 +02:00
stat.rb Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
track.rb Clean up code a bit 2025-07-23 20:08:24 +02:00
trip.rb Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
user.rb Update icons on the map 2025-10-14 13:47:41 +02:00
visit.rb Extract visit creation to a service 2025-08-21 18:58:59 +02:00
visit_draft.rb Add visits page 2024-07-24 20:25:16 +02:00