trek 2.5.0 → 2.7.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 +4 -4
- data/.node-version +1 -1
- data/AGENTS.md +18 -14
- data/CHANGELOG.md +88 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +135 -124
- data/Makefile +9 -1
- data/README.md +17 -21
- data/app/components/trek/dashboard/tile_component/tile_component.css +9 -0
- data/app/components/trek/dashboard/tile_component/tile_component.html.slim +4 -2
- data/app/components/trek/dashboard/tile_component.rb +12 -2
- data/app/components/trek/form/content_editor_component/content_editor_component.css +9 -8
- data/app/components/trek/form/content_editor_component/content_editor_component.html.slim +19 -93
- data/app/components/trek/form/content_editor_component/content_editor_component.js +94 -251
- data/app/components/trek/form/content_editor_component/extensions/block_view.js +40 -0
- data/app/components/trek/form/content_editor_component/extensions/image_block.js +28 -26
- data/app/components/trek/form/content_editor_component/extensions/prompts_block.js +15 -26
- data/app/components/trek/form/content_editor_component/extensions/table_of_contents.js +1 -3
- data/app/components/trek/form/content_editor_component.rb +15 -0
- data/app/components/trek/form/image_field_component/image_field_component.css +40 -1
- data/app/components/trek/form/image_field_component/image_field_component.html.slim +0 -9
- data/app/components/trek/form/image_field_component/image_field_component.js +1 -2
- data/app/components/trek/form/image_field_component.rb +36 -9
- data/app/components/trek/form/password_strength_component/password_strength_component.css +2 -0
- data/app/components/trek/form/sound_field_component/sound_field_component.js +1 -2
- data/app/components/trek/security_check_component/security_check_component.css +69 -0
- data/app/components/trek/security_check_component/security_check_component.html.slim +19 -0
- data/app/components/trek/security_check_component/security_check_component.js +15 -0
- data/app/components/trek/security_check_component.rb +19 -0
- data/app/content/trek/content/cleaner.rb +53 -0
- data/app/content/trek/content/document.rb +2 -2
- data/app/content/trek/content/list_item.rb +1 -1
- data/app/content/trek/content/paragraph.rb +7 -2
- data/app/content/trek/content/prompts_block.rb +1 -2
- data/app/content/trek/content.rb +6 -0
- data/app/controllers/concerns/trek/auditable.rb +5 -2
- data/app/controllers/concerns/trek/localization.rb +6 -2
- data/app/controllers/concerns/trek/reorderable.rb +24 -6
- data/app/controllers/trek/csp_reports_controller.rb +14 -1
- data/app/controllers/trek/panels/prompts_controller.rb +1 -1
- data/app/controllers/trek/resource_controller.rb +5 -5
- data/app/jobs/trek/purge_expired_sessions_job.rb +4 -3
- data/app/jobs/trek/purge_expired_sign_in_codes_job.rb +15 -0
- data/app/models/concerns/trek/contentable.rb +15 -1
- data/app/models/concerns/trek/users/sign_in_code.rb +70 -0
- data/app/models/concerns/trek/users/sign_in_lockout.rb +4 -2
- data/app/policies/trek/security_check_policy.rb +8 -0
- data/app/uploaders/image_uploader.rb +77 -15
- data/app/views/trek/panels/links/_form.html.slim +2 -4
- data/app/views/trek/panels/prompts/create.turbo_stream.slim +0 -1
- data/config/locales/trek.en.yml +97 -11
- data/config/locales/trek.fr.yml +97 -11
- data/docs/.vitepress/config.mjs +5 -1
- data/docs/background-jobs.md +74 -0
- data/docs/content-editor.md +219 -0
- data/docs/customize.md +2 -0
- data/docs/deploy.md +69 -6
- data/docs/getting-started.md +16 -18
- data/docs/index.md +2 -2
- data/docs/personal-data.md +61 -0
- data/docs/proxies.md +2 -2
- data/docs/reference/components.md +4 -4
- data/docs/reference/concerns/contentable.md +10 -4
- data/docs/reference/concerns/formattable.md +1 -1
- data/docs/reference/concerns/fragmentable.md +12 -6
- data/docs/reference/concerns/orderable.md +2 -2
- data/docs/reference/concerns/search-engine-optimizable.md +1 -1
- data/docs/reference/concerns/searchable.md +14 -1
- data/docs/reference/concerns/sectionable.md +7 -3
- data/docs/reference/concerns/versionable.md +1 -1
- data/docs/reference/controllers.md +33 -1
- data/docs/reference/environment-variables.md +3 -2
- data/docs/reference/formatters.md +4 -31
- data/docs/reference/forms.md +7 -4
- data/docs/reference/generators/admin-user.md +1 -1
- data/docs/reference/generators/audit-log.md +12 -13
- data/docs/reference/generators/install.md +23 -11
- data/docs/reference/generators/public-accounts.md +159 -0
- data/docs/reference/generators/scaffold.md +28 -9
- data/docs/reference/generators/security-headers.md +5 -4
- data/docs/reference/generators/taxonomies.md +1 -1
- data/docs/reference/icons.md +5 -3
- data/docs/reference/index.md +10 -7
- data/docs/reference/models/current.md +5 -3
- data/docs/reference/models/page-version.md +1 -1
- data/docs/reference/models/user.md +7 -8
- data/docs/reference/uploaders.md +25 -0
- data/docs/reference/validators.md +1 -1
- data/docs/security.md +30 -9
- data/docs/what-is-trek.md +4 -4
- data/lib/generators/trek/USAGE +1 -1
- data/lib/generators/trek/audit_log_generator.rb +62 -0
- data/lib/generators/trek/helpers.rb +17 -0
- data/lib/generators/trek/install/admin/routes_generator.rb +2 -1
- data/lib/generators/trek/install/admin/security_check_generator.rb +36 -0
- data/lib/generators/trek/install/admin/users_generator.rb +6 -1
- data/lib/generators/trek/install/audit_log_generator.rb +9 -45
- data/lib/generators/trek/install/ci_generator.rb +19 -0
- data/lib/generators/trek/install/good_job_generator.rb +161 -0
- data/lib/generators/trek/install/model_specs_generator.rb +3 -3
- data/lib/generators/trek/install/postcss_generator.rb +1 -2
- data/lib/generators/trek/install/ruby_generator.rb +1 -1
- data/lib/generators/trek/install/scalingo_generator.rb +7 -45
- data/lib/generators/trek/install/translations_generator.rb +1 -2
- data/lib/generators/trek/install_generator.rb +18 -2
- data/lib/generators/trek/public_accounts_generator.rb +294 -0
- data/lib/generators/trek/scaffold_generator.rb +22 -21
- data/lib/generators/trek/scalingo_generator.rb +67 -0
- data/lib/generators/trek/templates/.gitlab-ci.yml +10 -1
- data/lib/generators/trek/templates/AGENTS.md +2 -2
- data/lib/generators/trek/templates/Makefile +1 -0
- data/lib/generators/trek/templates/config/i18n-tasks.yml.erb +0 -8
- data/lib/generators/trek/templates/controllers/admin/password_renewals_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/admin/security_checks_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/admin/user_sessions_controller.rb +1 -1
- data/lib/generators/trek/templates/controllers/admin/users_controller.rb +0 -8
- data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +13 -4
- data/lib/generators/trek/templates/initializers/content_security_policy.rb +3 -2
- data/lib/generators/trek/templates/initializers/good_job.rb.tt +40 -0
- data/lib/generators/trek/templates/jobs/mail_delivery_job.rb +6 -0
- data/lib/generators/trek/templates/layouts/admin.html.slim +10 -0
- data/lib/generators/trek/templates/mailers/admin_mailer.rb +4 -2
- data/lib/generators/trek/templates/package.json.tt +1 -1
- data/lib/generators/trek/templates/policies/security_check.rb +4 -0
- data/lib/generators/trek/templates/public_accounts/api/authentication.rb.tt +76 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/accounts_controller.rb.tt +22 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/active_sessions_controller.rb.tt +21 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/base_controller.rb.tt +71 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/email_changes_controller.rb.tt +55 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/email_confirmations_controller.rb.tt +19 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/password_resets_controller.rb.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/passwords_controller.rb.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/registrations_controller.rb.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sessions_controller.rb.tt +57 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sign_in_codes_controller.rb.tt +20 -0
- data/lib/generators/trek/templates/public_accounts/jobs/sign_in_code_job.rb.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.en.yml.tt +215 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.fr.yml.tt +215 -0
- data/lib/generators/trek/templates/public_accounts/mailers/account_mailer.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/migrations/create_accounts.rb.tt +46 -0
- data/lib/generators/trek/templates/public_accounts/models/account/session.rb.tt +47 -0
- data/lib/generators/trek/templates/public_accounts/models/account/sign_in_code.rb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/models/account.rb.tt +87 -0
- data/lib/generators/trek/templates/public_accounts/spec/api/accounts_spec.rb.tt +90 -0
- data/lib/generators/trek/templates/public_accounts/spec/api/sign_ins_spec.rb.tt +188 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account/sign_in_code_spec.rb.tt +66 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account_spec.rb.tt +129 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/accounts_spec.rb.tt +126 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/authentication_spec.rb.tt +43 -0
- data/lib/generators/trek/templates/public_accounts/spec/web/sign_ins_spec.rb.tt +237 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.html.slim.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.en.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.html.slim.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_change_code.fr.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/email_confirmation.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.html.slim.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.en.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.html.slim.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/password_reset.fr.text.erb.tt +8 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.en.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.html.slim.tt +9 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_code.fr.text.erb.tt +11 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.html.slim.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.en.text.erb.tt +14 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.html.slim.tt +24 -0
- data/lib/generators/trek/templates/public_accounts/views/mailer/sign_in_locked.fr.text.erb.tt +14 -0
- data/lib/generators/trek/templates/public_accounts/web/authentication.rb.tt +97 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/accounts_controller.rb.tt +33 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/active_sessions_controller.rb.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/base_controller.rb.tt +52 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/email_changes_controller.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/email_confirmations_controller.rb.tt +19 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/password_resets_controller.rb.tt +41 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/passwords_controller.rb.tt +23 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/registrations_controller.rb.tt +24 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sessions_controller.rb.tt +85 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sign_in_codes_controller.rb.tt +32 -0
- data/lib/generators/trek/templates/public_accounts/web/views/_flash.html.slim.tt +5 -0
- data/lib/generators/trek/templates/public_accounts/web/views/accounts/show.html.slim.tt +52 -0
- data/lib/generators/trek/templates/public_accounts/web/views/email_changes/edit.html.slim.tt +17 -0
- data/lib/generators/trek/templates/public_accounts/web/views/email_changes/new.html.slim.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/edit.html.slim.tt +29 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/new.html.slim.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/web/views/passwords/edit.html.slim.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/web/views/registrations/new.html.slim.tt +30 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sessions/new.html.slim.tt +40 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sign_in_codes/new.html.slim.tt +17 -0
- data/lib/generators/trek/templates/spec/jobs/mail_delivery_job_spec.rb +11 -0
- data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +10 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +1 -1
- data/lib/generators/trek/templates/spec/requests/admin/good_job_spec.rb +34 -0
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +12 -1
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +16 -0
- data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +2 -2
- data/lib/generators/trek/templates/spec/requests/admin/security_checks_spec.rb +24 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_lockout_spec.rb +1 -1
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +33 -0
- data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +2 -2
- data/lib/generators/trek/templates/views/admin/pages/_form.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin/security_checks/show.html.slim +9 -0
- data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +6 -1
- data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +4 -1
- data/lib/generators/trek/templates/views/admin/users/index.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.text.erb +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.text.erb +1 -1
- data/lib/tasks/trek/attachments.rake +12 -0
- data/lib/tasks/trek/security.rake +10 -0
- data/lib/trek/csp_reports.rb +22 -4
- data/lib/trek/disposable_email_domains.rb +9 -20
- data/lib/trek/engine.rb +5 -0
- data/lib/trek/json_compatibility.rb +20 -0
- data/lib/trek/security_check.rb +241 -0
- data/lib/trek/stored_image_metadata.rb +88 -0
- data/lib/trek/typography_formatter.rb +35 -4
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +2 -1
- data/package.json +16 -13
- data/postcss.config.js +0 -3
- data/trek.gemspec +6 -7
- data/vitest.config.mjs +24 -0
- data/yarn.lock +1667 -1010
- metadata +122 -33
|
@@ -13,11 +13,10 @@ module Trek
|
|
|
13
13
|
source_root File.expand_path("../templates", __dir__)
|
|
14
14
|
|
|
15
15
|
def add_gem
|
|
16
|
-
install_needed = %w[rails-i18n i18n-tasks
|
|
16
|
+
install_needed = %w[rails-i18n i18n-tasks mobility].any? { |name| !in_gemfile?(name) }
|
|
17
17
|
|
|
18
18
|
gem "rails-i18n", ">= 6.0.0" unless in_gemfile?("rails-i18n")
|
|
19
19
|
gem "i18n-tasks", "~> 1.0" unless in_gemfile?("i18n-tasks")
|
|
20
|
-
gem "deepl-rb", "~> 3.0" unless in_gemfile?("deepl-rb")
|
|
21
20
|
gem "mobility", "~> 1.3.2" unless in_gemfile?("mobility")
|
|
22
21
|
bundle_install if install_needed
|
|
23
22
|
end
|
|
@@ -72,6 +72,11 @@ module Trek
|
|
|
72
72
|
generate_inline "trek:install:strip_attributes"
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
# Before the emails: the mailer configuration points at MailDeliveryJob.
|
|
76
|
+
def install_jobs
|
|
77
|
+
generate_inline "trek:install:good_job"
|
|
78
|
+
end
|
|
79
|
+
|
|
75
80
|
def install_emails
|
|
76
81
|
generate_inline "trek:install:postmark"
|
|
77
82
|
generate_inline "trek:install:mailer"
|
|
@@ -143,6 +148,7 @@ module Trek
|
|
|
143
148
|
generate_inline "trek:install:admin:user_password_resets"
|
|
144
149
|
generate_inline "trek:install:admin:user_sessions"
|
|
145
150
|
generate_inline "trek:install:admin:users"
|
|
151
|
+
generate_inline "trek:install:admin:security_check"
|
|
146
152
|
end
|
|
147
153
|
|
|
148
154
|
def install_assets
|
|
@@ -174,17 +180,27 @@ module Trek
|
|
|
174
180
|
say ""
|
|
175
181
|
say "Create an admin user with:"
|
|
176
182
|
say ""
|
|
177
|
-
say " rails g trek:admin:user --email admin@example.com --password ************"
|
|
183
|
+
say " bin/rails g trek:admin:user --email admin@example.com --password ************"
|
|
178
184
|
say ""
|
|
179
185
|
say "Then start the server:"
|
|
180
186
|
say ""
|
|
181
187
|
say " make dev"
|
|
182
188
|
say ""
|
|
189
|
+
say "More generators, to run when the app needs them:"
|
|
190
|
+
say ""
|
|
191
|
+
say " bin/rails g trek:scaffold Book title intro:text # a model and its admin panel"
|
|
192
|
+
say " bin/rails g trek:taxonomies # tags and their categories"
|
|
193
|
+
say " bin/rails g trek:audit_log # a log of the admin's requests"
|
|
194
|
+
say " bin/rails g trek:public_accounts Customer # accounts for the site's users, apart from the admin's"
|
|
195
|
+
say " bin/rails g trek:scalingo # the files deploying to Scalingo"
|
|
196
|
+
say ""
|
|
197
|
+
say "All of Trek's generators and their options: https://trek.etamin.studio/reference/#generators"
|
|
198
|
+
say ""
|
|
183
199
|
end
|
|
184
200
|
|
|
185
201
|
private
|
|
186
202
|
|
|
187
|
-
# Runs a generator in this process rather than in a new `rails generate`, which boots the app
|
|
203
|
+
# Runs a generator in this process rather than in a new `bin/rails generate`, which boots the app
|
|
188
204
|
# again: for Trek's 50-odd generators, that took about two minutes. Other gems' generators keep
|
|
189
205
|
# their own process (`generate`), as they may need a gem this run just added to the Gemfile.
|
|
190
206
|
def generate_inline(name)
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
require "rails/generators/named_base"
|
|
2
|
+
require "rails/generators/migration"
|
|
3
|
+
require "generators/trek/helpers"
|
|
4
|
+
|
|
5
|
+
module Trek
|
|
6
|
+
module Generators
|
|
7
|
+
# Accounts for the site's or the mobile app's users (customers, members…), apart from the admin's
|
|
8
|
+
# User: their own model, table, sessions and sign-in, so nothing public can reach a staff account.
|
|
9
|
+
#
|
|
10
|
+
# They sign in one way, picked with --sign-in:
|
|
11
|
+
#
|
|
12
|
+
# - `code` (default): a code emailed to them, which creates the account the first time, unless
|
|
13
|
+
# --invite-only: then only the accounts the app created sign in;
|
|
14
|
+
# - `password`: a password chosen on signing up, the email confirmed by a link, and reset by one.
|
|
15
|
+
#
|
|
16
|
+
# By default for a website: pages, and sessions kept in a cookie. With --api, for a mobile app:
|
|
17
|
+
# JSON endpoints, and sessions held through a JWT instead. With --model-only, neither: the models,
|
|
18
|
+
# mails and specs, for an app whose sign-in is its own (e.g. an API ported from another app).
|
|
19
|
+
class PublicAccountsGenerator < Rails::Generators::NamedBase
|
|
20
|
+
# Taken by the admin's account and Trek's own models, or planned for Trek 3 (Staff::User).
|
|
21
|
+
RESERVED_NAMES = %w[User Staff Session Current Page PagePath PageVersion Fragment MenuNode Tag Tagging TagCategory
|
|
22
|
+
ExternalLink AuditLog Dashboard].freeze
|
|
23
|
+
SIGN_INS = %w[code password].freeze
|
|
24
|
+
JWT_VERSION = "~> 3.1".freeze
|
|
25
|
+
|
|
26
|
+
include Rails::Generators::Migration
|
|
27
|
+
include Trek::Generators::Helpers
|
|
28
|
+
|
|
29
|
+
desc "Create accounts for the site's or the app's users, apart from the admin's: " \
|
|
30
|
+
"bin/rails g trek:public_accounts Customer [--sign-in=code|password] [--invite-only] [--api] [--path=customers] [--model-only]"
|
|
31
|
+
|
|
32
|
+
class_option :sign_in, type: :string, default: "code", enum: SIGN_INS,
|
|
33
|
+
desc: "How accounts sign in: with a code emailed to them, or with a password"
|
|
34
|
+
class_option :invite_only, type: :boolean, default: false,
|
|
35
|
+
desc: "Only the accounts the app created sign in: a code never creates one (with --sign-in=code)"
|
|
36
|
+
class_option :api, type: :boolean, default: false,
|
|
37
|
+
desc: "JSON endpoints and JWTs for a mobile app, instead of pages and a cookie"
|
|
38
|
+
class_option :path, type: :string, default: nil,
|
|
39
|
+
desc: "A path to put the routes under, e.g. members for /members/sign-in"
|
|
40
|
+
class_option :model_only, type: :boolean, default: false,
|
|
41
|
+
desc: "Only the models, mails and specs: no controllers, pages, routes nor tokens, the app signs in its own way"
|
|
42
|
+
|
|
43
|
+
source_root File.expand_path("templates/public_accounts", __dir__)
|
|
44
|
+
|
|
45
|
+
def check_name
|
|
46
|
+
return unless class_name.include?("::") || RESERVED_NAMES.include?(class_name)
|
|
47
|
+
|
|
48
|
+
raise Thor::Error, "#{class_name} can't be a public account model: pick a top-level name of the app's domain " \
|
|
49
|
+
"(Customer, Member, Reader…), other than #{RESERVED_NAMES.to_sentence(last_word_connector: " or ")}."
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def check_options
|
|
53
|
+
if model_only? && (api? || options[:path].present?)
|
|
54
|
+
raise Thor::Error, "--model-only adds no endpoints nor routes: drop --api and --path."
|
|
55
|
+
end
|
|
56
|
+
return unless invite_only? && password?
|
|
57
|
+
|
|
58
|
+
raise Thor::Error, "--invite-only only applies to --sign-in=code."
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def add_jwt_gem
|
|
62
|
+
return unless api?
|
|
63
|
+
return if in_gemfile?("jwt")
|
|
64
|
+
|
|
65
|
+
gem "jwt", JWT_VERSION
|
|
66
|
+
bundle_install
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def copy_models
|
|
70
|
+
template "models/account.rb.tt", "app/models/#{file_name}.rb"
|
|
71
|
+
template "models/account/session.rb.tt", "app/models/#{file_name}/session.rb"
|
|
72
|
+
template "models/account/sign_in_code.rb.tt", "app/models/#{file_name}/sign_in_code.rb" if code?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def copy_migration
|
|
76
|
+
return unless defined?(ActiveRecord)
|
|
77
|
+
|
|
78
|
+
migration_template "migrations/create_accounts.rb.tt", "db/migrate/trek_create_#{table_name}.rb",
|
|
79
|
+
migration_class_name:
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def add_current_attributes
|
|
83
|
+
inject_into_class "app/models/current.rb", "Current", <<-RUBY
|
|
84
|
+
# The signed-in #{human_name.downcase} (#{model_only? ? "set by the app's own sign-in" : "#{accounts_module}::Authentication"})
|
|
85
|
+
attribute :#{file_name}_session
|
|
86
|
+
delegate :#{file_name}, to: :#{file_name}_session, allow_nil: true
|
|
87
|
+
|
|
88
|
+
RUBY
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def copy_authentication_concern
|
|
92
|
+
return if model_only?
|
|
93
|
+
|
|
94
|
+
template "#{mode}/authentication.rb.tt", "app/controllers/concerns/#{accounts_path}/authentication.rb"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Every page of the site may show who is signed in. The API's controllers include it in their
|
|
98
|
+
# base controller instead.
|
|
99
|
+
def include_authentication_in_application_controller
|
|
100
|
+
return unless web?
|
|
101
|
+
|
|
102
|
+
inject_into_class "app/controllers/application_controller.rb", "ApplicationController",
|
|
103
|
+
" include #{accounts_module}::Authentication\n"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def copy_controllers
|
|
107
|
+
return if model_only?
|
|
108
|
+
|
|
109
|
+
controllers.each do |controller|
|
|
110
|
+
template "#{mode}/controllers/#{controller}_controller.rb.tt", "app/controllers/#{controllers_path}/#{controller}_controller.rb"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def copy_views
|
|
115
|
+
return unless web?
|
|
116
|
+
|
|
117
|
+
template "web/views/_flash.html.slim.tt", "app/views/#{controllers_path}/_flash.html.slim"
|
|
118
|
+
views.each do |view|
|
|
119
|
+
template "web/views/#{view}.html.slim.tt", "app/views/#{controllers_path}/#{view}.html.slim"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def copy_job
|
|
124
|
+
template "jobs/sign_in_code_job.rb.tt", "app/jobs/#{accounts_path}/sign_in_code_job.rb" if code?
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def copy_mailer
|
|
128
|
+
template "mailers/account_mailer.rb.tt", "app/mailers/#{file_name}_mailer.rb"
|
|
129
|
+
mails.product(%w[en fr], %w[html.slim text.erb]).each do |mail, locale, format|
|
|
130
|
+
template "views/mailer/#{mail}.#{locale}.#{format}.tt", "app/views/#{file_name}_mailer/#{mail}.#{locale}.#{format}"
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def copy_locales
|
|
135
|
+
%w[en fr].each do |locale|
|
|
136
|
+
template "locales/accounts.#{locale}.yml.tt", "config/locales/#{accounts_path}.#{locale}.yml"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def add_routes
|
|
141
|
+
route routes unless model_only?
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Its sessions expire as the admin's do (Trek::Users::SessionLifetime), and are purged the same way
|
|
145
|
+
def schedule_session_purge
|
|
146
|
+
schedule_in_good_job_cron :"purge_expired_#{file_name}_sessions",
|
|
147
|
+
job_class: "Trek::PurgeExpiredSessionsJob",
|
|
148
|
+
args: ["#{class_name}::Session"],
|
|
149
|
+
cron: "30 3 * * *",
|
|
150
|
+
description: "Delete the #{human_name.downcase} sessions past their idle timeout or lifetime"
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Each code holds an email, and only a new one deletes the expired ones
|
|
154
|
+
def schedule_sign_in_code_purge
|
|
155
|
+
return unless code?
|
|
156
|
+
|
|
157
|
+
schedule_in_good_job_cron :"purge_expired_#{file_name}_sign_in_codes",
|
|
158
|
+
job_class: "Trek::PurgeExpiredSignInCodesJob",
|
|
159
|
+
args: ["#{class_name}::SignInCode"],
|
|
160
|
+
cron: "45 3 * * *",
|
|
161
|
+
description: "Delete the #{human_name.downcase} sign-in codes past their validity"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def copy_specs
|
|
165
|
+
return unless File.directory?(File.join(destination_root, "spec"))
|
|
166
|
+
|
|
167
|
+
template "spec/models/account_spec.rb.tt", "spec/models/#{file_name}_spec.rb"
|
|
168
|
+
template "spec/models/account/sign_in_code_spec.rb.tt", "spec/models/#{file_name}/sign_in_code_spec.rb" if code?
|
|
169
|
+
return if model_only?
|
|
170
|
+
|
|
171
|
+
template "spec/#{mode}/sign_ins_spec.rb.tt", "spec/requests/#{controllers_path}/sign_ins_spec.rb"
|
|
172
|
+
template "spec/#{mode}/accounts_spec.rb.tt", "spec/requests/#{controllers_path}/accounts_spec.rb"
|
|
173
|
+
return if api?
|
|
174
|
+
|
|
175
|
+
template "spec/web/authentication_spec.rb.tt", "spec/controllers/application_controller_#{accounts_path}_spec.rb"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
private
|
|
179
|
+
|
|
180
|
+
def code? = options[:sign_in] == "code"
|
|
181
|
+
def password? = options[:sign_in] == "password"
|
|
182
|
+
def invite_only? = options[:invite_only]
|
|
183
|
+
def api? = options[:api]
|
|
184
|
+
def model_only? = options[:model_only]
|
|
185
|
+
# Pages and a cookie: neither --api nor --model-only
|
|
186
|
+
def web? = !api? && !model_only?
|
|
187
|
+
def mode = api? ? "api" : "web"
|
|
188
|
+
# With trek:install:audit_log, which the account controllers write to
|
|
189
|
+
def audit_log? = File.exist?(File.join(destination_root, "app/models/audit_log.rb"))
|
|
190
|
+
|
|
191
|
+
# Customers: the module of the authentication concern, and the folder of its files.
|
|
192
|
+
def accounts_module = class_name.pluralize
|
|
193
|
+
def accounts_path = file_name.pluralize
|
|
194
|
+
|
|
195
|
+
# The controllers' module and folder: under Api::V1:: for the API, the first version of it, so that a
|
|
196
|
+
# later version can be served next to it while older releases of the mobile app still use this one.
|
|
197
|
+
def controllers_module = api? ? "Api::V1::#{accounts_module}" : accounts_module
|
|
198
|
+
def controllers_path = api? ? "api/v1/#{accounts_path}" : accounts_path
|
|
199
|
+
|
|
200
|
+
# The route helpers' prefix: customer_sign_in_path, api_v1_customer_sign_in_path…
|
|
201
|
+
def route_prefix = api? ? "api_v1_#{file_name}" : file_name
|
|
202
|
+
|
|
203
|
+
# Where the routes go: /sign-in, /members/sign-in, /api/v1/sign-in…
|
|
204
|
+
def routes_path = [("api/v1" if api?), options[:path].presence].compact.join("/").presence
|
|
205
|
+
|
|
206
|
+
def controllers
|
|
207
|
+
names = code? ? %w[sign_in_codes sessions] : %w[registrations sessions password_resets email_confirmations passwords]
|
|
208
|
+
%w[base] + names + %w[accounts email_changes active_sessions]
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def views
|
|
212
|
+
shared = %w[sessions/new accounts/show email_changes/new]
|
|
213
|
+
if code?
|
|
214
|
+
shared + %w[sign_in_codes/new email_changes/edit]
|
|
215
|
+
else
|
|
216
|
+
shared + %w[registrations/new password_resets/new password_resets/edit passwords/edit]
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def mails
|
|
221
|
+
code? ? %w[sign_in_code email_change_code] : %w[email_confirmation password_reset email_change sign_in_locked]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# On paths of their own rather than the model's name, so renaming the model keeps them.
|
|
225
|
+
def routes
|
|
226
|
+
scope = [(%("#{routes_path}") if routes_path), "module: \"#{controllers_path}\"", "as: :#{route_prefix}"].compact
|
|
227
|
+
scope << "defaults: { format: :json }" if api?
|
|
228
|
+
|
|
229
|
+
<<~RUBY
|
|
230
|
+
# #{human_name.pluralize}' accounts (#{accounts_module}::Authentication)
|
|
231
|
+
scope #{scope.join(", ")} do
|
|
232
|
+
#{(api? ? api_routes : web_routes).gsub(/^/, " ")}end
|
|
233
|
+
RUBY
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def web_routes
|
|
237
|
+
sign_in = if code?
|
|
238
|
+
<<~RUBY
|
|
239
|
+
get "sign-in", to: "sign_in_codes#new", as: :sign_in
|
|
240
|
+
post "sign-in", to: "sign_in_codes#create"
|
|
241
|
+
get "sign-in/code", to: "sessions#new", as: :sign_in_code
|
|
242
|
+
post "sign-in/code", to: "sessions#create"
|
|
243
|
+
RUBY
|
|
244
|
+
else
|
|
245
|
+
<<~RUBY
|
|
246
|
+
get "sign-in", to: "sessions#new", as: :sign_in
|
|
247
|
+
post "sign-in", to: "sessions#create"
|
|
248
|
+
get "sign-up", to: "registrations#new", as: :sign_up
|
|
249
|
+
post "sign-up", to: "registrations#create"
|
|
250
|
+
resource :password_reset, only: %i[new create edit update], path: "password-reset"
|
|
251
|
+
get "account/confirm", to: "email_confirmations#show", as: :email_confirmation
|
|
252
|
+
post "account/confirm", to: "email_confirmations#create"
|
|
253
|
+
resource :password, only: %i[edit update], path: "account/password"
|
|
254
|
+
RUBY
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
sign_in + <<~RUBY
|
|
258
|
+
delete "sign-out", to: "sessions#destroy", as: :sign_out
|
|
259
|
+
resource :account, only: %i[show update destroy]
|
|
260
|
+
resource :email_change, only: %i[new create #{code? ? "edit update" : "show"}], path: "account/email"
|
|
261
|
+
resources :active_sessions, only: :destroy, path: "account/sessions" do
|
|
262
|
+
delete :others, action: :destroy_others, on: :collection
|
|
263
|
+
end
|
|
264
|
+
RUBY
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def api_routes
|
|
268
|
+
sign_in = if code?
|
|
269
|
+
<<~RUBY
|
|
270
|
+
post "sign-in", to: "sign_in_codes#create", as: :sign_in
|
|
271
|
+
post "sign-in/code", to: "sessions#create", as: :sign_in_code
|
|
272
|
+
RUBY
|
|
273
|
+
else
|
|
274
|
+
<<~RUBY
|
|
275
|
+
post "sign-in", to: "sessions#create", as: :sign_in
|
|
276
|
+
post "sign-up", to: "registrations#create", as: :sign_up
|
|
277
|
+
resource :password_reset, only: %i[create update], path: "password-reset"
|
|
278
|
+
resource :email_confirmation, only: %i[create update], path: "account/confirmation"
|
|
279
|
+
resource :password, only: :update, path: "account/password"
|
|
280
|
+
RUBY
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
sign_in + <<~RUBY
|
|
284
|
+
delete "session", to: "sessions#destroy", as: :session
|
|
285
|
+
resource :account, only: %i[show update destroy]
|
|
286
|
+
resource :email_change, only: %i[create update], path: "account/email"
|
|
287
|
+
resources :active_sessions, only: %i[index destroy], path: "account/sessions" do
|
|
288
|
+
delete :others, action: :destroy_others, on: :collection
|
|
289
|
+
end
|
|
290
|
+
RUBY
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -23,7 +23,7 @@ module Trek
|
|
|
23
23
|
super
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# `rails g model Shop::Product` writes app/models/shop.rb as a `module Shop`
|
|
26
|
+
# `bin/rails g model Shop::Product` writes app/models/shop.rb as a `module Shop`
|
|
27
27
|
# namespace file; if a `Shop` model already lives there, it gets replaced.
|
|
28
28
|
def warn_about_shadowed_models
|
|
29
29
|
model_namespaces.each do |ns|
|
|
@@ -68,7 +68,7 @@ module Trek
|
|
|
68
68
|
# controller/policy), a bare `Shop` under `module Admin` resolves to it.
|
|
69
69
|
def add_models_to_menu
|
|
70
70
|
inject_into_file dashboard_file_path,
|
|
71
|
-
"\n::#{class_name},",
|
|
71
|
+
"\n ::#{class_name},",
|
|
72
72
|
after: "MODELS_IN_MENU = ["
|
|
73
73
|
rubocop_autocorrect dashboard_file_path
|
|
74
74
|
end
|
|
@@ -108,20 +108,6 @@ module Trek
|
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
-
def translate_other_locale_files
|
|
112
|
-
unless ENV["DEEPL_AUTH_KEY"]
|
|
113
|
-
Rails.logger.debug "DEEPL_AUTH_KEY not found. Skipping translation."
|
|
114
|
-
return
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
if other_locales.empty?
|
|
118
|
-
Rails.logger.debug "No other locales found. Skipping translation."
|
|
119
|
-
return
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
system "i18n-tasks translate-missing --backend=deepl --from=en #{other_locales.map(&:to_s).join(" ")}"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
111
|
def cleanup
|
|
126
112
|
return if I18n.available_locales.include?(:en)
|
|
127
113
|
|
|
@@ -172,11 +158,7 @@ module Trek
|
|
|
172
158
|
# TODO: uncomment to attach files to the model, or remove if not needed
|
|
173
159
|
# include RecordImageUploader::Attachment(:image)
|
|
174
160
|
|
|
175
|
-
#
|
|
176
|
-
# def to_s
|
|
177
|
-
# title || super
|
|
178
|
-
# end
|
|
179
|
-
|
|
161
|
+
#{to_s_method}
|
|
180
162
|
# TODO: choose which attribute to use as image in the admin panel, or remove if not needed
|
|
181
163
|
# def image
|
|
182
164
|
# image_url || super
|
|
@@ -184,6 +166,25 @@ module Trek
|
|
|
184
166
|
RUBY
|
|
185
167
|
end
|
|
186
168
|
|
|
169
|
+
# The record's title in the admin (lists, breadcrumbs…): its first string attribute, or a TODO
|
|
170
|
+
# without one.
|
|
171
|
+
def to_s_method
|
|
172
|
+
title = attributes.find { it.type == :string }
|
|
173
|
+
return <<~RUBY unless title
|
|
174
|
+
# TODO: choose which attribute to use as title in the admin panel
|
|
175
|
+
# def to_s
|
|
176
|
+
# title.presence || super
|
|
177
|
+
# end
|
|
178
|
+
RUBY
|
|
179
|
+
|
|
180
|
+
<<~RUBY
|
|
181
|
+
# The title in the admin panel
|
|
182
|
+
def to_s
|
|
183
|
+
#{title.name}.presence || super
|
|
184
|
+
end
|
|
185
|
+
RUBY
|
|
186
|
+
end
|
|
187
|
+
|
|
187
188
|
def other_locales
|
|
188
189
|
I18n.available_locales.reject { |locale| locale == :en }
|
|
189
190
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require "rails/generators/actions"
|
|
2
|
+
require "generators/trek/helpers"
|
|
3
|
+
|
|
4
|
+
module Trek
|
|
5
|
+
module Generators
|
|
6
|
+
class ScalingoGenerator < Rails::Generators::Base
|
|
7
|
+
BUILDPACK_URL = "https://github.com/etaminstudio/trek-buildpack/archive/refs/tags/v0.1.4.tar.gz".freeze
|
|
8
|
+
|
|
9
|
+
include Trek::Generators::Helpers
|
|
10
|
+
|
|
11
|
+
desc "Create Scalingo files."
|
|
12
|
+
|
|
13
|
+
# The trek-buildpack replaces the apt + ruby buildpack combination. It
|
|
14
|
+
# pins Node from the .node-version that `rails new` already generates.
|
|
15
|
+
def remove_buildpacks
|
|
16
|
+
remove_file ".buildpacks"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# `rails new` adds Kamal, which a Scalingo app doesn't deploy with. Commenting the gem out drops
|
|
20
|
+
# it from the bundle along with its SSH dependencies (net-ssh, sshkit…), whose advisories would
|
|
21
|
+
# otherwise keep failing bundler-audit.
|
|
22
|
+
def comment_out_kamal
|
|
23
|
+
return unless in_gemfile?("kamal")
|
|
24
|
+
|
|
25
|
+
gsub_file "Gemfile",
|
|
26
|
+
/^(?:# Deploy this application anywhere as a Docker container[^\n]*\n)?gem "kamal"/,
|
|
27
|
+
%(# Unused: the app deploys on Scalingo.\n# gem "kamal")
|
|
28
|
+
bundle_install
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create_aptfile
|
|
32
|
+
create_file "Aptfile" do
|
|
33
|
+
<<~TEXT
|
|
34
|
+
libjemalloc2
|
|
35
|
+
libvips-tools --no-install-recommends
|
|
36
|
+
libwebp-dev
|
|
37
|
+
TEXT
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def create_procfile
|
|
42
|
+
create_file "Procfile" do
|
|
43
|
+
<<~TEXT
|
|
44
|
+
web: bundle exec rails server -p $PORT -e $RAILS_ENV -b 0.0.0.0
|
|
45
|
+
# A worker is only needed once jobs outgrow the web container
|
|
46
|
+
# (config.good_job.execution_mode = :async):
|
|
47
|
+
# worker: bundle exec good_job start
|
|
48
|
+
postdeploy: bundle exec rails db:migrate
|
|
49
|
+
TEXT
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def final_instructions
|
|
54
|
+
say ""
|
|
55
|
+
say "Configure the Scalingo app environment:"
|
|
56
|
+
say ""
|
|
57
|
+
say " scalingo --app <app> env-set BUILDPACK_URL=#{BUILDPACK_URL}"
|
|
58
|
+
say " scalingo --app <app> env-set 'DATABASE_URL=$SCALINGO_POSTGRESQL_URL'"
|
|
59
|
+
say ""
|
|
60
|
+
say "and make sure config/database.yml reads DATABASE_URL in production."
|
|
61
|
+
say ""
|
|
62
|
+
say "See https://trek.etamin.studio/deploy for details."
|
|
63
|
+
say ""
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -20,7 +20,7 @@ stages:
|
|
|
20
20
|
|
|
21
21
|
# Defaults
|
|
22
22
|
default:
|
|
23
|
-
image: registry.git.etamin.studio/devops/ci-ruby/node
|
|
23
|
+
image: registry.git.etamin.studio/devops/ci-ruby/node-<%= node_major %>:4.0.9
|
|
24
24
|
|
|
25
25
|
services:
|
|
26
26
|
- postgres:16
|
|
@@ -158,6 +158,15 @@ bundler-audit:
|
|
|
158
158
|
script:
|
|
159
159
|
- bundle exec bundle-audit check --update
|
|
160
160
|
|
|
161
|
+
# Advisories and deprecations, whatever their severity as bundler-audit, on the npm packages the app
|
|
162
|
+
# bundles (`dependencies`), not on its tooling (`devDependencies`). Reads yarn.lock: nothing to
|
|
163
|
+
# install. To skip one that doesn't apply, add its ID to `npmAuditIgnoreAdvisories` in .yarnrc.yml:
|
|
164
|
+
# the number `yarn npm audit` shows, or `<package> (deprecation)`.
|
|
165
|
+
npm-audit:
|
|
166
|
+
<<: *security_definition
|
|
167
|
+
script:
|
|
168
|
+
- yarn npm audit --recursive --environment production
|
|
169
|
+
|
|
161
170
|
# Software Bill of Materials (CycloneDX): the gems and npm packages in the lockfiles, with their licenses.
|
|
162
171
|
# Uncomment the job when a client asks for one.
|
|
163
172
|
# GitLab keeps each branch's latest one by default, past `expire_in`: hand over the one of the production branch.
|
|
@@ -4,7 +4,7 @@ Guidance for AI coding agents working in this repository.
|
|
|
4
4
|
|
|
5
5
|
## About this project
|
|
6
6
|
|
|
7
|
-
This is a Ruby on Rails application whose back-office/admin is built with **Trek**, a Rails CMS engine. Trek was installed via `rails g trek:install` and provides the admin UI, authentication, authorization, attachments, and base content models. Project-specific work lives in `app/` — admin controllers under `app/controllers/admin/`, plus your own models, policies, and components. Prefer Trek's generators (`rails g trek:scaffold`, `rails g trek:admin:user`, …) over hand-writing admin plumbing.
|
|
7
|
+
This is a Ruby on Rails application whose back-office/admin is built with **Trek**, a Rails CMS engine. Trek was installed via `bin/rails g trek:install` and provides the admin UI, authentication, authorization, attachments, and base content models. Project-specific work lives in `app/` — admin controllers under `app/controllers/admin/`, plus your own models, policies, and components. Prefer Trek's generators (`bin/rails g trek:scaffold`, `bin/rails g trek:admin:user`, …) over hand-writing admin plumbing.
|
|
8
8
|
|
|
9
9
|
## Commands
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ This is a Ruby on Rails application whose back-office/admin is built with **Trek
|
|
|
15
15
|
make test # run the RSpec suite (alias: make spec)
|
|
16
16
|
make lint # rubocop + slim-lint + eslint + stylelint + prettier
|
|
17
17
|
make fix # auto-correct lint/format issues
|
|
18
|
-
make scan # brakeman + bundle-audit
|
|
18
|
+
make scan # brakeman + bundle-audit + yarn npm audit
|
|
19
19
|
|
|
20
20
|
## Conventions
|
|
21
21
|
|
|
@@ -100,14 +100,6 @@ search:
|
|
|
100
100
|
## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example
|
|
101
101
|
|
|
102
102
|
## Translation Services
|
|
103
|
-
translation:
|
|
104
|
-
deepl_api_key:
|
|
105
|
-
deepl_host: "https://api-free.deepl.com"
|
|
106
|
-
deepl_glossary_ids:
|
|
107
|
-
- f28106eb-0e06-489e-82c6-8215d6f95089
|
|
108
|
-
- 2c6415be-1852-4f54-9e1b-d800463496b4
|
|
109
|
-
deepl_options:
|
|
110
|
-
formality: prefer_less
|
|
111
103
|
# translation:
|
|
112
104
|
# # Google Translate
|
|
113
105
|
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Admin
|
|
2
|
+
# After a suspected compromise: every user, this admin included, must choose a new password at
|
|
3
|
+
# their next request (User.require_password_renewal!).
|
|
4
|
+
class PasswordRenewalsController < Admin::BaseController
|
|
5
|
+
def create
|
|
6
|
+
authorize! User, to: :require_password_renewal?
|
|
7
|
+
User.require_password_renewal!
|
|
8
|
+
redirect_to admin_users_path, notice: t(".success")
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Admin
|
|
2
|
+
# The app's security settings (Trek::SecurityCheck), checked on this very request too: whether it came
|
|
3
|
+
# over HTTPS, and the address Rails sees behind a CDN. For admins only (Admin::SecurityCheckPolicy).
|
|
4
|
+
class SecurityChecksController < Admin::BaseController
|
|
5
|
+
def show
|
|
6
|
+
authorize! :security_check, to: :show?, with: Admin::SecurityCheckPolicy
|
|
7
|
+
@check = Trek::SecurityCheck.new(request:)
|
|
8
|
+
@checked_at = Time.current
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -24,14 +24,6 @@ module Admin
|
|
|
24
24
|
@object.password = SecureRandom.alphanumeric(24) if @object.password.blank?
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
# After a suspected compromise: every user, this admin included, must choose a new password at
|
|
28
|
-
# their next request.
|
|
29
|
-
def require_password_renewal
|
|
30
|
-
authorize! User, to: :require_password_renewal?
|
|
31
|
-
User.require_password_renewal!
|
|
32
|
-
redirect_to admin_users_path, notice: t(".success")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
27
|
def theme
|
|
36
28
|
value = params[:theme].to_s
|
|
37
29
|
Current.user.update!(theme: value) if User.themes.key?(value)
|
|
@@ -83,14 +83,23 @@ module Trek::Authentication
|
|
|
83
83
|
).deliver_later
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
# The users who signed in from this browser, in a
|
|
86
|
+
# The last 20 users who signed in from this browser, in a cookie encrypted so that the browser's
|
|
87
|
+
# users can't read who else signed in from it, kept 13 months (the CNIL's yardstick for cookies)
|
|
88
|
+
# after the last of those sign-ins
|
|
87
89
|
def signed_in_from_this_browser?(user)
|
|
88
|
-
|
|
90
|
+
known_user_ids.include?(user.id)
|
|
89
91
|
end
|
|
90
92
|
|
|
91
93
|
def remember_sign_in_from_this_browser(user)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
cookies.encrypted[:trek_known_users] = {
|
|
95
|
+
value: (known_user_ids | [user.id]).last(20), expires: 13.months, httponly: true, same_site: :lax
|
|
96
|
+
}
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Also reads the signed cookie Trek wrote before encrypting it, so the upgrade doesn't email every
|
|
100
|
+
# user on their next sign-in. The fallback can go 13 months after the upgrade.
|
|
101
|
+
def known_user_ids
|
|
102
|
+
Array(cookies.encrypted[:trek_known_users] || cookies.signed[:trek_known_users])
|
|
94
103
|
end
|
|
95
104
|
|
|
96
105
|
def terminate_session
|
|
@@ -22,8 +22,9 @@ Rails.application.configure do
|
|
|
22
22
|
# Framed by its own pages only (Lookbook's previews), against clickjacking
|
|
23
23
|
policy.frame_ancestors :self
|
|
24
24
|
policy.object_src :none
|
|
25
|
-
# No inline script: the app's own files, and the scripts given the request's nonce
|
|
26
|
-
|
|
25
|
+
# No inline script: the app's own files, and the scripts given the request's nonce. A blocked
|
|
26
|
+
# inline script's first 40 characters go with the report (`'report-sample'`), to tell what it was
|
|
27
|
+
policy.script_src :self, :report_sample
|
|
27
28
|
# Inline `style` attributes stay allowed: Trek's components and Backpack's set some (colors,
|
|
28
29
|
# custom properties)
|
|
29
30
|
policy.style_src :self, :unsafe_inline
|