roda-gen 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/bin/roda +11 -0
- data/lib/roda-gen.rb +3 -0
- data/lib/roda_gen/app_name.rb +29 -0
- data/lib/roda_gen/cli.rb +122 -0
- data/lib/roda_gen/generators/daemon.rb +78 -0
- data/lib/roda_gen/generators/migration.rb +68 -0
- data/lib/roda_gen/generators/migration_numbering.rb +21 -0
- data/lib/roda_gen/generators/model.rb +75 -0
- data/lib/roda_gen/generators/project.rb +145 -0
- data/lib/roda_gen/generators/route.rb +71 -0
- data/lib/roda_gen/generators/templates/daemon/bin/%daemon_name%.tt +13 -0
- data/lib/roda_gen/generators/templates/daemon/lib/daemon/%daemon_name%.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/daemon/spec/daemons/%daemon_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/migration/db/migrate/%migration_filename%.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/model/db/migrate/%migration_filename%.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/model/models/%resource_name%.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/model/spec/models/%resource_name%_spec.rb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/%app_name%.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/.bundle/config.tt +3 -0
- data/lib/roda_gen/generators/templates/project/.erb_lint.yml.tt +29 -0
- data/lib/roda_gen/generators/templates/project/.gitignore.tt +19 -0
- data/lib/roda_gen/generators/templates/project/.reek.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/.rspec.tt +4 -0
- data/lib/roda_gen/generators/templates/project/.rubocop.yml.tt +119 -0
- data/lib/roda_gen/generators/templates/project/.ruby-version.tt +1 -0
- data/lib/roda_gen/generators/templates/project/.rubycritic.yml.tt +15 -0
- data/lib/roda_gen/generators/templates/project/Gemfile.tt +109 -0
- data/lib/roda_gen/generators/templates/project/Procfile.dev.tt +7 -0
- data/lib/roda_gen/generators/templates/project/README.md.tt +891 -0
- data/lib/roda_gen/generators/templates/project/Rakefile.tt +3 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/admin.js.tt +84 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/app.js.tt +29 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/push.js.tt +53 -0
- data/lib/roda_gen/generators/templates/project/assets/javascripts/upload.js.tt +200 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/app.css.tt +52 -0
- data/lib/roda_gen/generators/templates/project/assets/stylesheets/typography.css.tt +85 -0
- data/lib/roda_gen/generators/templates/project/bin/console.tt +2 -0
- data/lib/roda_gen/generators/templates/project/bin/dev.tt +8 -0
- data/lib/roda_gen/generators/templates/project/bin/gdpr_worker.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/push_sender.tt +13 -0
- data/lib/roda_gen/generators/templates/project/bin/setup.tt +224 -0
- data/lib/roda_gen/generators/templates/project/bin/shrine_clean_cache.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/boot.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/config/console.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/database.rb.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/00_environments.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/01_logger.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/02_app_config.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/10_database.rb.tt +3 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/15_mail.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/20_redis.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/25_rack_attack.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/30_i18n.rb.tt +37 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/35_listen_job.rb.tt +4 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/37_shrine.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/40_routing.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/41_render.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/43_static.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/44_sessions.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/45_security.rb.tt +49 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/46_flash.rb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/47_json.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/48_errors.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/49_misc.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/50_mailer.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/51_locale_kit.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/52_consent_kit.rb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/55_audit_log.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/56_form_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/57_rodauth.rb.tt +304 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/60_web_push.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/61_flipper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/initializers/62_split.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/config/puma.rb.tt +24 -0
- data/lib/roda_gen/generators/templates/project/config/settings/development.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings/production.yml.tt +13 -0
- data/lib/roda_gen/generators/templates/project/config/settings/test.yml.tt +9 -0
- data/lib/roda_gen/generators/templates/project/config/settings.yml.tt +45 -0
- data/lib/roda_gen/generators/templates/project/config.ru.tt +36 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_account_profiles.rb.tt +66 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_accounts.rb.tt +70 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_audit_log.rb.tt +185 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_authorization.rb.tt +68 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_countries.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_calling_codes.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_exit_codes.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_languages.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_country_time_zones.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_currencies.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_gdpr_requests.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_languages.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_push_subscriptions.rb.tt +16 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_rodauth_features.rb.tt +105 -0
- data/lib/roda_gen/generators/templates/project/db/migrate/create_settings.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_countries.csv.tt +250 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_currencies.csv.tt +162 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/01_languages.csv.tt +144 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_calling_codes.csv.tt +237 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_exit_codes.csv.tt +239 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_languages.csv.tt +226 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/02_country_time_zones.csv.tt +369 -0
- data/lib/roda_gen/generators/templates/project/db/seeds/03_setting_system_defaults.yml.tt +35 -0
- data/lib/roda_gen/generators/templates/project/db/seeds.rb.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/Caddyfile.tt +69 -0
- data/lib/roda_gen/generators/templates/project/deploy/logrotate/%app_name%-caddy.tt +11 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-audit-partition.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-gdpr-worker.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-push-sender.service.tt +25 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.service.tt +21 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%-shrine-cleanup.timer.tt +16 -0
- data/lib/roda_gen/generators/templates/project/deploy/systemd/%app_name%.service.tt +36 -0
- data/lib/roda_gen/generators/templates/project/helpers/audit_helper.rb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/helpers/authorization_helper.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/helpers/current_account_helper.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/helpers/feature_flag_helper.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/helpers/form_helper.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/helpers/http_cache_helper.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/helpers/logger_helper.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/helpers/split_helper.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_context.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/lib/audit_lookup.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/base.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/gdpr_worker.rb.tt +53 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/push_sender.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/daemon/shrine_cache_cleaner.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/lib/deploy_check.rb.tt +96 -0
- data/lib/roda_gen/generators/templates/project/lib/filtered_logger.rb.tt +54 -0
- data/lib/roda_gen/generators/templates/project/lib/gdpr.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/lib/rbac_audit.rb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/.rubocop.yml.tt +4 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/audit.rake.tt +85 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/console.rake.tt +8 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/db.rake.tt +104 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/deploy.rake.tt +38 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/flags.rake.tt +47 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/gdpr.rake.tt +31 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/parser_current_shim.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/quality.rake.tt +84 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/secrets.rake.tt +154 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/spec.rake.tt +136 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/split.rake.tt +27 -0
- data/lib/roda_gen/generators/templates/project/lib/tasks/tailwind.rake.tt +35 -0
- data/lib/roda_gen/generators/templates/project/locales/de.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/en.yml.tt +321 -0
- data/lib/roda_gen/generators/templates/project/locales/es.yml.tt +326 -0
- data/lib/roda_gen/generators/templates/project/locales/fr.yml.tt +329 -0
- data/lib/roda_gen/generators/templates/project/locales/it.yml.tt +325 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/de.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/en.yml.tt +6 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/es.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/fr.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/it.yml.tt +5 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/sv.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/rodauth/tru.yml.tt +274 -0
- data/lib/roda_gen/generators/templates/project/locales/sv.yml.tt +319 -0
- data/lib/roda_gen/generators/templates/project/locales/tru.yml.tt +294 -0
- data/lib/roda_gen/generators/templates/project/log/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/models/account.rb.tt +50 -0
- data/lib/roda_gen/generators/templates/project/models/account_privilege.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/models/account_profile.rb.tt +115 -0
- data/lib/roda_gen/generators/templates/project/models/account_role.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/audit_action.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/models/audit_actor_type.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/audit_log.rb.tt +257 -0
- data/lib/roda_gen/generators/templates/project/models/audit_status.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/models/country.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/models/country_calling_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_exit_code.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/country_language.rb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/models/country_time_zone.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/currency.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/gdpr_request.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/models/gender.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/models/language.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/models/privilege.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/push_subscription.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/models/role.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/models/role_privilege.rb.tt +14 -0
- data/lib/roda_gen/generators/templates/project/models/setting_system_default.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/models/setting_user_value.rb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/models/settings.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/models/signup_form_data.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/models.rb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/package.json.tt +13 -0
- data/lib/roda_gen/generators/templates/project/public/apple-touch-icon.png +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.ico +0 -0
- data/lib/roda_gen/generators/templates/project/public/favicon.svg.tt +5 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Italic-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/JetBrainsMono-Variable.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-BoldItalic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Italic.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/Lato-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NOTICE.md +17 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriac-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Bold.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/fonts/NotoSansSyriacWestern-Regular.woff2 +0 -0
- data/lib/roda_gen/generators/templates/project/public/manifest.webmanifest.tt +12 -0
- data/lib/roda_gen/generators/templates/project/public/robots.txt.tt +4 -0
- data/lib/roda_gen/generators/templates/project/public/service-worker.js.tt +27 -0
- data/lib/roda_gen/generators/templates/project/routes/account.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/routes/admin.rb.tt +118 -0
- data/lib/roda_gen/generators/templates/project/routes/gdpr.rb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/routes/heartbeat.rb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/routes/legal.rb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/routes/profile.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/project/routes/push.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/role_boundary_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/spec_helper.rb.tt +146 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/support/auth_helpers.rb.tt +71 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/auth_spec.rb.tt +25 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/consent_nojs_spec.rb.tt +60 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/create_account_form_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/otp_lifecycle_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/profile_form_spec.rb.tt +17 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/uat/upload_spec.rb.tt +102 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/auth_pages_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/browser/wcag/legal_pages_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/base_spec.rb.tt +106 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/gdpr_worker_spec.rb.tt +72 -0
- data/lib/roda_gen/generators/templates/project/spec/daemons/push_sender_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/locale_parity_spec.rb.tt +58 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_profile_spec.rb.tt +180 -0
- data/lib/roda_gen/generators/templates/project/spec/models/account_spec.rb.tt +104 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_actor_type_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_log_spec.rb.tt +398 -0
- data/lib/roda_gen/generators/templates/project/spec/models/audit_status_spec.rb.tt +7 -0
- data/lib/roda_gen/generators/templates/project/spec/models/authorization_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_calling_code_spec.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_exit_code_spec.rb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_language_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_spec.rb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/spec/models/country_time_zone_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/currency_spec.rb.tt +9 -0
- data/lib/roda_gen/generators/templates/project/spec/models/deploy_check_spec.rb.tt +143 -0
- data/lib/roda_gen/generators/templates/project/spec/models/gdpr_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/language_spec.rb.tt +15 -0
- data/lib/roda_gen/generators/templates/project/spec/models/rbac_audit_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_system_default_spec.rb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/spec/models/setting_user_value_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/models/settings_spec.rb.tt +63 -0
- data/lib/roda_gen/generators/templates/project/spec/models/signup_form_data_spec.rb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/spec/spec_helper.rb.tt +93 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_log_helpers.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/support/audit_lookup_shared_examples.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/spec/support/auth_helpers.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/support/faker.rb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/spec/web/admin_spec.rb.tt +155 -0
- data/lib/roda_gen/generators/templates/project/spec/web/audit_log_spec.rb.tt +159 -0
- data/lib/roda_gen/generators/templates/project/spec/web/auth_spec.rb.tt +492 -0
- data/lib/roda_gen/generators/templates/project/spec/web/authorization_spec.rb.tt +110 -0
- data/lib/roda_gen/generators/templates/project/spec/web/boot_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/consent_banner_spec.rb.tt +46 -0
- data/lib/roda_gen/generators/templates/project/spec/web/feature_flag_helper_spec.rb.tt +33 -0
- data/lib/roda_gen/generators/templates/project/spec/web/flags_spec.rb.tt +67 -0
- data/lib/roda_gen/generators/templates/project/spec/web/gdpr_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/heartbeat_spec.rb.tt +65 -0
- data/lib/roda_gen/generators/templates/project/spec/web/host_allowlist_spec.rb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/spec/web/legal_spec.rb.tt +61 -0
- data/lib/roda_gen/generators/templates/project/spec/web/locale_resolver_spec.rb.tt +34 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_helper_spec.rb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/spec/web/logger_spec.rb.tt +82 -0
- data/lib/roda_gen/generators/templates/project/spec/web/otp_audit_spec.rb.tt +147 -0
- data/lib/roda_gen/generators/templates/project/spec/web/profile_spec.rb.tt +97 -0
- data/lib/roda_gen/generators/templates/project/spec/web/push_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_runtime_spec.rb.tt +52 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rack_attack_spec.rb.tt +81 -0
- data/lib/roda_gen/generators/templates/project/spec/web/rbac_audit_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/request_id_spec.rb.tt +62 -0
- data/lib/roda_gen/generators/templates/project/spec/web/role_boundary_spec.rb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/spec/web/session_skip_spec.rb.tt +74 -0
- data/lib/roda_gen/generators/templates/project/spec/web/split_helper_spec.rb.tt +38 -0
- data/lib/roda_gen/generators/templates/project/spec/web/type_routing_spec.rb.tt +55 -0
- data/lib/roda_gen/generators/templates/project/spec/web/upload_zone_spec.rb.tt +91 -0
- data/lib/roda_gen/generators/templates/project/tmp/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/vendor/.keep.tt +0 -0
- data/lib/roda_gen/generators/templates/project/views/403.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/404.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/500.erb.tt +12 -0
- data/lib/roda_gen/generators/templates/project/views/_head_meta.erb.tt +29 -0
- data/lib/roda_gen/generators/templates/project/views/_impersonate_picker.erb.tt +21 -0
- data/lib/roda_gen/generators/templates/project/views/_language_switcher.erb.tt +22 -0
- data/lib/roda_gen/generators/templates/project/views/_locked_accounts.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/_upload_zone.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/account/profile.erb.tt +149 -0
- data/lib/roda_gen/generators/templates/project/views/admin/flags.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_banner.erb.tt +59 -0
- data/lib/roda_gen/generators/templates/project/views/consent_kit/_preferences.erb.tt +87 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/erased.erb.tt +6 -0
- data/lib/roda_gen/generators/templates/project/views/gdpr/index.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/layout.erb.tt +112 -0
- data/lib/roda_gen/generators/templates/project/views/legal/contact.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/legal/cookies.erb.tt +47 -0
- data/lib/roda_gen/generators/templates/project/views/legal/disclaimer.erb.tt +19 -0
- data/lib/roda_gen/generators/templates/project/views/legal/privacy.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/account_unlocked.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_erased.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/mailers/data_export.erb.tt +5 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/add-recovery-codes.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-login.erb.tt +44 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/change-password.erb.tt +41 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/close-account.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/confirm-password.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/create-account.erb.tt +183 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/login.erb.tt +51 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/logout.erb.tt +10 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-auth.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-disable.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-setup.erb.tt +48 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock-not-available.erb.tt +18 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/otp-unlock.erb.tt +28 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-auth.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/recovery-codes.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/remember.erb.tt +35 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password-request.erb.tt +27 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/reset-password.erb.tt +30 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-auth.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-disable.erb.tt +20 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/two-factor-manage.erb.tt +36 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account-request.erb.tt +13 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/unlock-account.erb.tt +23 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account-resend.erb.tt +26 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-account.erb.tt +32 -0
- data/lib/roda_gen/generators/templates/project/views/rodauth/verify-login-change.erb.tt +8 -0
- data/lib/roda_gen/generators/templates/route/routes/%plural%.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/route/spec/web/%plural%_spec.rb.tt +36 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/index.erb.tt +11 -0
- data/lib/roda_gen/generators/templates/route/views/%plural%/show.erb.tt +7 -0
- data/lib/roda_gen/generators/templates/upload/db/migrate/%migration_filename%.rb.tt +13 -0
- data/lib/roda_gen/generators/templates/upload/helpers/upload_serving.rb.tt +43 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%.rb.tt +11 -0
- data/lib/roda_gen/generators/templates/upload/models/%resource_name%_uploader.rb.tt +19 -0
- data/lib/roda_gen/generators/templates/upload/routes/%plural%.rb.tt +44 -0
- data/lib/roda_gen/generators/templates/upload/spec/web/%plural%_spec.rb.tt +56 -0
- data/lib/roda_gen/generators/templates/upload/views/%plural%/index.erb.tt +18 -0
- data/lib/roda_gen/generators/upload.rb +83 -0
- data/lib/roda_gen/project_context.rb +30 -0
- data/lib/roda_gen/version.rb +5 -0
- data/lib/roda_gen.rb +16 -0
- metadata +497 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
require_relative '../gdpr'
|
|
5
|
+
|
|
6
|
+
# Runs as the app role, which unlike web may read audit_log for an export and
|
|
7
|
+
# redact it for an erasure
|
|
8
|
+
module Daemons
|
|
9
|
+
class GdprWorker < Daemons::Base
|
|
10
|
+
CHANNELS = %w[gdpr_request].freeze
|
|
11
|
+
|
|
12
|
+
def initialize(db: DB, **)
|
|
13
|
+
super(**)
|
|
14
|
+
@db = db
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def run = run_listening(@db, CHANNELS)
|
|
18
|
+
|
|
19
|
+
# Drain every pending row, not just the notified one, so stragglers clear too
|
|
20
|
+
def handle_gdpr_request(_payload)
|
|
21
|
+
GdprRequest.pending.each { |request| fulfill(request) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def fulfill(request)
|
|
27
|
+
account = request.account or raise('account missing')
|
|
28
|
+
send("deliver_#{request.type}", account)
|
|
29
|
+
request.done!
|
|
30
|
+
rescue StandardError => e
|
|
31
|
+
@logger.error("[#{tag}] request #{request.pk} (#{request.type}) failed: #{e.message}")
|
|
32
|
+
request.failed!(e.message)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def deliver_export(account)
|
|
36
|
+
export = Gdpr.export(account).to_json
|
|
37
|
+
<%= @app.camel %>Mailer.sendmail('/data-export', account.email, locale_for(account), export)
|
|
38
|
+
AuditLog.record(action: 'system.data.export', actor_type: :system,
|
|
39
|
+
payload: { account_id: account.id }, status: :success)
|
|
40
|
+
@logger.info("[#{tag}] emailed data export for account #{account.id}")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def deliver_erase(account)
|
|
44
|
+
locale = locale_for(account) # erase! drops the profile, read first
|
|
45
|
+
<%= @app.camel %>Mailer.sendmail('/data-erased', Gdpr.erase!(account), locale)
|
|
46
|
+
@logger.info("[#{tag}] erased account #{account.id}")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def locale_for(account)
|
|
50
|
+
(account.profile&.language || I18n.default_locale).to_s
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
|
|
5
|
+
# Payload is an account id, for instance NOTIFY send_push, '42'
|
|
6
|
+
module Daemons
|
|
7
|
+
class PushSender < Daemons::Base
|
|
8
|
+
CHANNELS = %w[send_push].freeze
|
|
9
|
+
|
|
10
|
+
def initialize(db: DB, **)
|
|
11
|
+
super(**)
|
|
12
|
+
@db = db
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def run = run_listening(@db, CHANNELS)
|
|
16
|
+
|
|
17
|
+
def handle_send_push(payload)
|
|
18
|
+
account = Account[payload.to_s.strip.to_i]
|
|
19
|
+
return unless account
|
|
20
|
+
|
|
21
|
+
message = push_message(account)
|
|
22
|
+
PushSubscription.where(account_id: account.id).each { |sub| deliver(sub, message) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def push_message(account)
|
|
28
|
+
profile = account.profile
|
|
29
|
+
locale = profile ? profile.language.to_sym : I18n.default_locale
|
|
30
|
+
I18n.with_locale(locale) do
|
|
31
|
+
{ title: I18n.t('push.notification.title', app: <%= @app.camel %>Config.site.company.name),
|
|
32
|
+
body: I18n.t('push.notification.body'),
|
|
33
|
+
url: '/' }.to_json
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def deliver(sub, message)
|
|
38
|
+
WebPush.payload_send(message:, endpoint: sub.endpoint, p256dh: sub.p256dh,
|
|
39
|
+
auth: sub.auth_key, vapid: <%= @app.camel %>::VAPID_OPTIONS)
|
|
40
|
+
@logger.info("[#{tag}] pushed to subscription #{sub.id}")
|
|
41
|
+
rescue WebPush::ExpiredSubscription, WebPush::InvalidSubscription
|
|
42
|
+
# 404/410/400, the browser dropped it, prune instead of retrying
|
|
43
|
+
sub.destroy
|
|
44
|
+
@logger.info("[#{tag}] pruned dead subscription #{sub.id}")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Run daily by <%= @app.snake %>-shrine-cleanup.timer, also from bin/shrine_clean_cache
|
|
4
|
+
module Daemons
|
|
5
|
+
module ShrineCacheCleaner
|
|
6
|
+
SETTING_NAME = 'file_cache_retention'
|
|
7
|
+
|
|
8
|
+
def self.cleanup!(
|
|
9
|
+
retention_seconds: Settings.for_system(SETTING_NAME).to_i,
|
|
10
|
+
logger: <%= @app.camel %>.logger
|
|
11
|
+
)
|
|
12
|
+
cutoff = Time.now - retention_seconds
|
|
13
|
+
deleted = 0
|
|
14
|
+
Shrine.storages[:cache].clear! do |path|
|
|
15
|
+
path.mtime < cutoff && (deleted += 1)
|
|
16
|
+
end
|
|
17
|
+
logger.info(
|
|
18
|
+
"[shrine_cache_cleaner] removed #{deleted} cache file(s) older than #{retention_seconds}s"
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Run by rake deploy:check and the puma unit's ExecStartPre
|
|
4
|
+
module Deploy
|
|
5
|
+
module Check
|
|
6
|
+
LEGAL_PLACEHOLDER = /\A\[.+\]\z/
|
|
7
|
+
SMTP_REQUIRED_FIELDS = %i[address user_name password].freeze
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
# Legal pages and footer read site.*, so a leftover "[ORG NR]" ships visibly broken
|
|
12
|
+
def settings_placeholders!
|
|
13
|
+
offenders = []
|
|
14
|
+
%i[company address contact regulator].each do |group|
|
|
15
|
+
section = <%= @app.camel %>Config.site.public_send(group)
|
|
16
|
+
next unless section
|
|
17
|
+
|
|
18
|
+
walk_placeholders(section.to_h, [group.to_s], offenders)
|
|
19
|
+
end
|
|
20
|
+
return if offenders.empty?
|
|
21
|
+
|
|
22
|
+
raise "unfilled placeholders in config/settings.yml: #{offenders.join(', ')}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def walk_placeholders(node, path, offenders)
|
|
26
|
+
node.each do |k, v|
|
|
27
|
+
if v.is_a?(Hash)
|
|
28
|
+
walk_placeholders(v, path + [k.to_s], offenders)
|
|
29
|
+
elsif v.is_a?(String) && v.match?(LEGAL_PLACEHOLDER)
|
|
30
|
+
offenders << "site.#{(path + [k.to_s]).join('.')}=#{v}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def database_url!(url)
|
|
36
|
+
raise 'url is blank' if url.blank?
|
|
37
|
+
|
|
38
|
+
Database.connect(url).tap { |db| db.fetch('SELECT 1').get }.disconnect
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def redis!
|
|
42
|
+
pong = REDIS.with(&:ping)
|
|
43
|
+
raise "expected PONG, got #{pong.inspect}" unless pong == 'PONG'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Dev's empty creds fall through to tmp/mail/*.eml capture, in prod that
|
|
47
|
+
# silently drops outbound mail
|
|
48
|
+
def mail_smtp!
|
|
49
|
+
missing = <%= @app.camel %>Config.mail.accounts.to_h.flat_map { |name, account| missing_smtp_fields(name, account) }
|
|
50
|
+
raise "blank SMTP credentials: #{missing.join(', ')}" unless missing.empty?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def missing_smtp_fields(name, account)
|
|
54
|
+
smtp = account[:smtp] || account['smtp'] || {}
|
|
55
|
+
SMTP_REQUIRED_FIELDS.each_with_object([]) do |key, missing|
|
|
56
|
+
value = smtp[key] || smtp[key.to_s]
|
|
57
|
+
missing << "mail.accounts.#{name}.smtp.#{key}" if value.to_s.strip.empty?
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Without the current partition writes fall to audit_log_default and bypass its
|
|
62
|
+
# grants, without the next one a rollover-timer hiccup blocks the period's first INSERT
|
|
63
|
+
def audit_partitions!
|
|
64
|
+
today = Date.today
|
|
65
|
+
current, = AuditLog.partition_for(today, 0, AuditLog::PARTITION_CADENCE)
|
|
66
|
+
nextp, = AuditLog.partition_for(today, 1, AuditLog::PARTITION_CADENCE)
|
|
67
|
+
missing = [current, nextp].reject { |n| audit_partition_exists?(n) }
|
|
68
|
+
return if missing.empty?
|
|
69
|
+
|
|
70
|
+
raise "missing partitions: #{missing.join(', ')} (run `rake audit:add_next[2]`)"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def audit_partition_exists?(name)
|
|
74
|
+
DB.fetch(<<~SQL, name).any?
|
|
75
|
+
SELECT 1
|
|
76
|
+
FROM pg_inherits i
|
|
77
|
+
JOIN pg_class child ON child.oid = i.inhrelid
|
|
78
|
+
JOIN pg_namespace child_ns ON child_ns.oid = child.relnamespace
|
|
79
|
+
JOIN pg_class parent ON parent.oid = i.inhparent
|
|
80
|
+
JOIN pg_namespace parent_ns ON parent_ns.oid = parent.relnamespace
|
|
81
|
+
WHERE child.relname = ?
|
|
82
|
+
AND child_ns.nspname = 'audit_log'
|
|
83
|
+
AND parent.relname = 'audit_log'
|
|
84
|
+
AND parent_ns.nspname = 'audit_log'
|
|
85
|
+
SQL
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Roda :assets fingerprints on boot but does not compile, a missing file leaves
|
|
89
|
+
# the layout linking to a 404
|
|
90
|
+
def assets_tailwind!
|
|
91
|
+
pattern = File.expand_path('../assets/stylesheets/.compiled/*.css', __dir__)
|
|
92
|
+
compiled = Dir[pattern].select { File.size(it).positive? }
|
|
93
|
+
raise 'no compiled Tailwind output (run `rake tailwind:build`)' if compiled.empty?
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
|
|
5
|
+
class FilteredLogger
|
|
6
|
+
MASK = '<FILTERED>'
|
|
7
|
+
|
|
8
|
+
LEVELS = %i[debug info warn error fatal unknown].freeze
|
|
9
|
+
|
|
10
|
+
def initialize(logger, sensitive_keys)
|
|
11
|
+
@logger = logger
|
|
12
|
+
@sensitive = sensitive_keys.to_h { |key| [key.to_s, true] }.freeze
|
|
13
|
+
keys = Regexp.union(sensitive_keys.map(&:to_s))
|
|
14
|
+
# Query-string shaped values inside logged text, the Rodauth verify
|
|
15
|
+
# and reset links carry their token as ?key=...
|
|
16
|
+
@text_pattern = /([?&]#{keys}=)[^&\s"]+/
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
LEVELS.each do |level|
|
|
20
|
+
define_method(level) do |message = nil, &block|
|
|
21
|
+
if block
|
|
22
|
+
@logger.public_send(level) { filter(block.call) }
|
|
23
|
+
else
|
|
24
|
+
@logger.public_send(level, filter(message))
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def filter(value)
|
|
30
|
+
case value
|
|
31
|
+
when Hash
|
|
32
|
+
value.to_h do |key, val|
|
|
33
|
+
masked = @sensitive[key.to_s] ? MASK : filter(val)
|
|
34
|
+
[key, masked]
|
|
35
|
+
end
|
|
36
|
+
when Array
|
|
37
|
+
value.map { filter(it) }
|
|
38
|
+
when String
|
|
39
|
+
value.gsub(@text_pattern) { "#{Regexp.last_match(1)}#{MASK}" }
|
|
40
|
+
else
|
|
41
|
+
value
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def method_missing(name, ...)
|
|
46
|
+
@logger.public_send(name, ...)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# include_private is Ruby's respond_to_missing? contract
|
|
50
|
+
# :reek:BooleanParameter
|
|
51
|
+
def respond_to_missing?(name, include_private = false)
|
|
52
|
+
@logger.respond_to?(name, include_private) || super
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Export (Art. 15/20) and erasure (Art. 17) on the anonymize-and-retain model
|
|
4
|
+
# App role only, web may not read or redact audit_log
|
|
5
|
+
module Gdpr
|
|
6
|
+
# Rodauth's own tables, no models. account_login_change_keys holds a pending email too
|
|
7
|
+
CREDENTIAL_TABLES = %i[
|
|
8
|
+
account_password_reset_keys account_verification_keys
|
|
9
|
+
account_login_change_keys account_remember_keys
|
|
10
|
+
account_login_failures account_lockouts account_activity_times
|
|
11
|
+
account_otp_keys account_otp_unlocks account_recovery_codes
|
|
12
|
+
].freeze
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def export(account)
|
|
16
|
+
account_id = account.id
|
|
17
|
+
{
|
|
18
|
+
account: export_account(account),
|
|
19
|
+
profile: account.profile&.values&.except(:account_id),
|
|
20
|
+
roles: account.roles.map(&:role),
|
|
21
|
+
privileges: account.all_privileges,
|
|
22
|
+
settings: SettingUserValue.where(account_id: account_id).select_hash(:name, :value),
|
|
23
|
+
push_subscriptions: PushSubscription.where(account_id: account_id).select(:endpoint, :created_at).all,
|
|
24
|
+
audit_events: export_audit(account_id)
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns the original email for the confirmation mail
|
|
29
|
+
def erase!(account)
|
|
30
|
+
account_id = account.id
|
|
31
|
+
email = account.email
|
|
32
|
+
DB.transaction do
|
|
33
|
+
remove_pii!(account_id)
|
|
34
|
+
deactivate!(account_id)
|
|
35
|
+
AuditLog.erase_for_account!(account_id)
|
|
36
|
+
AuditLog.record(action: 'system.data.erase', actor_type: :system,
|
|
37
|
+
payload: { account_id: account_id }, status: :success)
|
|
38
|
+
end
|
|
39
|
+
email
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Audit drops oldest-first by partition, so a skeleton whose deleted_at predates
|
|
43
|
+
# the oldest surviving row has no audit rows left (Art. 5(1)(e)). Run after partitions drop
|
|
44
|
+
def purge_retained!
|
|
45
|
+
oldest = AuditLog.min(:occurred_at)
|
|
46
|
+
accounts = Account.where(Sequel.~(deleted_at: nil))
|
|
47
|
+
accounts = accounts.where { deleted_at < oldest } if oldest
|
|
48
|
+
accounts.select_map(:id).each { |account_id| delete_skeleton!(account_id) }.length
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def export_account(account)
|
|
54
|
+
{
|
|
55
|
+
id: account.id,
|
|
56
|
+
email: account.email,
|
|
57
|
+
status: DB[:account_statuses].where(id: account.status_id).get(:name),
|
|
58
|
+
created_at: account.created_at
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def export_audit(account_id)
|
|
63
|
+
audit_rows_for(account_id)
|
|
64
|
+
.naked.order(Sequel.desc(:occurred_at))
|
|
65
|
+
.select(:occurred_at, :action_id, :status_id, :ip_address)
|
|
66
|
+
.map do |row|
|
|
67
|
+
{
|
|
68
|
+
occurred_at: row[:occurred_at],
|
|
69
|
+
action: AuditAction.cache.key(row[:action_id]),
|
|
70
|
+
status: AuditStatus.cache.key(row[:status_id]),
|
|
71
|
+
ip_address: row[:ip_address]&.to_s
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def remove_pii!(account_id)
|
|
77
|
+
AccountProfile.where(account_id: account_id).delete
|
|
78
|
+
Account.where(id: account_id).update(
|
|
79
|
+
email: "erased-#{account_id}@#{<%= @app.camel %>Config.site.domain.host}.invalid",
|
|
80
|
+
status_id: 3,
|
|
81
|
+
deleted_at: Sequel::CURRENT_TIMESTAMP
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def deactivate!(account_id)
|
|
86
|
+
DB[Sequel[:rodauth_secrets][:account_password_hashes]].where(id: account_id).delete
|
|
87
|
+
CREDENTIAL_TABLES.each { |table| DB[table].where(id: account_id).delete }
|
|
88
|
+
DB[:account_active_session_keys].where(account_id: account_id).delete
|
|
89
|
+
PushSubscription.where(account_id: account_id).delete
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def delete_skeleton!(account_id)
|
|
93
|
+
DB.transaction do
|
|
94
|
+
SettingUserValue.where(updated_by: account_id).update(updated_by: nil)
|
|
95
|
+
SettingUserValue.where(account_id: account_id).delete
|
|
96
|
+
AccountRole.where(account_id: account_id).delete
|
|
97
|
+
AccountPrivilege.where(account_id: account_id).delete
|
|
98
|
+
Account.where(id: account_id).delete
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def audit_rows_for(account_id)
|
|
103
|
+
AuditLog.where { Sequel.|({ actor_id: account_id }, { impersonator_id: account_id }) }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'audit_context'
|
|
4
|
+
|
|
5
|
+
# An event left out of the verb map is not logged. Dataset-level writes
|
|
6
|
+
# (AccountRole.where(...).delete) skip Sequel's hooks and so skip this,
|
|
7
|
+
# Gdpr.delete_skeleton! relies on that and logs system.data.erase instead
|
|
8
|
+
module RbacAudit
|
|
9
|
+
def self.included(model)
|
|
10
|
+
model.plugin :dirty
|
|
11
|
+
model.extend(ClassMethods)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module ClassMethods
|
|
15
|
+
def audit_rbac(prefix, **verbs)
|
|
16
|
+
@audit_rbac_actions = verbs.to_h { |event, verb| [event, "#{prefix}.#{verb}"] }.freeze
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def audit_rbac_action(event) = @audit_rbac_actions[event]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def after_create
|
|
23
|
+
super
|
|
24
|
+
record_rbac_audit(:created, values)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def after_update
|
|
28
|
+
super
|
|
29
|
+
# column_changes, not previous_changes: the dirty plugin assigns previous_changes
|
|
30
|
+
# after its own after_update calls super, so it is still nil here
|
|
31
|
+
record_rbac_audit(:updated, values.merge(changed: column_changes))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def after_destroy
|
|
35
|
+
super
|
|
36
|
+
record_rbac_audit(:deleted, values)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def record_rbac_audit(event, payload)
|
|
42
|
+
action = model.audit_rbac_action(event)
|
|
43
|
+
return unless action
|
|
44
|
+
|
|
45
|
+
AuditLog.record(action: action, payload: payload, status: :success, **AuditContext.current)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :audit do
|
|
4
|
+
desc 'Ensure N audit_log partitions starting from the current period exist at the configured cadence (idempotent)'
|
|
5
|
+
task :add_next, %i[n cadence env] do |_t, args|
|
|
6
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
7
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
8
|
+
require_relative '../../config/boot'
|
|
9
|
+
require_relative '../../config/database'
|
|
10
|
+
require_relative '../../models/audit_log'
|
|
11
|
+
|
|
12
|
+
n = (args[:n] || 1).to_i
|
|
13
|
+
cadence = (args[:cadence] || AuditLog::PARTITION_CADENCE).to_sym
|
|
14
|
+
unless %i[monthly quarterly yearly].include?(cadence)
|
|
15
|
+
abort "Unknown cadence: #{cadence.inspect}. Allowed: :monthly, :quarterly, :yearly"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Offset 0 is the current period. The systemd rollover timer uses [2]
|
|
19
|
+
# so it stays one period ahead through the boundary tick
|
|
20
|
+
0.upto(n - 1) do |offset|
|
|
21
|
+
name, range_start, range_end = AuditLog.partition_for(Date.today, offset, cadence)
|
|
22
|
+
DB.fetch('SELECT audit_log.create_partition(?, ?, ?)',
|
|
23
|
+
name, range_start, range_end).first
|
|
24
|
+
puts "Ensured partition #{name} [#{range_start} .. #{range_end})."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc 'Add a single partition for an explicit YYYY-MM (or YYYY-Q[1-4], or YYYY) period'
|
|
29
|
+
task :add, %i[period env] do |_t, args|
|
|
30
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
31
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
32
|
+
require_relative '../../config/boot'
|
|
33
|
+
require_relative '../../config/database'
|
|
34
|
+
require_relative '../../models/audit_log'
|
|
35
|
+
|
|
36
|
+
name, range_start, range_end = AuditLog.partition_for_period(args.fetch(:period))
|
|
37
|
+
DB.fetch('SELECT audit_log.create_partition(?, ?, ?)',
|
|
38
|
+
name, range_start, range_end).first
|
|
39
|
+
puts "Ensured partition #{name} [#{range_start} .. #{range_end})."
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
desc 'Move rows out of audit_log_default for `period` (YYYY-MM, YYYY-Q1..Q4, YYYY) into a fresh partition'
|
|
43
|
+
task :evacuate_default, %i[period env] do |_t, args|
|
|
44
|
+
period = args[:period].to_s
|
|
45
|
+
abort 'Usage: rake audit:evacuate_default[YYYY-MM]' if period.empty?
|
|
46
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
47
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
48
|
+
require_relative '../../config/boot'
|
|
49
|
+
require_relative '../../config/database'
|
|
50
|
+
require_relative '../../models/audit_log'
|
|
51
|
+
|
|
52
|
+
result = AuditLog.evacuate_default_partition(period)
|
|
53
|
+
case result[:status]
|
|
54
|
+
when :evacuated
|
|
55
|
+
puts "Evacuated #{result[:moved]} row(s) from audit_log_default into #{result[:name]}."
|
|
56
|
+
when :already_partitioned
|
|
57
|
+
puts "#{result[:name]} is already a partition — nothing to evacuate."
|
|
58
|
+
when :nothing_in_default
|
|
59
|
+
puts "audit_log_default has no rows for #{period}; #{result[:name]} not created."
|
|
60
|
+
puts "Use `rake audit:add[#{period}]` instead."
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
desc 'Retention: drop audit_log partitions whose range_end <= cutoff (YYYY-MM-DD)'
|
|
65
|
+
task :drop_partitions_before, %i[cutoff env] do |_t, args|
|
|
66
|
+
cutoff = args[:cutoff].to_s
|
|
67
|
+
abort 'Usage: rake audit:drop_partitions_before[YYYY-MM-DD]' if cutoff.empty?
|
|
68
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
69
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
70
|
+
require_relative '../../<%= @app.snake %>'
|
|
71
|
+
require_relative '../../lib/gdpr'
|
|
72
|
+
|
|
73
|
+
dropped = AuditLog.drop_partitions_before(cutoff)
|
|
74
|
+
if dropped.empty?
|
|
75
|
+
puts "No partitions with range_end <= #{cutoff}."
|
|
76
|
+
else
|
|
77
|
+
dropped.each { |name| puts "Dropped #{name}." }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Dropping the last partition holding an erased account's audit rows
|
|
81
|
+
# removes its retention basis, so purge the pseudonymized skeleton now
|
|
82
|
+
purged = Gdpr.purge_retained!
|
|
83
|
+
puts "Purged #{purged} erased account(s) past retention." if purged.positive?
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
desc 'Open IRB with the full app context (env defaults to RACK_ENV, then development)'
|
|
4
|
+
task :irb, [:env] do |_t, args|
|
|
5
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
6
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
7
|
+
sh 'irb -I. -rconfig/console'
|
|
8
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :db do
|
|
4
|
+
desc 'Migrate the database to latest (env defaults to RACK_ENV)'
|
|
5
|
+
task :up, [:env] do |_t, args|
|
|
6
|
+
migrate(args[:env], nil)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
desc 'Migrate the database down to a target version (0 = all the way down)'
|
|
10
|
+
task :down, [:version, :env] do |_t, args|
|
|
11
|
+
target = args[:version] ? args[:version].to_i : 0
|
|
12
|
+
migrate(args[:env], target)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Migrate down then up (bounce)'
|
|
16
|
+
task :bounce, [:env] do |_t, args|
|
|
17
|
+
migrate(args[:env], 0)
|
|
18
|
+
migrate(args[:env], nil)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
desc 'Load reference data from db/seeds/ into the current DB'
|
|
22
|
+
task :seed, [:env] do |_t, args|
|
|
23
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
24
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
25
|
+
load File.expand_path('../../db/seeds.rb', __dir__)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc 'Create the database for the current RACK_ENV (idempotent, skip if exists)'
|
|
29
|
+
task :create, [:env] do |_t, args|
|
|
30
|
+
ENV['RACK_ENV'] = args[:env] || ENV['RACK_ENV'] || 'development'
|
|
31
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
32
|
+
require_relative '../../config/boot'
|
|
33
|
+
# Not config/database, db:create runs before the DB exists and it would connect
|
|
34
|
+
require_relative '../../config/initializers/02_app_config'
|
|
35
|
+
require 'uri'
|
|
36
|
+
require 'open3'
|
|
37
|
+
|
|
38
|
+
url = <%= @app.camel %>Config.database.app_url.to_s
|
|
39
|
+
url = <%= @app.camel %>Config.database.url.to_s if url.empty?
|
|
40
|
+
uri = URI.parse(url)
|
|
41
|
+
db_name = uri.path.delete_prefix('/')
|
|
42
|
+
|
|
43
|
+
_out, err, status = Open3.capture3(
|
|
44
|
+
'createdb', '-E', 'UTF8', '-T', 'template0', '--locale=sv_SE.UTF-8',
|
|
45
|
+
'-O', uri.user, db_name
|
|
46
|
+
)
|
|
47
|
+
if status.success?
|
|
48
|
+
puts "→ created #{db_name}"
|
|
49
|
+
elsif err.include?('already exists')
|
|
50
|
+
puts "→ #{db_name} already exists (skipping createdb)"
|
|
51
|
+
else
|
|
52
|
+
abort "createdb failed (exit #{status.exitstatus}): #{err.strip}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def migrate(env, version)
|
|
58
|
+
ENV['RACK_ENV'] = env || ENV['RACK_ENV'] || 'development'
|
|
59
|
+
# DDL needs the app role
|
|
60
|
+
ENV['DATABASE_ROLE'] = 'app'
|
|
61
|
+
require_relative '../../config/boot'
|
|
62
|
+
# Not models.rb, :require_valid_schema raises before db:up has created the tables
|
|
63
|
+
require_relative '../../config/database'
|
|
64
|
+
|
|
65
|
+
# Sequel's migrator raises on an empty db/migrate/
|
|
66
|
+
migrations_dir = File.expand_path('../../db/migrate', __dir__)
|
|
67
|
+
if Dir["#{migrations_dir}/*.rb"].empty?
|
|
68
|
+
puts 'No migrations found in db/migrate/ — nothing to do.'
|
|
69
|
+
return
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
Sequel.extension :migration
|
|
73
|
+
Sequel::Migrator.run(DB, 'db/migrate', target: version)
|
|
74
|
+
puts "Migrated #{DB.opts[:database]} to version #{DB[:schema_info].get(:version)}."
|
|
75
|
+
|
|
76
|
+
grant_web_privileges!
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def grant_web_privileges!
|
|
80
|
+
require 'uri'
|
|
81
|
+
web_url = <%= @app.camel %>Config.database.url
|
|
82
|
+
return if web_url.blank?
|
|
83
|
+
|
|
84
|
+
web_user = begin
|
|
85
|
+
URI.parse(web_url).user
|
|
86
|
+
rescue URI::InvalidURIError
|
|
87
|
+
nil
|
|
88
|
+
end
|
|
89
|
+
return if web_user.blank?
|
|
90
|
+
|
|
91
|
+
# Quote as a PG identifier, stops a hostile database.url from injecting SQL
|
|
92
|
+
quoted = "\"#{web_user.gsub('"', '""')}\""
|
|
93
|
+
|
|
94
|
+
DB.run "GRANT USAGE ON SCHEMA public TO #{quoted}"
|
|
95
|
+
DB.run "GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO #{quoted}"
|
|
96
|
+
DB.run "GRANT USAGE, SELECT, UPDATE ON ALL SEQUENCES IN SCHEMA public TO #{quoted}"
|
|
97
|
+
# No FOR ROLE, applies to the connected role (app)
|
|
98
|
+
DB.run "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO #{quoted}"
|
|
99
|
+
DB.run "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT, UPDATE ON SEQUENCES TO #{quoted}"
|
|
100
|
+
|
|
101
|
+
puts "Granted web-role privileges to #{web_user}."
|
|
102
|
+
rescue Sequel::DatabaseError => e
|
|
103
|
+
warn "[db:up] could not grant privileges to #{web_user.inspect}: #{e.message}"
|
|
104
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ExecStartPre gate on the puma unit, a failing check aborts the start
|
|
4
|
+
namespace :deploy do
|
|
5
|
+
desc 'Pre-flight production checks: settings placeholders, DB/Redis connectivity, SMTP, partitions, assets'
|
|
6
|
+
task :check do
|
|
7
|
+
if ENV['SKIP_DEPLOY_CHECKS'] == '1'
|
|
8
|
+
puts '→ SKIP_DEPLOY_CHECKS=1 set; skipping all deploy:check guards'
|
|
9
|
+
next
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require_relative '../../<%= @app.snake %>'
|
|
13
|
+
require_relative '../deploy_check'
|
|
14
|
+
|
|
15
|
+
failures = []
|
|
16
|
+
run_check = lambda do |name, &block|
|
|
17
|
+
block.call
|
|
18
|
+
puts "→ #{name}... OK"
|
|
19
|
+
rescue StandardError => e
|
|
20
|
+
puts "✗ #{name}: #{e.message}"
|
|
21
|
+
failures << [name, e.message]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
run_check.call('settings.placeholders') { Deploy::Check.settings_placeholders! }
|
|
25
|
+
run_check.call('database.web') { Deploy::Check.database_url!(<%= @app.camel %>Config.database.url) }
|
|
26
|
+
run_check.call('database.app') { Deploy::Check.database_url!(<%= @app.camel %>Config.database.app_url) }
|
|
27
|
+
run_check.call('redis') { Deploy::Check.redis! }
|
|
28
|
+
run_check.call('mail.smtp') { Deploy::Check.mail_smtp! }
|
|
29
|
+
run_check.call('audit.partitions') { Deploy::Check.audit_partitions! }
|
|
30
|
+
run_check.call('assets.tailwind') { Deploy::Check.assets_tailwind! }
|
|
31
|
+
|
|
32
|
+
next if failures.empty?
|
|
33
|
+
|
|
34
|
+
warn "\n#{failures.length} check(s) failed:"
|
|
35
|
+
failures.each_with_index { |(n, m), i| warn " #{i + 1}. #{n} — #{m}" }
|
|
36
|
+
exit 1
|
|
37
|
+
end
|
|
38
|
+
end
|