dawarich/app/javascript/controllers
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
..
add_visit_controller.js Extract map controls to a separate file 2025-10-15 11:43:49 +02:00
application.js Add flashes with StumulusJS 2024-01-03 12:13:00 +01:00
base_controller.js Update flash message styles 2025-02-15 17:58:33 +01:00
checkbox_select_all_controller.js Hide "Delete Selected" button when no points are selected. 2025-07-26 14:41:03 +02:00
clipboard_controller.js Add a button to copy invitation link for pending invitations 2025-10-14 13:28:56 +02:00
datetime_controller.js Inherit all stimulus controllers from base_controller 2025-02-15 16:48:03 +01:00
direct_upload_controller.js Merge branch 'dev', remote-tracking branch 'origin' into refactoring/user-data-import 2025-09-26 19:31:31 +02:00
family_members_controller.js Fix remembering family members layer state and refreshing locations 2025-10-21 19:54:25 +02:00
family_navbar_indicator_controller.js Show family members on the map 2025-09-29 21:31:24 +02:00
imports_controller.js Update importing process 2025-07-02 20:22:40 +02:00
index.js Add flashes with StumulusJS 2024-01-03 12:13:00 +01:00
location_sharing_toggle_controller.js Fix routes to use singular resource for family 2025-10-04 23:08:02 +02:00
map_controls_controller.js Make sure date nav not being hidden when clicking next/prev day button 2025-10-14 17:39:17 +02:00
map_preview_controller.js Inherit all stimulus controllers from base_controller 2025-02-15 16:48:03 +01:00
maps_controller.js Fix remembering family members layer state and refreshing locations 2025-10-21 19:54:25 +02:00
notifications_controller.js Fix notifications scroll 2025-06-11 21:12:03 +02:00
onboarding_modal_controller.js Add limits for import size for trial users 2025-08-14 20:50:22 +02:00
public_stat_map_controller.js Add collapsible footer to map controls and update location search icon 2025-10-14 17:30:53 +02:00
public_trip_map_controller.js Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00
removals_controller.js Inherit all stimulus controllers from base_controller 2025-02-15 16:48:03 +01:00
sharing_modal_controller.js Add a button to copy invitation link for pending invitations 2025-10-14 13:28:56 +02:00
stat_page_controller.js Update map layers based on user theme preference (light/dark) and add theme-aware styling to map controls and buttons. 2025-09-26 18:49:13 +02:00
trip_map_controller.js Update map layers based on user theme preference (light/dark) and add theme-aware styling to map controls and buttons. 2025-09-26 18:49:13 +02:00
trips_controller.js Updte map view 2025-10-30 19:16:38 +01:00
user_data_archive_direct_upload_controller.js Rework importing user data archive 2025-09-23 20:39:12 +02:00
visit_modal_map_controller.js Inherit all stimulus controllers from base_controller 2025-02-15 16:48:03 +01:00
visit_modal_places_controller.js Add visits to the map page 2025-03-02 21:24:57 +01:00
visit_name_controller.js Inherit all stimulus controllers from base_controller 2025-02-15 16:48:03 +01:00
visits_map_controller.js Add visits to the map page 2025-03-02 21:24:57 +01:00