trek 2.4.0 → 2.6.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 +12 -8
- data/CHANGELOG.md +62 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +205 -171
- data/Makefile +28 -1
- data/README.md +2 -2
- 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 +5 -0
- 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.rb +37 -14
- data/app/components/trek/list/item_component.rb +1 -1
- data/app/components/trek/list/tree/item_component.rb +2 -2
- data/app/components/trek/search_component/search_component.html.slim +2 -1
- data/app/components/trek/search_component.rb +9 -1
- data/app/content/trek/content/bullet_list.rb +10 -0
- data/app/content/trek/content/cleaner.rb +53 -0
- data/app/content/trek/content/document.rb +33 -0
- data/app/content/trek/content/image_block.rb +52 -0
- data/app/content/trek/content/link_resolver.rb +33 -0
- data/app/content/trek/content/list_item.rb +19 -0
- data/app/content/trek/content/ordered_list.rb +10 -0
- data/app/content/trek/content/paragraph.rb +10 -0
- data/app/content/trek/content/prompts_block.rb +21 -0
- data/app/content/trek/content.rb +38 -0
- data/app/controllers/concerns/trek/reorderable.rb +32 -3
- data/app/controllers/trek/csp_reports_controller.rb +17 -7
- data/app/controllers/trek/panels/base_controller.rb +3 -0
- data/app/controllers/trek/panels/links_controller.rb +1 -1
- data/app/controllers/trek/panels/prompts_controller.rb +2 -2
- data/app/controllers/trek/resource_controller.rb +5 -5
- data/app/helpers/trek/thumbnail_helper.rb +11 -0
- data/app/jobs/trek/purge_expired_sessions_job.rb +4 -3
- data/app/models/concerns/trek/contentable.rb +19 -10
- data/app/models/concerns/trek/pageable.rb +10 -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/views/trek/panels/images/_form.html.slim +1 -1
- data/app/views/trek/panels/images/create.turbo_stream.slim +1 -1
- data/app/views/trek/panels/links/_form.html.slim +3 -5
- data/app/views/trek/panels/prompts/_form.html.slim +1 -1
- data/app/views/trek/panels/prompts/create.turbo_stream.slim +0 -1
- data/config/locales/trek.en.yml +40 -2
- data/config/locales/trek.fr.yml +40 -2
- data/docs/.vitepress/config.mjs +4 -1
- data/docs/background-jobs.md +69 -0
- data/docs/content-editor.md +219 -0
- data/docs/customize.md +2 -0
- data/docs/deploy.md +2 -2
- data/docs/getting-started.md +4 -4
- data/docs/index.md +1 -1
- data/docs/reference/components.md +2 -2
- data/docs/reference/concerns/contentable.md +11 -4
- data/docs/reference/concerns/formattable.md +1 -1
- data/docs/reference/controllers.md +1 -1
- data/docs/reference/environment-variables.md +1 -0
- data/docs/reference/formatters.md +4 -9
- data/docs/reference/forms.md +1 -1
- data/docs/reference/generators/audit-log.md +2 -2
- data/docs/reference/generators/install.md +3 -2
- data/docs/reference/generators/public-accounts.md +141 -0
- data/docs/reference/generators/security-headers.md +1 -1
- data/docs/reference/index.md +2 -1
- data/docs/reference/models/fragment.md +1 -0
- data/docs/reference/models/user.md +3 -1
- data/docs/what-is-trek.md +5 -5
- data/lib/generators/trek/audit_log_generator.rb +54 -0
- data/lib/generators/trek/helpers.rb +13 -5
- data/lib/generators/trek/install/admin/users_generator.rb +6 -1
- data/lib/generators/trek/install/admin_generator.rb +8 -0
- data/lib/generators/trek/install/appsignal_generator.rb +1 -1
- data/lib/generators/trek/install/audit_log_generator.rb +9 -45
- data/lib/generators/trek/install/authentication_generator.rb +1 -1
- data/lib/generators/trek/install/authorization_generator.rb +1 -1
- 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/postmark_generator.rb +2 -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/specs_generator.rb +11 -0
- data/lib/generators/trek/install/user_generator.rb +1 -1
- data/lib/generators/trek/install_generator.rb +15 -0
- data/lib/generators/trek/public_accounts_generator.rb +267 -0
- data/lib/generators/trek/scaffold_generator.rb +13 -5
- data/lib/generators/trek/scalingo_generator.rb +55 -0
- data/lib/generators/trek/templates/.gitlab-ci.yml +1 -1
- data/lib/generators/trek/templates/Makefile +1 -1
- data/lib/generators/trek/templates/controllers/admin/fragments_controller.rb +7 -0
- data/lib/generators/trek/templates/controllers/admin/panels/images_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/panels/links_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/panels/prompts_controller.rb +8 -0
- data/lib/generators/trek/templates/controllers/admin/password_renewals_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/initializers/content_security_policy.rb +3 -2
- data/lib/generators/trek/templates/initializers/good_job.rb.tt +38 -0
- data/lib/generators/trek/templates/jobs/mail_delivery_job.rb +6 -0
- data/lib/generators/trek/templates/layouts/admin.html.slim +5 -0
- data/lib/generators/trek/templates/mailers/admin_mailer.rb +4 -2
- data/lib/generators/trek/templates/models/fragment.rb +14 -0
- data/lib/generators/trek/templates/package.json.tt +1 -1
- 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 +45 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sign_in_codes_controller.rb.tt +15 -0
- data/lib/generators/trek/templates/public_accounts/jobs/sign_in_code_job.rb.tt +13 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.en.yml.tt +205 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.fr.yml.tt +205 -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 +73 -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 +158 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account/sign_in_code_spec.rb.tt +56 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account_spec.rb.tt +109 -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 +215 -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 +78 -0
- data/lib/generators/trek/templates/public_accounts/web/controllers/sign_in_codes_controller.rb.tt +27 -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 +26 -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 +25 -0
- data/lib/generators/trek/templates/public_accounts/web/views/registrations/new.html.slim.tt +28 -0
- data/lib/generators/trek/templates/public_accounts/web/views/sessions/new.html.slim.tt +38 -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 +12 -1
- data/lib/generators/trek/templates/spec/requests/admin/active_sessions_spec.rb +1 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +27 -3
- 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 +9 -1
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +70 -0
- data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +2 -2
- 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 +5 -3
- data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +2 -2
- data/lib/generators/trek/templates/views/admin/fragments/index.html.slim +14 -3
- 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/trek/csp_reports.rb +22 -4
- data/lib/trek/engine.rb +8 -3
- data/lib/trek/saved_attachments_reload.rb +2 -1
- data/lib/trek/typography_formatter.rb +35 -4
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +1 -1
- data/package.json +12 -8
- data/renovate.json +1 -0
- data/trek.gemspec +3 -3
- data/vitest.config.mjs +24 -0
- data/yarn.lock +1706 -1028
- metadata +116 -14
- data/app/formatters/prosemirror_to_html/global_id_to_links_formatter.rb +0 -19
- data/app/formatters/prosemirror_to_html/nodes/image_block.rb +0 -44
- data/app/formatters/prosemirror_to_html/nodes/prompts_block.rb +0 -28
- data/app/formatters/prosemirror_to_html/remove_empty_paragraphs_formatter.rb +0 -11
- data/app/models/prosemirror.rb +0 -23
|
@@ -2,22 +2,31 @@ module Trek
|
|
|
2
2
|
module Contentable
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
4
|
|
|
5
|
+
included do
|
|
6
|
+
before_validation :clean_content
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
def parsed_content
|
|
6
10
|
return if content.blank?
|
|
7
11
|
|
|
8
12
|
content.is_a?(Hash) ? content : JSON.parse(content)
|
|
9
13
|
end
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
# The content as a Prosemirror::Document, built with Trek::Content.schema. Problems found while parsing
|
|
16
|
+
# or rendering it are reported with the record in their context (see Trek::Content::Document).
|
|
17
|
+
def content_document
|
|
12
18
|
return if content.blank?
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
Trek::Content::Document.parse(self, parsed_content)
|
|
15
21
|
end
|
|
16
22
|
|
|
17
|
-
def
|
|
18
|
-
|
|
23
|
+
def formatted_content
|
|
24
|
+
content_document&.to_html
|
|
25
|
+
end
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
# The plain text, with its blocks separated by a blank line and its hard breaks by a newline
|
|
28
|
+
def content_text
|
|
29
|
+
content_document&.to_text
|
|
21
30
|
end
|
|
22
31
|
|
|
23
32
|
def prosemirror_content?
|
|
@@ -30,11 +39,11 @@ module Trek
|
|
|
30
39
|
|
|
31
40
|
private
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
# Before saving, removes what rendering skips: empty paragraphs, empty list items and lists left empty
|
|
43
|
+
# (Trek::Content::Cleaner). The content editor submits the content as a JSON string: it's stored as a
|
|
44
|
+
# document. Translated content is cleaned in the current locale.
|
|
45
|
+
def clean_content
|
|
46
|
+
self.content = Trek::Content.clean(parsed_content) if prosemirror_content?
|
|
38
47
|
end
|
|
39
48
|
end
|
|
40
49
|
end
|
|
@@ -21,9 +21,10 @@ module Trek
|
|
|
21
21
|
super || build_page(parent: default_parent_page)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# The admin links to records by id, the site by slug.
|
|
24
25
|
def to_param
|
|
25
26
|
# TODO: find a better way?
|
|
26
|
-
if
|
|
27
|
+
if called_from_admin?
|
|
27
28
|
id || super
|
|
28
29
|
else
|
|
29
30
|
page&.slug || super
|
|
@@ -96,5 +97,13 @@ module Trek
|
|
|
96
97
|
def apply_default_parent_page
|
|
97
98
|
page.parent = default_parent_page
|
|
98
99
|
end
|
|
100
|
+
|
|
101
|
+
# Whether an admin file (controller, view, layout, mailer…) is in the call stack. Trek::AdminIpAllowlist
|
|
102
|
+
# doesn't count: a middleware, it sits in the stack of every request, the site's included.
|
|
103
|
+
def called_from_admin?
|
|
104
|
+
caller_locations.any? do |location|
|
|
105
|
+
location.path.include?("admin") && !location.path.end_with?("/lib/trek/admin_ip_allowlist.rb")
|
|
106
|
+
end
|
|
107
|
+
end
|
|
99
108
|
end
|
|
100
109
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trek
|
|
4
|
+
module Users
|
|
5
|
+
# A one-time code emailed to sign in, or to confirm a new email address: 6 digits, valid for
|
|
6
|
+
# `validity` (10 minutes), for `max_attempts` tries (5), then single use. Stored as an HMAC of the
|
|
7
|
+
# code keyed on the app's secret_key_base, never in clear. Kept by email rather than by account,
|
|
8
|
+
# so an email without an account gets one too: asking for a code answers the same whether or not
|
|
9
|
+
# the email has an account (ANSSI guide on passwords, R14), and verifying it creates the account.
|
|
10
|
+
#
|
|
11
|
+
# A new code for an email replaces its earlier ones for the same purpose. Needs the `email`,
|
|
12
|
+
# `purpose`, `code_digest`, `attempts` and `expires_at` columns, and the account's foreign key for
|
|
13
|
+
# an email change.
|
|
14
|
+
module SignInCode
|
|
15
|
+
extend ActiveSupport::Concern
|
|
16
|
+
|
|
17
|
+
PURPOSES = %w[sign_in email_change].freeze
|
|
18
|
+
LENGTH = 6
|
|
19
|
+
|
|
20
|
+
included do
|
|
21
|
+
class_attribute :validity, default: 10.minutes
|
|
22
|
+
class_attribute :max_attempts, default: 5
|
|
23
|
+
|
|
24
|
+
# The code in clear, on the record `issue` returns only: for the email, never stored.
|
|
25
|
+
attribute :code, :string
|
|
26
|
+
|
|
27
|
+
normalizes :email, with: ->(email) { email.strip.downcase }
|
|
28
|
+
|
|
29
|
+
validates :email, presence: true
|
|
30
|
+
validates :purpose, inclusion: { in: PURPOSES }
|
|
31
|
+
|
|
32
|
+
scope :expired, -> { where(expires_at: ...Time.current) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class_methods do
|
|
36
|
+
# A new code for `email`, replacing the earlier ones for `purpose`. Its `code` is the one to send.
|
|
37
|
+
def issue(email, purpose: "sign_in", **attributes)
|
|
38
|
+
code = SecureRandom.random_number(10**LENGTH).to_s.rjust(LENGTH, "0")
|
|
39
|
+
|
|
40
|
+
transaction do
|
|
41
|
+
where(email: normalize_value_for(:email, email), purpose:).delete_all
|
|
42
|
+
# Codes nobody used: they can't sign anyone in anymore
|
|
43
|
+
expired.delete_all
|
|
44
|
+
create!(email:, purpose:, code_digest: code_digest(code), expires_at: validity.from_now, **attributes)
|
|
45
|
+
end.tap { it.code = code }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# The code of `email` for `purpose` when `code` matches it, used up; nil otherwise. Every try
|
|
49
|
+
# counts, the right one included, and a code past max_attempts can't sign in anymore.
|
|
50
|
+
def redeem(email, code, purpose: "sign_in", **attributes)
|
|
51
|
+
record = where(email: normalize_value_for(:email, email), purpose:, **attributes)
|
|
52
|
+
.where(expires_at: Time.current..).order(created_at: :desc).first
|
|
53
|
+
return unless record
|
|
54
|
+
|
|
55
|
+
# Counted in the database first, so parallel tries can't go past max_attempts
|
|
56
|
+
counted = where(id: record.id).where(attempts: ...max_attempts).update_all("attempts = attempts + 1") # rubocop:disable Rails/SkipsModelValidations
|
|
57
|
+
return if counted.zero?
|
|
58
|
+
return unless ActiveSupport::SecurityUtils.secure_compare(record.code_digest, code_digest(code.to_s.gsub(/\D/, "")))
|
|
59
|
+
|
|
60
|
+
# Single use: only one of parallel right tries gets it
|
|
61
|
+
record if where(id: record.id).delete_all == 1
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def code_digest(code)
|
|
65
|
+
OpenSSL::HMAC.hexdigest("SHA256", Rails.application.key_generator.generate_key("trek/sign_in_codes"), code)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -10,7 +10,8 @@ module Trek
|
|
|
10
10
|
#
|
|
11
11
|
# While locked, signing in fails even with the right password, and the attempts don't count. A
|
|
12
12
|
# successful sign-in or a new password (e.g. through a reset) unlocks it. The user is emailed
|
|
13
|
-
# when it first locks (`sign_in_lockout_email`)
|
|
13
|
+
# when it first locks (`sign_in_lockout_email`), by `sign_in_lockout_mailer`'s `sign_in_locked`
|
|
14
|
+
# (AdminMailer).
|
|
14
15
|
#
|
|
15
16
|
# Needs the `failed_sign_in_count` and `sign_in_locked_until` columns.
|
|
16
17
|
module SignInLockout
|
|
@@ -21,6 +22,7 @@ module Trek
|
|
|
21
22
|
class_attribute :sign_in_lockout_duration, default: 1.minute
|
|
22
23
|
class_attribute :sign_in_lockout_max, default: 1.hour
|
|
23
24
|
class_attribute :sign_in_lockout_email, default: true
|
|
25
|
+
class_attribute :sign_in_lockout_mailer, default: "AdminMailer"
|
|
24
26
|
|
|
25
27
|
before_save :unlock_sign_in, if: :password_digest_changed?
|
|
26
28
|
end
|
|
@@ -41,7 +43,7 @@ module Trek
|
|
|
41
43
|
update_column(:sign_in_locked_until, sign_in_lockout_delay.from_now) # rubocop:disable Rails/SkipsModelValidations
|
|
42
44
|
# Once per series of failures, not on each failure that extends it
|
|
43
45
|
first_lockout = failed_sign_in_count == sign_in_lockout_after
|
|
44
|
-
|
|
46
|
+
sign_in_lockout_mailer.constantize.sign_in_locked(self).deliver_later if sign_in_lockout_email && first_lockout
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
def record_successful_sign_in!
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
h1.c-trek--layout-panel-title = t(".title")
|
|
1
|
+
h1.c-trek--layout-panel-title = t("admin.panels.links.form.title")
|
|
2
2
|
|
|
3
3
|
= form_with model: @object, scope: :link, url: %i[admin panels links] do |f|
|
|
4
4
|
= render Trek::Form::ErrorsComponent.new(object: @object)
|
|
@@ -20,10 +20,8 @@ h1.c-trek--layout-panel-title = t(".title")
|
|
|
20
20
|
= f.select :target,
|
|
21
21
|
options_for_select(@object.class::TARGETS, @object.target)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/ = f.group :title
|
|
26
|
-
/ = f.text_field :title
|
|
23
|
+
= f.group :title
|
|
24
|
+
= f.text_field :title
|
|
27
25
|
|
|
28
26
|
= render Trek::Form::ActionsComponent.new do |c|
|
|
29
27
|
ruby:
|
data/config/locales/trek.en.yml
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
en:
|
|
3
|
+
activemodel:
|
|
4
|
+
attributes:
|
|
5
|
+
trek/content_editor/image:
|
|
6
|
+
alt: Alternative text
|
|
7
|
+
credit: Credit
|
|
8
|
+
file: Image
|
|
9
|
+
size: Display width
|
|
10
|
+
text: Image caption
|
|
11
|
+
trek/content_editor/link:
|
|
12
|
+
href: Link to
|
|
13
|
+
target: Open this link in…
|
|
14
|
+
text: Link text
|
|
15
|
+
title: Title
|
|
16
|
+
trek/content_editor/prompt:
|
|
17
|
+
href: Link to
|
|
18
|
+
target: Open this link in…
|
|
19
|
+
text: Button text
|
|
20
|
+
title: Title
|
|
21
|
+
options:
|
|
22
|
+
trek/content_editor/image:
|
|
23
|
+
size:
|
|
24
|
+
default: As wide as the text
|
|
25
|
+
larger: Extends past the sides
|
|
3
26
|
activerecord:
|
|
4
27
|
attributes:
|
|
5
28
|
audit_log:
|
|
@@ -71,6 +94,7 @@ en:
|
|
|
71
94
|
browse: Browse…
|
|
72
95
|
cancel: Cancel
|
|
73
96
|
delete: Delete
|
|
97
|
+
download_original: Download original
|
|
74
98
|
edit: Edit
|
|
75
99
|
logout: Log out
|
|
76
100
|
manage: Manage
|
|
@@ -155,6 +179,7 @@ en:
|
|
|
155
179
|
intro: Fragment
|
|
156
180
|
update:
|
|
157
181
|
success: Fragment updated
|
|
182
|
+
jobs: Background jobs
|
|
158
183
|
metadata: Metadata
|
|
159
184
|
navigation: Navigation
|
|
160
185
|
pages:
|
|
@@ -205,6 +230,9 @@ en:
|
|
|
205
230
|
success: Passkey added
|
|
206
231
|
destroy:
|
|
207
232
|
success: Passkey deleted
|
|
233
|
+
password_renewals:
|
|
234
|
+
create:
|
|
235
|
+
success: Every user will have to choose a new password
|
|
208
236
|
passwords_mailer:
|
|
209
237
|
reset:
|
|
210
238
|
subject: Reset your password
|
|
@@ -266,8 +294,6 @@ en:
|
|
|
266
294
|
last_used: Last used %{time} ago
|
|
267
295
|
never_used: Never used
|
|
268
296
|
title: Sign in without a password
|
|
269
|
-
require_password_renewal:
|
|
270
|
-
success: Every user will have to choose a new password
|
|
271
297
|
search:
|
|
272
298
|
alert: No user found with email
|
|
273
299
|
sessions:
|
|
@@ -301,6 +327,18 @@ en:
|
|
|
301
327
|
errors:
|
|
302
328
|
messages:
|
|
303
329
|
disposable: is a disposable email address, use a permanent one
|
|
330
|
+
helpers:
|
|
331
|
+
hint:
|
|
332
|
+
trek/content_editor/image:
|
|
333
|
+
alt: For accessibility and SEO, describe what the image shows, without repeating the caption
|
|
334
|
+
credit: The author's name
|
|
335
|
+
text: Shown under the image
|
|
336
|
+
trek/content_editor/link:
|
|
337
|
+
href: Choose a page or enter a URL
|
|
338
|
+
title: Shown on hover, useful for accessibility and SEO
|
|
339
|
+
trek/content_editor/prompt:
|
|
340
|
+
href: Choose a page or enter a URL
|
|
341
|
+
title: Shown on hover, useful for accessibility and SEO
|
|
304
342
|
notices:
|
|
305
343
|
authentication_needed: Please log in
|
|
306
344
|
password_renewal_needed: "Your password must be renewed: choose a new one"
|
data/config/locales/trek.fr.yml
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
---
|
|
2
2
|
fr:
|
|
3
|
+
activemodel:
|
|
4
|
+
attributes:
|
|
5
|
+
trek/content_editor/image:
|
|
6
|
+
alt: Texte alternatif
|
|
7
|
+
credit: Crédit
|
|
8
|
+
file: Image
|
|
9
|
+
size: Largeur d'affichage
|
|
10
|
+
text: Légende de l'image
|
|
11
|
+
trek/content_editor/link:
|
|
12
|
+
href: Lien vers
|
|
13
|
+
target: Ouvrir ce lien dans…
|
|
14
|
+
text: Texte du lien
|
|
15
|
+
title: Titre
|
|
16
|
+
trek/content_editor/prompt:
|
|
17
|
+
href: Lien vers
|
|
18
|
+
target: Ouvrir ce lien dans…
|
|
19
|
+
text: Texte du bouton
|
|
20
|
+
title: Titre
|
|
21
|
+
options:
|
|
22
|
+
trek/content_editor/image:
|
|
23
|
+
size:
|
|
24
|
+
default: Comme la colonne de texte
|
|
25
|
+
larger: Dépasse sur les côtés
|
|
3
26
|
activerecord:
|
|
4
27
|
attributes:
|
|
5
28
|
audit_log:
|
|
@@ -71,6 +94,7 @@ fr:
|
|
|
71
94
|
browse: Parcourir…
|
|
72
95
|
cancel: Annuler
|
|
73
96
|
delete: Supprimer
|
|
97
|
+
download_original: Télécharger l'original
|
|
74
98
|
edit: Éditer
|
|
75
99
|
logout: Se déconnecter
|
|
76
100
|
manage: Gérer
|
|
@@ -164,6 +188,7 @@ fr:
|
|
|
164
188
|
intro: Fragment
|
|
165
189
|
update:
|
|
166
190
|
success: Fragment mis à jour
|
|
191
|
+
jobs: Tâches de fond
|
|
167
192
|
metadata: Métadonnées
|
|
168
193
|
navigation: Navigation
|
|
169
194
|
pages:
|
|
@@ -214,6 +239,9 @@ fr:
|
|
|
214
239
|
success: Clé d'accès ajoutée
|
|
215
240
|
destroy:
|
|
216
241
|
success: Clé d'accès supprimée
|
|
242
|
+
password_renewals:
|
|
243
|
+
create:
|
|
244
|
+
success: Chaque utilisateur devra choisir un nouveau mot de passe
|
|
217
245
|
passwords_mailer:
|
|
218
246
|
reset:
|
|
219
247
|
subject: Nouveau mot de passe
|
|
@@ -275,8 +303,6 @@ fr:
|
|
|
275
303
|
last_used: Utilisée il y a %{time}
|
|
276
304
|
never_used: Jamais utilisée
|
|
277
305
|
title: Se connecter sans mot de passe
|
|
278
|
-
require_password_renewal:
|
|
279
|
-
success: Chaque utilisateur devra choisir un nouveau mot de passe
|
|
280
306
|
search:
|
|
281
307
|
alert: Utilisateur non trouvé avec cette adresse e-mail
|
|
282
308
|
sessions:
|
|
@@ -310,6 +336,18 @@ fr:
|
|
|
310
336
|
errors:
|
|
311
337
|
messages:
|
|
312
338
|
disposable: est une adresse e-mail jetable, utilisez-en une permanente
|
|
339
|
+
helpers:
|
|
340
|
+
hint:
|
|
341
|
+
trek/content_editor/image:
|
|
342
|
+
alt: Pour l'accessibilité et le référencement, décrire le contenu de l'image, sans répéter le texte de la légende
|
|
343
|
+
credit: Indiquer le nom de l'auteur
|
|
344
|
+
text: Sera affichée sous l'image
|
|
345
|
+
trek/content_editor/link:
|
|
346
|
+
href: Choisir une page ou entrer une URL
|
|
347
|
+
title: Affiché au survol, utile pour l'accessibilité et le référencement
|
|
348
|
+
trek/content_editor/prompt:
|
|
349
|
+
href: Choisir une page ou entrer une URL
|
|
350
|
+
title: Affiché au survol, utile pour l'accessibilité et le référencement
|
|
313
351
|
notices:
|
|
314
352
|
authentication_needed: Veuillez vous connecter
|
|
315
353
|
password_renewal_needed: "Votre mot de passe doit être renouvelé : choisissez-en un nouveau"
|
data/docs/.vitepress/config.mjs
CHANGED
|
@@ -53,9 +53,11 @@ export default defineConfig({
|
|
|
53
53
|
text: 'Guides',
|
|
54
54
|
items: [
|
|
55
55
|
{ text: 'How to customize Trek', link: '/customize' },
|
|
56
|
+
{ text: 'Content editor', link: '/content-editor' },
|
|
56
57
|
{ text: 'Deploying to Scalingo', link: '/deploy' },
|
|
57
58
|
{ text: 'IP addresses behind a proxy', link: '/proxies' },
|
|
58
|
-
{ text: 'Security and compliance', link: '/security' }
|
|
59
|
+
{ text: 'Security and compliance', link: '/security' },
|
|
60
|
+
{ text: 'Background jobs', link: '/background-jobs' }
|
|
59
61
|
]
|
|
60
62
|
},
|
|
61
63
|
{
|
|
@@ -77,6 +79,7 @@ export default defineConfig({
|
|
|
77
79
|
{ text: 'Scaffold', link: '/reference/generators/scaffold' },
|
|
78
80
|
{ text: 'Taxonomies', link: '/reference/generators/taxonomies' },
|
|
79
81
|
{ text: 'Audit log', link: '/reference/generators/audit-log' },
|
|
82
|
+
{ text: 'Public accounts', link: '/reference/generators/public-accounts' },
|
|
80
83
|
{ text: 'Security headers', link: '/reference/generators/security-headers' }
|
|
81
84
|
]
|
|
82
85
|
},
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Background jobs
|
|
2
|
+
|
|
3
|
+
Trek apps run Active Job on [GoodJob](https://github.com/bensheldon/good_job), installed by `rails g trek:install` (or on its own with `rails g trek:install:good_job`). GoodJob stores its queue in the application's own PostgreSQL database, so there is no second database to provision — which is why the installer removes the Solid Queue setup `rails new` generates.
|
|
4
|
+
|
|
5
|
+
## What the installer sets up
|
|
6
|
+
|
|
7
|
+
| Where | What |
|
|
8
|
+
| ----------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| `Gemfile` | `good_job` replaces `solid_queue` (Solid Cache stays: its table lives in the primary database) |
|
|
10
|
+
| `config/application.rb` | `config.active_job.queue_adapter = :good_job` and `config.action_mailer.delivery_job = "MailDeliveryJob"` |
|
|
11
|
+
| `config/environments/production.rb` | `config.good_job.execution_mode = :async` and `config.good_job.shutdown_timeout = 25` |
|
|
12
|
+
| `config/environments/test.rb` | `config.active_job.queue_adapter = :test`, so specs can check what is enqueued (`have_enqueued_job`) |
|
|
13
|
+
| `config/initializers/good_job.rb` | queues, cron, error reporting, and the dashboard guard |
|
|
14
|
+
| `config/database.yml` | a connection pool sized for the web threads **and** the job threads |
|
|
15
|
+
| `app/jobs/mail_delivery_job.rb` | the delivery job every `deliver_later` email goes through |
|
|
16
|
+
| `config/routes.rb` | `mount GoodJob::Engine => "good_job"` inside `namespace :admin` |
|
|
17
|
+
|
|
18
|
+
## Async in Puma, or a dedicated worker
|
|
19
|
+
|
|
20
|
+
In production the jobs run in the web container's own threads (`execution_mode = :async`): nothing else to deploy, nothing else to pay for. `shutdown_timeout = 25` lets a restart drain the jobs in flight instead of dropping them.
|
|
21
|
+
|
|
22
|
+
`GOOD_JOB_MAX_THREADS` sizes the job pool. It also feeds the database pool, since `config/database.yml` reserves connections for the web threads and the job threads separately:
|
|
23
|
+
|
|
24
|
+
```yml
|
|
25
|
+
max_connections: <%= web = ENV.fetch("RAILS_MAX_THREADS", 5).to_i; 1 + web + ENV.fetch("GOOD_JOB_MAX_THREADS", web).to_i %>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
When the jobs outgrow the web container — long-running work, or a queue that must not compete with requests — move them to their own process: set `config.good_job.execution_mode = :external` and uncomment the worker line in the `Procfile` (`worker: bundle exec good_job start`). Note that in `:external` mode only the worker runs a scheduler, so cron then runs there and nowhere else.
|
|
29
|
+
|
|
30
|
+
## Queues
|
|
31
|
+
|
|
32
|
+
One scheduler serves every queue by default (`config.good_job.queues = "*"`). Give a queue its own lane when it must not wait behind the others:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
config.good_job.queues = "mailers:2;*:3"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The thread counts have to stay within `GOOD_JOB_MAX_THREADS` — they are database connections too.
|
|
39
|
+
|
|
40
|
+
## Scheduled jobs (cron)
|
|
41
|
+
|
|
42
|
+
Recurring jobs are declared in the initializer, and only run in production (a development machine should not fire them):
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
config.good_job.enable_cron = Rails.env.production?
|
|
46
|
+
config.good_job.cron = {
|
|
47
|
+
purge_old_sessions: {
|
|
48
|
+
cron: "0 3 * * *", # every day at 3am
|
|
49
|
+
class: "PurgeOldSessionsJob",
|
|
50
|
+
description: "Delete the user sessions that expired more than a month ago"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## The dashboard
|
|
56
|
+
|
|
57
|
+
GoodJob's dashboard is mounted at `/admin/good_job`. It sits outside `Admin::BaseController`, so it is guarded in the initializer by the same signed session cookie the admin uses: anyone who is not an administrator gets a 404 rather than a redirect, which keeps the route invisible. The installed request spec covers the three cases (administrator, privileged non-administrator, visitor).
|
|
58
|
+
|
|
59
|
+
## Mail deliveries are retried
|
|
60
|
+
|
|
61
|
+
GoodJob discards a failed job rather than retrying it, so a transient error from the mail service would lose the email. Every `deliver_later` goes through `MailDeliveryJob` instead, which retries five times with a growing delay:
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
class MailDeliveryJob < ActionMailer::MailDeliveryJob
|
|
65
|
+
retry_on StandardError, wait: :polynomially_longer, attempts: 5
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
An error raised in a scheduler thread, outside a job's own execution, has no retry handler to catch it; `config.good_job.on_thread_error` reports it through `Rails.error` like the rest of the app.
|