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,23 @@
|
|
|
1
|
+
<form method="post" class="max-w-md mx-auto space-y-4">
|
|
2
|
+
<%%== rodauth.csrf_tag %>
|
|
3
|
+
<%%== rodauth.unlock_account_additional_form_tags %>
|
|
4
|
+
|
|
5
|
+
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box border p-4 space-y-3">
|
|
6
|
+
<legend class="fieldset-legend px-2 text-base font-semibold"><%%= rodauth.unlock_account_button %></legend>
|
|
7
|
+
|
|
8
|
+
<%%== rodauth.unlock_account_explanatory_text %>
|
|
9
|
+
|
|
10
|
+
<%% if rodauth.unlock_account_requires_password? %>
|
|
11
|
+
<label class="block">
|
|
12
|
+
<span class="block mb-1 text-sm font-medium"><%%= rodauth.password_label %></span>
|
|
13
|
+
<input type="password" name="<%%= rodauth.password_param %>"
|
|
14
|
+
class="input w-full" required autocomplete="current-password">
|
|
15
|
+
<%% if err = rodauth.field_error(rodauth.password_param) %>
|
|
16
|
+
<p class="text-error text-sm mt-1"><%%= err %></p>
|
|
17
|
+
<%% end %>
|
|
18
|
+
</label>
|
|
19
|
+
<%% end %>
|
|
20
|
+
</fieldset>
|
|
21
|
+
|
|
22
|
+
<button type="submit" class="btn btn-primary w-full"><%%= rodauth.unlock_account_button %></button>
|
|
23
|
+
</form>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<form action="<%%= rodauth.verify_account_resend_path %>" method="post" class="max-w-md mx-auto space-y-4">
|
|
2
|
+
<%%== rodauth.csrf_tag(rodauth.verify_account_resend_path) %>
|
|
3
|
+
<%%== rodauth.verify_account_resend_additional_form_tags %>
|
|
4
|
+
|
|
5
|
+
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box border p-4 space-y-3">
|
|
6
|
+
<legend class="fieldset-legend px-2 text-base font-semibold"><%%= rodauth.verify_account_resend_button %></legend>
|
|
7
|
+
|
|
8
|
+
<%%== rodauth.verify_account_resend_explanatory_text %>
|
|
9
|
+
|
|
10
|
+
<%% if rodauth.param_or_nil(rodauth.login_param) %>
|
|
11
|
+
<input type="hidden" name="<%%= rodauth.login_param %>" value="<%%= rodauth.param_or_nil(rodauth.login_param) %>">
|
|
12
|
+
<%% else %>
|
|
13
|
+
<label class="block">
|
|
14
|
+
<span class="block mb-1 text-sm font-medium"><%%= rodauth.login_label %></span>
|
|
15
|
+
<input type="<%%= rodauth.login_input_type %>" name="<%%= rodauth.login_param %>"
|
|
16
|
+
class="input w-full" required
|
|
17
|
+
autocomplete="<%%= rodauth.login_field_autocomplete_value %>">
|
|
18
|
+
<%% if err = rodauth.field_error(rodauth.login_param) %>
|
|
19
|
+
<p class="text-error text-sm mt-1"><%%= err %></p>
|
|
20
|
+
<%% end %>
|
|
21
|
+
</label>
|
|
22
|
+
<%% end %>
|
|
23
|
+
</fieldset>
|
|
24
|
+
|
|
25
|
+
<button type="submit" class="btn btn-primary w-full"><%%= rodauth.verify_account_resend_button %></button>
|
|
26
|
+
</form>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<form method="post" class="max-w-md mx-auto space-y-4">
|
|
2
|
+
<%%== rodauth.csrf_tag %>
|
|
3
|
+
<%%== rodauth.verify_account_additional_form_tags %>
|
|
4
|
+
|
|
5
|
+
<%% if rodauth.verify_account_set_password? %>
|
|
6
|
+
<fieldset class="fieldset bg-base-200 border-base-300 rounded-box border p-4 space-y-3">
|
|
7
|
+
<legend class="fieldset-legend px-2 text-base font-semibold"><%%= rodauth.verify_account_button %></legend>
|
|
8
|
+
|
|
9
|
+
<label class="block">
|
|
10
|
+
<span class="block mb-1 text-sm font-medium"><%%= rodauth.password_label %></span>
|
|
11
|
+
<input type="password" name="<%%= rodauth.password_param %>"
|
|
12
|
+
class="input w-full" required autocomplete="new-password" minlength="12">
|
|
13
|
+
<%% if err = rodauth.field_error(rodauth.password_param) %>
|
|
14
|
+
<p class="text-error text-sm mt-1"><%%= err %></p>
|
|
15
|
+
<%% end %>
|
|
16
|
+
</label>
|
|
17
|
+
|
|
18
|
+
<%% if rodauth.require_password_confirmation? %>
|
|
19
|
+
<label class="block">
|
|
20
|
+
<span class="block mb-1 text-sm font-medium"><%%= rodauth.password_confirm_label %></span>
|
|
21
|
+
<input type="password" name="<%%= rodauth.password_confirm_param %>"
|
|
22
|
+
class="input w-full" required autocomplete="new-password">
|
|
23
|
+
<%% if err = rodauth.field_error(rodauth.password_confirm_param) %>
|
|
24
|
+
<p class="text-error text-sm mt-1"><%%= err %></p>
|
|
25
|
+
<%% end %>
|
|
26
|
+
</label>
|
|
27
|
+
<%% end %>
|
|
28
|
+
</fieldset>
|
|
29
|
+
<%% end %>
|
|
30
|
+
|
|
31
|
+
<button type="submit" class="btn btn-primary w-full"><%%= rodauth.verify_account_button %></button>
|
|
32
|
+
</form>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<%%# Styled stand-in for rodauth's Bootstrap default, labels come from rodauth-i18n -%>
|
|
2
|
+
<div class="max-w-md mx-auto space-y-4">
|
|
3
|
+
<form method="post" class="space-y-4">
|
|
4
|
+
<%%== rodauth.csrf_tag %>
|
|
5
|
+
<%%== rodauth.verify_login_change_additional_form_tags %>
|
|
6
|
+
<button type="submit" class="btn btn-primary w-full"><%%= rodauth.verify_login_change_button %></button>
|
|
7
|
+
</form>
|
|
8
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class <%= @app.camel %>
|
|
4
|
+
hash_branch('<%= @plural %>') do |r|
|
|
5
|
+
r.is do
|
|
6
|
+
r.get do
|
|
7
|
+
@records = <%= @resource.camel %>.all
|
|
8
|
+
view('<%= @plural %>/index')
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
r.is Integer do |id|
|
|
13
|
+
r.get do
|
|
14
|
+
@record = <%= @resource.camel %>[id] or r.halt(404)
|
|
15
|
+
view('<%= @plural %>/show')
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe '/<%= @plural %> routes' do
|
|
6
|
+
describe 'GET /<%= @plural %>' do
|
|
7
|
+
it 'renders the index' do
|
|
8
|
+
<%= @resource.camel %>.create(name: 'alpha')
|
|
9
|
+
<%= @resource.camel %>.create(name: 'beta')
|
|
10
|
+
|
|
11
|
+
get '/<%= @plural %>'
|
|
12
|
+
expect(last_response.status).to eq(200)
|
|
13
|
+
expect(last_response.body).to include('alpha', 'beta')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'shows an empty state when no records exist' do
|
|
17
|
+
get '/<%= @plural %>'
|
|
18
|
+
expect(last_response.body).to include('No <%= @plural %> yet')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe 'GET /<%= @plural %>/:id' do
|
|
23
|
+
it 'renders the record' do
|
|
24
|
+
record = <%= @resource.camel %>.create(name: 'gamma')
|
|
25
|
+
|
|
26
|
+
get "/<%= @plural %>/#{record.id}"
|
|
27
|
+
expect(last_response.status).to eq(200)
|
|
28
|
+
expect(last_response.body).to include('gamma')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it '404s on an unknown id' do
|
|
32
|
+
get '/<%= @plural %>/99999'
|
|
33
|
+
expect(last_response.status).to eq(404)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<h1><%= @plural.capitalize %></h1>
|
|
2
|
+
|
|
3
|
+
<%% if @records.empty? %>
|
|
4
|
+
<p>No <%= @plural %> yet.</p>
|
|
5
|
+
<%% else %>
|
|
6
|
+
<ul>
|
|
7
|
+
<%% @records.each do |record| %>
|
|
8
|
+
<li><a href="/<%= @plural %>/<%%= record.id %>"><%%= h record.name %></a></li>
|
|
9
|
+
<%% end %>
|
|
10
|
+
</ul>
|
|
11
|
+
<%% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Sequel.migration do
|
|
4
|
+
change do
|
|
5
|
+
create_table(:<%= @plural %>) do
|
|
6
|
+
primary_key :id
|
|
7
|
+
foreign_key :account_id, :accounts, type: :Bignum, null: false, on_delete: :cascade
|
|
8
|
+
column :file_data, :jsonb, null: false
|
|
9
|
+
DateTime :created_at
|
|
10
|
+
index :account_id
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Shared plumbing for every `roda g upload` resource. Each generated
|
|
4
|
+
# routes file registers it with `plugin UploadServing`; re-registering
|
|
5
|
+
# is a no-op, so any number of upload resources share one copy.
|
|
6
|
+
module UploadServing
|
|
7
|
+
module InstanceMethods
|
|
8
|
+
# Cap from file_upload_max_size, Shrine answers 413 above it, a folder
|
|
9
|
+
# drop's path is kept as metadata once sanitised
|
|
10
|
+
def direct_upload_options
|
|
11
|
+
{
|
|
12
|
+
max_size: Settings.for_system('file_upload_max_size').to_i,
|
|
13
|
+
upload_context: lambda do |request|
|
|
14
|
+
path = request.params['relative_path'].to_s
|
|
15
|
+
keep = path.length.between?(1, 512) && !path.start_with?('/') && !path.split('/').include?('..')
|
|
16
|
+
keep ? { metadata: { 'relative_path' => path } } : {}
|
|
17
|
+
end
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Prod hands off to Caddy with X-Accel-Redirect so no Puma worker streams the file, dev streams inline.
|
|
22
|
+
# The /upload prefix is the storage directory on disk, not a route
|
|
23
|
+
def serve_shrine_file(record, request, derivative: nil)
|
|
24
|
+
request.halt 404 unless record
|
|
25
|
+
io = derivative ? record.file(derivative) : record.file
|
|
26
|
+
request.halt 404 unless io
|
|
27
|
+
|
|
28
|
+
attachment_headers!(io)
|
|
29
|
+
if self.class.production?
|
|
30
|
+
response['X-Accel-Redirect'] = "/upload/#{io.storage_key}/#{io.id}"
|
|
31
|
+
else
|
|
32
|
+
response.write(io.read)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# filename is user supplied, strip quote, CR and LF so Content-Disposition cannot be split
|
|
37
|
+
def attachment_headers!(io)
|
|
38
|
+
safe_name = (io.original_filename || 'file').gsub(/["\r\n]/, '_')
|
|
39
|
+
response['Content-Type'] = io.mime_type || 'application/octet-stream'
|
|
40
|
+
response['Content-Disposition'] = %(inline; filename="#{safe_name}")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# models.rb loads models/*.rb alphabetically and the uploader has to
|
|
4
|
+
# exist before the Attachment include, so require it outright
|
|
5
|
+
require_relative '<%= @resource_name %>_uploader'
|
|
6
|
+
|
|
7
|
+
class <%= @resource.camel %> < Sequel::Model
|
|
8
|
+
include <%= @resource.camel %>Uploader::Attachment(:file)
|
|
9
|
+
|
|
10
|
+
many_to_one :account
|
|
11
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'image_processing/vips'
|
|
4
|
+
|
|
5
|
+
class <%= @resource.camel %>Uploader < Shrine
|
|
6
|
+
# The no-JS path posts raw files to the form and never passes the
|
|
7
|
+
# endpoint's cap, so the validator reuses file_upload_max_size.
|
|
8
|
+
# Add a MIME allowlist here before taking arbitrary uploads
|
|
9
|
+
Attacher.validate do
|
|
10
|
+
validate_max_size Settings.for_system('file_upload_max_size').to_i
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Non-image uploads fail Vips, keep only the thumb that exists
|
|
14
|
+
Attacher.derivatives do |original|
|
|
15
|
+
{ thumb: ImageProcessing::Vips.source(original).resize_to_limit!(300, 300) }
|
|
16
|
+
rescue ::Vips::Error
|
|
17
|
+
{}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class <%= @app.camel %>
|
|
4
|
+
plugin UploadServing
|
|
5
|
+
|
|
6
|
+
hash_branch('<%= @plural %>') do |r|
|
|
7
|
+
rodauth.require_authentication
|
|
8
|
+
|
|
9
|
+
# Direct uploads from upload.js land in :cache here, one file per request
|
|
10
|
+
r.on('cache') { r.run <%= @resource.camel %>Uploader.upload_endpoint(:cache, **direct_upload_options) }
|
|
11
|
+
|
|
12
|
+
r.is do
|
|
13
|
+
r.get do
|
|
14
|
+
@<%= @plural %> = <%= @resource.camel %>.where(account_id: current_account.id).reverse(:id).limit(10).all
|
|
15
|
+
view('<%= @plural %>/index')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
r.post do
|
|
19
|
+
# files[] is cached-file JSON from upload.js or raw multipart files from the <noscript> input
|
|
20
|
+
@pending = (r.params['files'] || []).map { |file| <%= @resource.camel %>.new(account_id: current_account.id, file: file) }
|
|
21
|
+
failed = @pending.reject(&:valid?)
|
|
22
|
+
if failed.empty?
|
|
23
|
+
DB.transaction do
|
|
24
|
+
@pending.each do |record|
|
|
25
|
+
record.file_attacher.create_derivatives
|
|
26
|
+
record.save_changes
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
flash[:notice] = "Uploaded #{@pending.size} file(s)"
|
|
30
|
+
r.redirect '/<%= @plural %>'
|
|
31
|
+
else
|
|
32
|
+
# Render, not redirect, so the form replays the cached uploads in hidden fields
|
|
33
|
+
flash.now[:error] = "Upload failed: #{failed.flat_map { |u| u.errors.full_messages }.uniq.join(', ')}"
|
|
34
|
+
@<%= @plural %> = <%= @resource.camel %>.where(account_id: current_account.id).reverse(:id).limit(10).all
|
|
35
|
+
view('<%= @plural %>/index')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
owned = ->(id) { <%= @resource.camel %>.where(account_id: current_account.id)[id] }
|
|
41
|
+
r.get(Integer, 'thumb') { |id| serve_shrine_file(owned.call(id), r, derivative: :thumb) }
|
|
42
|
+
r.get(Integer) { |id| serve_shrine_file(owned.call(id), r) }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
# LocaleKit 302s bare GETs to /<locale>/…, so the specs target /en/ directly
|
|
6
|
+
RSpec.describe '/<%= @plural %> routes' do
|
|
7
|
+
def index_csrf_tokens
|
|
8
|
+
get '/en/<%= @plural %>'
|
|
9
|
+
form_token = last_response.body[/name="_csrf"\s+value="([^"]+)"/, 1]
|
|
10
|
+
zone_token = last_response.body[/data-csrf="([^"]+)"/, 1]
|
|
11
|
+
[form_token, zone_token]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def direct_upload(zone_token, body: 'hello world', name: 'hello.txt')
|
|
15
|
+
file = Rack::Test::UploadedFile.new(StringIO.new(body), 'text/plain', original_filename: name)
|
|
16
|
+
post '/en/<%= @plural %>/cache', 'file' => file, '_csrf' => zone_token
|
|
17
|
+
last_response
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'requires authentication' do
|
|
21
|
+
get '/en/<%= @plural %>'
|
|
22
|
+
expect(last_response.status).to eq(302)
|
|
23
|
+
expect(last_response.headers['location']).to include('/account/login')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'direct-uploads to cache, saves the record and serves it back to its owner' do
|
|
27
|
+
sign_up_and_log_in
|
|
28
|
+
form_token, zone_token = index_csrf_tokens
|
|
29
|
+
|
|
30
|
+
cached = direct_upload(zone_token)
|
|
31
|
+
expect(cached.status).to eq(200)
|
|
32
|
+
|
|
33
|
+
post '/en/<%= @plural %>', 'files' => [cached.body], '_csrf' => form_token
|
|
34
|
+
expect(last_response.status).to eq(302)
|
|
35
|
+
|
|
36
|
+
record = <%= @resource.camel %>.last
|
|
37
|
+
expect(record.file.original_filename).to eq('hello.txt')
|
|
38
|
+
|
|
39
|
+
get "/en/<%= @plural %>/#{record.id}"
|
|
40
|
+
expect(last_response.status).to eq(200)
|
|
41
|
+
expect(last_response.body).to eq('hello world')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'hides files from other accounts' do
|
|
45
|
+
sign_up_and_log_in
|
|
46
|
+
_form_token, zone_token = index_csrf_tokens
|
|
47
|
+
cached = direct_upload(zone_token)
|
|
48
|
+
form_token, = index_csrf_tokens
|
|
49
|
+
post '/en/<%= @plural %>', 'files' => [cached.body], '_csrf' => form_token
|
|
50
|
+
record = <%= @resource.camel %>.last
|
|
51
|
+
|
|
52
|
+
sign_up_and_log_in
|
|
53
|
+
get "/en/<%= @plural %>/#{record.id}"
|
|
54
|
+
expect(last_response.status).to eq(404)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%%# Drop zone inside the form, a failed submit replays cached uploads from the hidden fields -%>
|
|
2
|
+
<form method="post" action="/<%= @plural %>" enctype="multipart/form-data" class="space-y-4">
|
|
3
|
+
<%%== csrf_tag('/<%= @plural %>') %>
|
|
4
|
+
<%% Array(@pending).each do |record| %>
|
|
5
|
+
<input type="hidden" name="files[]" value="<%%= record.cached_file_data %>">
|
|
6
|
+
<%% end %>
|
|
7
|
+
<%%== render('./_upload_zone', locals: { url: '/<%= @plural %>/cache' }) %>
|
|
8
|
+
<button type="submit" class="btn btn-primary">Save</button>
|
|
9
|
+
</form>
|
|
10
|
+
|
|
11
|
+
<ul class="mt-6 space-y-1">
|
|
12
|
+
<%% @<%= @plural %>.each do |record| %>
|
|
13
|
+
<li>
|
|
14
|
+
<a href="/<%= @plural %>/<%%= record.id %>"><%%= record.file.metadata['relative_path'] || record.file.original_filename %></a>
|
|
15
|
+
<%% if record.file(:thumb) %><img src="/<%= @plural %>/<%%= record.id %>/thumb" alt="" class="inline h-8"><%% end %>
|
|
16
|
+
</li>
|
|
17
|
+
<%% end %>
|
|
18
|
+
</ul>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'thor'
|
|
4
|
+
require 'thor/group'
|
|
5
|
+
|
|
6
|
+
module RodaGen
|
|
7
|
+
module Generators
|
|
8
|
+
# Scaffolds the protected-upload flow on top of the wired Shrine
|
|
9
|
+
# infrastructure (config/initializers/37_shrine.rb, _upload_zone.erb,
|
|
10
|
+
# upload.js): an uploader + model pair, a create_<plural> migration,
|
|
11
|
+
# routes/<plural>.rb with the direct-upload mount at /<plural>/cache
|
|
12
|
+
# and authenticated per-account serving, the index view with the drop
|
|
13
|
+
# zone, and a web spec driving the whole flow.
|
|
14
|
+
#
|
|
15
|
+
# Pluralization is naïve (singular + 's') — pass --plural for
|
|
16
|
+
# irregulars (`attachment --plural attachments` is fine, `box` is not).
|
|
17
|
+
class Upload < Thor::Group
|
|
18
|
+
include Thor::Actions
|
|
19
|
+
include MigrationNumbering
|
|
20
|
+
|
|
21
|
+
def self.exit_on_failure? = true
|
|
22
|
+
|
|
23
|
+
argument :raw_name, type: :string, banner: 'NAME'
|
|
24
|
+
|
|
25
|
+
class_option :force, type: :boolean, default: false,
|
|
26
|
+
desc: 'Overwrite existing files without prompting'
|
|
27
|
+
class_option :plural, type: :string, default: nil,
|
|
28
|
+
desc: 'Plural form (default: NAME + "s")'
|
|
29
|
+
|
|
30
|
+
attr_reader :app, :resource, :resource_name, :plural, :migration_filename
|
|
31
|
+
|
|
32
|
+
def self.source_root
|
|
33
|
+
File.expand_path('templates/upload', __dir__)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def validate_context
|
|
37
|
+
@context = ProjectContext.new
|
|
38
|
+
@app = @context.app
|
|
39
|
+
rescue ProjectContext::NotAProject => e
|
|
40
|
+
say_error e.message
|
|
41
|
+
exit 1
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def validate_name
|
|
45
|
+
@resource = AppName.new(raw_name)
|
|
46
|
+
@resource_name = @resource.snake
|
|
47
|
+
@plural = options[:plural] || "#{@resource.snake}s"
|
|
48
|
+
|
|
49
|
+
unless AppName::VALID.match?(@plural)
|
|
50
|
+
say_error "invalid plural #{@plural.inspect}: must match #{AppName::VALID.source}"
|
|
51
|
+
exit 1
|
|
52
|
+
end
|
|
53
|
+
rescue AppName::InvalidName => e
|
|
54
|
+
say_error e.message
|
|
55
|
+
exit 1
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def calculate_migration_filename
|
|
59
|
+
@migration_filename = next_migration_filename("create_#{@plural}")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def set_destination
|
|
63
|
+
self.destination_root = @context.root
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def render_tree
|
|
67
|
+
directory '.', '.'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def print_next_steps
|
|
71
|
+
say <<~MSG, :green
|
|
72
|
+
|
|
73
|
+
bundle exec rake db:up # apply the migration
|
|
74
|
+
|
|
75
|
+
What stays manual (README: Uploads and protected serving):
|
|
76
|
+
* burst throttle for /#{plural}/cache in config/initializers/25_rack_attack.rb
|
|
77
|
+
* production: the X-Accel block and request_body cap in deploy/Caddyfile
|
|
78
|
+
* a MIME allowlist in models/#{resource_name}_uploader.rb before taking arbitrary uploads
|
|
79
|
+
MSG
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RodaGen
|
|
4
|
+
# Detects that the cwd looks like a roda-gen project and derives the
|
|
5
|
+
# application's AppName from the project file structure. Used by every
|
|
6
|
+
# in-project subcommand (`daemon`, `db_daemon`, `resource`).
|
|
7
|
+
class ProjectContext
|
|
8
|
+
class NotAProject < StandardError; end
|
|
9
|
+
|
|
10
|
+
MARKERS = %w[config/boot.rb config/database.rb Gemfile].freeze
|
|
11
|
+
|
|
12
|
+
attr_reader :root, :app
|
|
13
|
+
|
|
14
|
+
def initialize(root = Dir.pwd)
|
|
15
|
+
@root = root
|
|
16
|
+
|
|
17
|
+
missing = MARKERS.reject { |m| File.exist?(File.join(root, m)) }
|
|
18
|
+
unless missing.empty?
|
|
19
|
+
raise NotAProject,
|
|
20
|
+
"cwd #{root.inspect} doesn't look like a roda-gen project " \
|
|
21
|
+
"(missing #{missing.join(', ')})"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
app_file = Dir[File.join(root, '*.rb')].find { |f| File.read(f).match?(/^\s*class\s+\w+\s*<\s*Roda\b/) }
|
|
25
|
+
raise NotAProject, "no <name>.rb with `class X < Roda` at #{root.inspect}" unless app_file
|
|
26
|
+
|
|
27
|
+
@app = AppName.new(File.basename(app_file, '.rb'))
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/roda_gen.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'roda_gen/version'
|
|
4
|
+
require_relative 'roda_gen/app_name'
|
|
5
|
+
require_relative 'roda_gen/project_context'
|
|
6
|
+
require_relative 'roda_gen/generators/migration_numbering'
|
|
7
|
+
require_relative 'roda_gen/generators/project'
|
|
8
|
+
require_relative 'roda_gen/generators/daemon'
|
|
9
|
+
require_relative 'roda_gen/generators/model'
|
|
10
|
+
require_relative 'roda_gen/generators/migration'
|
|
11
|
+
require_relative 'roda_gen/generators/route'
|
|
12
|
+
require_relative 'roda_gen/generators/upload'
|
|
13
|
+
require_relative 'roda_gen/cli'
|
|
14
|
+
|
|
15
|
+
module RodaGen
|
|
16
|
+
end
|