dawarich/db/migrate
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
..
20220325100310_devise_create_users.rb Fix failing specs 2025-09-13 17:46:45 +02:00
20231021104256_add_service_name_to_active_storage_blobs.active_storage.rb Update to Rails 7.1.1 2023-10-21 12:43:31 +02:00
20231021104257_create_active_storage_variant_records.active_storage.rb Update to Rails 7.1.1 2023-10-21 12:43:31 +02:00
20231021104258_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb Update to Rails 7.1.1 2023-10-21 12:43:31 +02:00
20240315213523_create_points.rb Add areas 2024-07-21 20:09:42 +02:00
20240315215423_create_imports.rb Migrate from old template 2024-03-15 23:27:31 +01:00
20240317171559_add_indicies_to_points_latitude_longitude.rb Add indicies to points latitude longitude 2024-03-17 18:16:45 +01:00
20240323125126_add_raw_points_and_doubles_to_import.rb Save number of raw points and doubles in import file 2024-03-23 14:20:20 +01:00
20240323160300_create_stats.rb Add basic stats 2024-03-23 20:29:55 +01:00
20240323161049_add_index_to_points_timestamp.rb Add basic stats 2024-03-23 20:29:55 +01:00
20240323190039_add_user_id_to_stat.rb Add basic stats 2024-03-23 20:29:55 +01:00
20240324161309_create_active_storage_tables.active_storage.rb Use Active Storage to import GPX files 2025-03-23 18:37:10 +01:00
20240324161800_add_processed_to_imports.rb Move import processing to background job & allow to disable reverse geocoding 2024-03-24 18:05:39 +01:00
20240324173315_add_daily_distance_to_stat.rb Add nice charts to the stat cards 2024-03-24 18:55:35 +01:00
20240404154959_add_api_key_to_users.rb Add callback to create API key for new users 2024-04-04 20:14:11 +02:00
20240425200155_add_raw_data_to_imports.rb Use shrine to upload files instead of ActiveStorage 2024-04-25 22:28:34 +02:00
20240518095848_add_theme_to_users.rb Persist app theme in user settings 2024-05-18 12:13:29 +02:00
20240525110244_add_user_id_to_points.rb Scope points to a user 2024-05-25 13:26:56 +02:00
20240612152451_create_exports.rb Implement Exporting points to a file 2024-06-12 20:29:38 +02:00
20240620205120_add_settings_to_users.rb Add new settings page to allow user change route rendering options 2024-06-20 23:57:00 +02:00
20240630093005_add_fog_of_war_to_default_settings.rb Disable registration and implement user creation in the settings page 2024-06-30 12:31:21 +02:00
20240703105734_create_notifications.rb Add notifications 2024-07-04 22:20:12 +02:00
20240712141303_add_geodata_to_points.rb Add tests for background jobs stuff 2024-07-12 21:59:03 +02:00
20240713103051_add_admin_to_users.rb Add admin flag to users 2024-07-16 22:26:16 +02:00
20240721165313_create_areas.rb Add areas 2024-07-21 20:09:42 +02:00
20240721183005_create_visits.rb Add visits page 2024-07-24 20:25:16 +02:00
20240721183116_add_visit_id_to_points.rb Add Visit model and associations 2024-07-21 20:32:29 +02:00
20240805150111_create_places.rb Add visits detection 2024-08-05 21:23:08 +02:00
20240808102348_add_place_id_to_visits.rb Add lots of logic 2024-08-12 22:18:11 +02:00
20240808102425_make_area_id_optional_in_visits.rb Add lots of logic 2024-08-12 22:18:11 +02:00
20240808121027_create_place_visits.rb Add lots of logic 2024-08-12 22:18:11 +02:00
20240822092405_add_points_count_to_imports.rb Add counter cache for imports 2024-08-22 22:40:27 +02:00
20241127161621_create_trips.rb Add distance calculation and trip cards to trips index 2024-11-28 15:29:17 +01:00
20241128095325_create_action_text_tables.action_text.rb Add Trix editor to trips 2024-11-28 12:00:54 +01:00
20241202114820_add_reverse_geocoded_at_to_points.rb Add some minor changes 2024-12-11 14:21:44 +01:00
20241205160055_add_devise_trackable_columns_to_users.rb Add basic telemetry 2024-12-05 17:12:35 +01:00
20241211113119_add_started_at_index_to_visits.rb Add some minor changes 2024-12-11 14:21:44 +01:00
20241226202204_add_database_users_constraints.rb Add database constraints for users table 2024-12-26 21:34:10 +01:00
20241226202831_validate_add_database_users_constraints.rb Add database constraints for users table 2024-12-26 21:34:10 +01:00
20250120152014_add_course_and_course_accuracy_to_points.rb Implement dawarich points parsing 2025-01-20 16:37:15 +01:00
20250120152540_add_external_track_id_to_points.rb Implement dawarich points parsing 2025-01-20 16:37:15 +01:00
20250120154555_add_unique_index_to_points.rb Add rake tasks for data cleanup and user activation 2025-03-21 18:09:58 +01:00
20250123145155_enable_postgis_extension.rb Enable PostGIS extension only if it's not already enabled 2025-05-16 20:07:55 +02:00
20250123151657_add_path_to_trips.rb Add path to trips 2025-01-24 12:01:54 +01:00
20250219195822_add_status_to_users.rb Restrict to some functionality access for inactive users 2025-02-19 21:23:11 +01:00
20250221181805_add_lonlat_to_points.rb Use lonlat in maps controller 2025-02-23 22:59:14 +01:00
20250221185032_add_lonlat_index.rb Speed up some importing processes 2025-02-22 23:14:23 +01:00
20250221194430_remove_points_latitude_longitude_uniqueness_index.rb Use lonlat in maps controller 2025-02-23 22:59:14 +01:00
20250221194509_add_unique_lon_lat_index_to_points.rb Speed up some importing processes 2025-02-22 23:14:23 +01:00
20250303194009_add_lonlat_to_places.rb Add lonlat to places 2025-03-03 20:50:49 +01:00
20250303194043_add_lonlat_index_to_places.rb Add lonlat to places 2025-03-03 20:50:49 +01:00
20250324180755_add_format_start_at_end_at_to_exports.rb Rename format column to file_format in exports table 2025-04-02 21:19:02 +02:00
20250404182437_add_active_until_to_users.rb Add active_until to users 2025-04-04 20:27:46 +02:00
20250513164521_add_visited_countries_to_trips.rb Update visited_countries column type to jsonb 2025-05-16 21:29:07 +02:00
20250515190752_create_countries.rb Update views and specs 2025-05-16 19:53:42 +02:00
20250515192211_add_country_id_to_points.rb Put countries into database 2025-05-16 18:51:48 +02:00
20250625185030_add_file_type_to_exports.rb User export: exporting exports and imports data with files 2025-06-25 21:14:33 +02:00
20250627184017_add_status_to_imports.rb Update changelog 2025-06-30 22:51:25 +02:00
20250703193656_create_tracks.rb Store track distance in user's preferred unit 2025-07-07 22:23:37 +02:00
20250703193657_add_track_id_to_points.rb Add tracks calculation and storage in the database 2025-07-03 20:18:18 +02:00
20250721204404_add_index_on_places_geodata_osm_id.rb Fix stats calculation performance 2025-07-22 22:41:12 +02:00
20250723164055_add_track_generation_composite_index.rb Add composite index for track generation 2025-07-23 19:30:56 +02:00
20250728191359_add_country_name_to_points.rb Fix country name in points 2025-07-29 21:17:33 +02:00
20250821192219_add_points_count_to_users.rb Reset counters for points counter cache 2025-08-26 15:26:05 +02:00
20250823125940_remove_default_from_imports_source.rb Fix import detection 2025-08-23 16:07:15 +02:00
20250905120121_add_user_country_composite_index_to_points.rb Add follow up emails 2025-09-05 19:39:50 +02:00
20250910224538_add_sharing_fields_to_stats.rb Update stuff, fix stuff 2025-09-29 22:27:07 +02:00
20250910224714_add_index_to_stats_share_uuid.rb Add Lucide icons and stats sharing 2025-09-11 20:41:43 +02:00
20250918215512_add_h3_hex_ids_to_stats.rb Update migration 2025-09-20 15:55:10 +02:00
20250926220114_create_families.rb Use ids instead of uuids for primary keys in family tables 2025-09-30 18:43:26 +02:00
20250926220135_create_family_memberships.rb Update migrations 2025-10-05 14:02:18 +02:00
20250926220158_create_family_invitations.rb Update migrations 2025-10-05 14:02:18 +02:00
20250926220345_validate_family_foreign_keys.rb Add implementation plan and complete phase 1 2025-09-27 00:46:29 +02:00
20251030190924_add_utm_parameters_to_users.rb Updte map view 2025-10-30 19:16:38 +01:00
20251105153510_add_sharing_to_trips.rb Implement public trip sharing with Shareable concern 2025-11-05 15:44:27 +00:00