trek 2.3.2 → 2.5.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/.yarn/releases/yarn-4.18.1.cjs +1000 -0
- data/.yarnrc.yml +3 -5
- data/AGENTS.md +12 -8
- data/CHANGELOG.md +73 -0
- data/Gemfile.lock +226 -171
- data/Makefile +38 -1
- data/README.md +2 -2
- data/app/assets/icons/trek/passkey.svg +5 -0
- data/app/assets/stylesheets/trek/base.css +6 -0
- data/app/components/trek/entries/item_component/item_component.css +6 -0
- data/app/components/trek/form/image_field_component/image_field_component.html.slim +9 -0
- data/app/components/trek/form/image_field_component.rb +1 -5
- data/app/components/trek/form/password_strength_component/password_strength_component.css +56 -0
- data/app/components/trek/form/password_strength_component/password_strength_component.html.slim +8 -0
- data/app/components/trek/form/password_strength_component/password_strength_component.js +74 -0
- data/app/components/trek/form/password_strength_component.rb +29 -0
- data/app/components/trek/gate_component/gate_component.css +7 -0
- data/app/components/trek/icon/sprite_component.rb +3 -2
- 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/components/trek/section_component/section_component.css +22 -0
- data/app/components/trek/section_component/section_component.html.slim +5 -0
- data/app/components/trek/section_component/section_component.js +1 -0
- data/app/components/trek/section_component.rb +14 -0
- data/app/content/trek/content/bullet_list.rb +10 -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 +22 -0
- data/app/content/trek/content.rb +32 -0
- data/app/controllers/concerns/trek/auditable.rb +103 -0
- data/app/controllers/concerns/trek/filters.rb +2 -0
- data/app/controllers/concerns/trek/passkeys.rb +37 -0
- data/app/controllers/concerns/trek/reorderable.rb +14 -3
- data/app/controllers/trek/csp_reports_controller.rb +59 -0
- 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 +1 -1
- data/app/controllers/trek/resource_controller.rb +7 -1
- data/app/helpers/trek/audit_logs_helper.rb +21 -0
- data/app/helpers/trek/thumbnail_helper.rb +11 -0
- data/app/helpers/trek/user_agents_helper.rb +36 -0
- data/app/javascript/controllers/index.js +3 -0
- data/app/javascript/controllers/passkey_controller.js +118 -0
- data/app/javascript/trek.js +4 -0
- data/app/jobs/trek/audit_log/purge_job.rb +18 -0
- data/app/jobs/trek/purge_expired_sessions_job.rb +14 -0
- data/app/jobs/trek/resolve_session_hostname_job.rb +17 -0
- data/app/models/concerns/trek/audit_log.rb +30 -0
- data/app/models/concerns/trek/contentable.rb +9 -14
- data/app/models/concerns/trek/pageable.rb +10 -1
- data/app/models/concerns/trek/users/passkeys.rb +75 -0
- data/app/models/concerns/trek/users/password_history.rb +51 -0
- data/app/models/concerns/trek/users/password_policy.rb +85 -0
- data/app/models/concerns/trek/users/password_renewal.rb +51 -0
- data/app/models/concerns/trek/users/session_lifetime.rb +39 -0
- data/app/models/concerns/trek/users/sign_in_lockout.rb +67 -0
- data/app/models/concerns/trek/users/sign_ins.rb +31 -0
- data/app/models/concerns/trek/users/validations.rb +3 -2
- data/app/models/trek/feature.rb +6 -0
- data/app/models/trek/pwned_passwords.rb +40 -0
- data/app/models/trek/user_session.rb +10 -0
- data/app/policies/trek/audit_log_policy.rb +34 -0
- data/app/policies/trek/user_policy.rb +5 -0
- data/app/validators/not_disposable_validator.rb +18 -0
- 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 +1 -1
- data/app/views/trek/panels/prompts/_form.html.slim +1 -1
- data/config/brakeman.ignore +22 -0
- data/config/i18n-tasks.yml +7 -0
- data/config/locales/trek.en.yml +167 -39
- data/config/locales/trek.fr.yml +168 -40
- data/docs/.vitepress/config.mjs +8 -3
- data/docs/deploy.md +2 -0
- data/docs/getting-started.md +3 -3
- data/docs/proxies.md +53 -0
- data/docs/reference/components.md +1 -0
- data/docs/reference/concerns/contentable.md +2 -1
- data/docs/reference/controllers.md +1 -1
- data/docs/reference/environment-variables.md +2 -0
- data/docs/reference/formatters.md +31 -8
- data/docs/reference/generators/admin-user.md +1 -1
- data/docs/reference/generators/audit-log.md +113 -0
- data/docs/reference/generators/install.md +12 -3
- data/docs/reference/generators/security-headers.md +109 -0
- data/docs/reference/index.md +3 -0
- data/docs/reference/models/fragment.md +1 -0
- data/docs/reference/models/tag.md +4 -2
- data/docs/reference/models/user.md +123 -3
- data/docs/reference/validators.md +94 -0
- data/docs/security.md +90 -0
- data/docs/what-is-trek.md +4 -4
- data/lefthook.yml +8 -0
- data/lib/generators/trek/helpers.rb +13 -5
- data/lib/generators/trek/install/admin/user_password_resets_generator.rb +5 -0
- data/lib/generators/trek/install/admin/user_sessions_generator.rb +5 -0
- data/lib/generators/trek/install/admin/users_generator.rb +23 -0
- 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 +56 -0
- data/lib/generators/trek/install/authentication_generator.rb +78 -4
- data/lib/generators/trek/install/authorization_generator.rb +1 -1
- data/lib/generators/trek/install/esbuild_generator.rb +1 -2
- data/lib/generators/trek/install/mailer_generator.rb +18 -0
- data/lib/generators/trek/install/model_specs_generator.rb +6 -4
- data/lib/generators/trek/install/postcss_generator.rb +1 -4
- data/lib/generators/trek/install/postmark_generator.rb +2 -2
- data/lib/generators/trek/install/security_headers_generator.rb +49 -0
- 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/yarn_generator.rb +1 -1
- data/lib/generators/trek/install_generator.rb +62 -54
- data/lib/generators/trek/scaffold_generator.rb +13 -5
- data/lib/generators/trek/taxonomies_generator.rb +5 -0
- data/lib/generators/trek/templates/.gitlab-ci.yml +18 -2
- data/lib/generators/trek/templates/Makefile +1 -1
- data/lib/generators/trek/templates/controllers/admin/active_sessions_controller.rb +21 -0
- data/lib/generators/trek/templates/controllers/admin/audit_logs_controller.rb +30 -0
- 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/passkey_sessions_controller.rb +41 -0
- data/lib/generators/trek/templates/controllers/admin/passkeys_controller.rb +37 -0
- data/lib/generators/trek/templates/controllers/admin/user_password_resets_controller.rb +4 -4
- data/lib/generators/trek/templates/controllers/admin/user_sessions_controller.rb +53 -4
- data/lib/generators/trek/templates/controllers/admin/users_controller.rb +20 -0
- data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +58 -7
- data/lib/generators/trek/templates/helpers/application_helper.rb +0 -4
- data/lib/generators/trek/templates/initializers/audit_log.rb +11 -0
- data/lib/generators/trek/templates/initializers/content_security_policy.rb +49 -0
- data/lib/generators/trek/templates/initializers/permissions_policy.rb +19 -0
- data/lib/generators/trek/templates/jobs/admin/password_reset_job.rb +9 -0
- data/lib/generators/trek/templates/layouts/admin/auth.html.slim +0 -5
- data/lib/generators/trek/templates/layouts/admin.html.slim +0 -3
- data/lib/generators/trek/templates/mailers/admin/passwords_mailer.rb +1 -1
- data/lib/generators/trek/templates/mailers/admin_mailer.rb +28 -1
- data/lib/generators/trek/templates/migrations/audit_logs.rb.erb +27 -0
- data/lib/generators/trek/templates/migrations/tags.rb.erb +6 -1
- data/lib/generators/trek/templates/migrations/user_passkeys.rb.erb +24 -0
- data/lib/generators/trek/templates/migrations/user_password_renewal.rb.erb +8 -0
- data/lib/generators/trek/templates/migrations/user_previous_passwords.rb.erb +10 -0
- data/lib/generators/trek/templates/migrations/user_session_tracking.rb.erb +11 -0
- data/lib/generators/trek/templates/migrations/user_sign_in_lockout.rb.erb +7 -0
- data/lib/generators/trek/templates/migrations/user_sign_ins.rb.erb +13 -0
- data/lib/generators/trek/templates/models/audit_log.rb +3 -0
- data/lib/generators/trek/templates/models/fragment.rb +14 -0
- data/lib/generators/trek/templates/models/tag_category.rb +2 -1
- data/lib/generators/trek/templates/models/user/passkey.rb +17 -0
- data/lib/generators/trek/templates/models/user/previous_password.rb +4 -0
- data/lib/generators/trek/templates/models/user/session.rb +8 -0
- data/lib/generators/trek/templates/policies/audit_log.rb +4 -0
- data/lib/generators/trek/templates/spec/mailers/admin/passwords_mailer_spec.rb +16 -0
- data/lib/generators/trek/templates/spec/mailers/admin_mailer_spec.rb +51 -0
- data/lib/generators/trek/templates/spec/models/audit_log_spec.rb +43 -0
- data/lib/generators/trek/templates/spec/models/tag_spec.rb +52 -0
- data/lib/generators/trek/templates/spec/models/user/session_spec.rb +68 -0
- data/lib/generators/trek/templates/spec/models/user_spec.rb +142 -4
- data/lib/generators/trek/templates/spec/requests/admin/active_sessions_spec.rb +120 -0
- data/lib/generators/trek/templates/spec/requests/admin/audit_logs_spec.rb +149 -0
- data/lib/generators/trek/templates/spec/requests/admin/fragments_spec.rb +26 -2
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +8 -0
- data/lib/generators/trek/templates/spec/requests/admin/panels_spec.rb +54 -0
- data/lib/generators/trek/templates/spec/requests/admin/passkey_sessions_spec.rb +103 -0
- data/lib/generators/trek/templates/spec/requests/admin/passkeys_spec.rb +104 -0
- data/lib/generators/trek/templates/spec/requests/admin/password_renewal_spec.rb +83 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_lockout_spec.rb +95 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +95 -0
- data/lib/generators/trek/templates/spec/requests/admin/user_password_resets_spec.rb +43 -6
- data/lib/generators/trek/templates/spec/requests/admin/user_sessions_spec.rb +25 -2
- data/lib/generators/trek/templates/views/admin/audit_logs/index.html.slim +35 -0
- data/lib/generators/trek/templates/views/admin/audit_logs/show.html.slim +50 -0
- data/lib/generators/trek/templates/views/admin/fragments/index.html.slim +14 -3
- data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +16 -6
- data/lib/generators/trek/templates/views/admin/user_password_resets/new.html.slim +2 -1
- data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +27 -1
- data/lib/generators/trek/templates/views/admin/users/_passkeys.html.slim +67 -0
- data/lib/generators/trek/templates/views/admin/users/_properties.html.slim +21 -0
- data/lib/generators/trek/templates/views/admin/users/_sessions.html.slim +70 -0
- data/lib/generators/trek/templates/views/admin/users/index.html.slim +13 -0
- data/lib/generators/trek/templates/views/admin/users/show.html.slim +10 -21
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.html.slim +22 -0
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.en.text.erb +16 -0
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.html.slim +22 -0
- data/lib/generators/trek/templates/views/admin_mailer/new_sign_in.fr.text.erb +16 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.en.html.slim +17 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.en.text.erb +10 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.fr.html.slim +18 -0
- data/lib/generators/trek/templates/views/admin_mailer/sign_in_locked.fr.text.erb +10 -0
- data/lib/trek/admin_ip_allowlist.rb +52 -0
- data/lib/trek/csp_reports.rb +99 -0
- data/lib/trek/data/common_passwords.txt +857 -0
- data/lib/trek/data/passkey_providers.json +404 -0
- data/lib/trek/disposable_email_domains.rb +53 -0
- data/lib/trek/engine.rb +18 -1
- data/lib/trek/passkey_providers.rb +19 -0
- data/lib/trek/reverse_dns.rb +27 -0
- data/lib/trek/saved_attachments_reload.rb +2 -1
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +14 -1
- data/package.json +3 -5
- data/renovate.json +12 -1
- data/trek.gemspec +6 -3
- data/yarn.lock +2273 -2573
- metadata +160 -17
- data/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs +0 -541
- data/.yarn/releases/yarn-3.8.0.cjs +0 -875
- 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
- data/lib/generators/trek/templates/models/user_session.rb +0 -3
data/Makefile
CHANGED
|
@@ -1,17 +1,54 @@
|
|
|
1
1
|
.PHONY: *
|
|
2
2
|
|
|
3
|
-
lint
|
|
3
|
+
# One target per tool: `make -k lint` runs them all and reports every failure, as CI does.
|
|
4
|
+
lint: lint-ruby lint-slim lint-js lint-css lint-prettier lint-i18n
|
|
5
|
+
|
|
6
|
+
lint-ruby:
|
|
4
7
|
bundle exec rubocop
|
|
8
|
+
|
|
9
|
+
lint-slim:
|
|
5
10
|
bundle exec slim-lint "app/**/*.slim"
|
|
11
|
+
|
|
12
|
+
lint-js:
|
|
6
13
|
yarn eslint "app/**/*.js"
|
|
14
|
+
|
|
15
|
+
lint-css:
|
|
7
16
|
yarn stylelint "app/**/*.css"
|
|
17
|
+
|
|
18
|
+
lint-prettier:
|
|
8
19
|
yarn prettier --check "{app,config,lib,spec}/**/*.{css,js,json,md,yml}"
|
|
9
20
|
|
|
21
|
+
# Locale parity: every base-locale key must be translated in the others. (Full `health` doesn't fit
|
|
22
|
+
# an engine: keys are used by host apps, and many components use relative keys that only resolve
|
|
23
|
+
# there.)
|
|
24
|
+
lint-i18n:
|
|
25
|
+
bundle exec i18n-tasks missing -t diff
|
|
26
|
+
|
|
27
|
+
# One target per tool, as for lint
|
|
28
|
+
security: security-brakeman security-bundler-audit
|
|
29
|
+
|
|
30
|
+
security-brakeman:
|
|
31
|
+
bundle exec brakeman --no-exit-on-error
|
|
32
|
+
|
|
33
|
+
security-bundler-audit:
|
|
34
|
+
bundle exec bundle-audit check --update
|
|
35
|
+
|
|
10
36
|
fix:
|
|
11
37
|
bundle exec rubocop --autocorrect
|
|
12
38
|
yarn eslint "app/**/*.js" --fix
|
|
13
39
|
yarn stylelint "app/**/*.css" --fix
|
|
14
40
|
yarn prettier --write "{app,config,lib,spec}/**/*.{css,js,json,md,yml}"
|
|
41
|
+
$(MAKE) i18n-normalize
|
|
42
|
+
|
|
43
|
+
# Sort the locale keys (i18n-tasks), then format the files as the rest of the repo (Prettier): each
|
|
44
|
+
# tool alone undoes the other's style, so they always run together.
|
|
45
|
+
i18n-normalize:
|
|
46
|
+
bundle exec i18n-tasks normalize
|
|
47
|
+
yarn prettier --write "config/locales/*.yml"
|
|
48
|
+
|
|
49
|
+
# Fails when the locale files aren't normalized (see i18n-normalize)
|
|
50
|
+
i18n-check: i18n-normalize
|
|
51
|
+
git diff --exit-code config/locales
|
|
15
52
|
|
|
16
53
|
release:
|
|
17
54
|
@read -p "New version (current: $$(sed -n 's/.*VERSION = "\(.*\)"/\1/p' lib/trek/version.rb)): " version; \
|
data/README.md
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
|
|
2
|
+
<path fill-rule="evenodd" d="M4.8,4A4,4,0,1,1,.8,8,4,4,0,0,1,4.8,4Zm0,2.4A1.6,1.6,0,1,0,6.4,8,1.6,1.6,0,0,0,4.8,6.4Z"/>
|
|
3
|
+
<path d="M15.2,8.8H8.4V7.2h6.8a.8.8,0,0,1,0,1.6Z"/>
|
|
4
|
+
<path d="M12.8,11.2a.8.8,0,0,1-.8-.8V8h1.6v2.4A.8.8,0,0,1,12.8,11.2Z"/>
|
|
5
|
+
</svg>
|
|
@@ -41,6 +41,12 @@ body {
|
|
|
41
41
|
transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/* A term with more to say on hover, e.g. an IP address and its host name */
|
|
45
|
+
abbr[title] {
|
|
46
|
+
cursor: help;
|
|
47
|
+
text-decoration: underline dotted;
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
a {
|
|
45
51
|
color: var(--accent-9);
|
|
46
52
|
transition: color 0.2s ease;
|
|
@@ -31,3 +31,12 @@
|
|
|
31
31
|
size: :narrow,
|
|
32
32
|
data: remove_button_data_attributes,
|
|
33
33
|
)
|
|
34
|
+
/ The uploaded file itself, the preview being a thumbnail
|
|
35
|
+
= render Trek::ButtonComponent.new( \
|
|
36
|
+
text: t("admin.actions.see_original"),
|
|
37
|
+
size: :narrow,
|
|
38
|
+
href: image.url,
|
|
39
|
+
target: "_blank",
|
|
40
|
+
rel: "noopener",
|
|
41
|
+
) do |button|
|
|
42
|
+
- button.with_icon("trek/external")
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* Use component-local class names and add them to HTML via #class_for(name) helper */
|
|
2
|
+
|
|
3
|
+
/* The controller sets data-level, from 0 (too short) to 3 (strong), once a password is typed. */
|
|
4
|
+
|
|
5
|
+
.strength {
|
|
6
|
+
align-items: center;
|
|
7
|
+
display: flex;
|
|
8
|
+
gap: 1.2rem;
|
|
9
|
+
margin-top: 0.8rem;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.bar {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex: 1;
|
|
15
|
+
gap: 0.4rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.segment {
|
|
19
|
+
background-color: var(--slate-5);
|
|
20
|
+
border-radius: 0.2rem;
|
|
21
|
+
flex: 1;
|
|
22
|
+
height: 0.4rem;
|
|
23
|
+
transition: background-color 0.15s ease-out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.label {
|
|
27
|
+
color: var(--slate-11);
|
|
28
|
+
font-size: 0.8em;
|
|
29
|
+
min-width: 8ch;
|
|
30
|
+
text-align: right;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.root[data-level="0"] .label,
|
|
34
|
+
.root[data-level="1"] .label {
|
|
35
|
+
color: var(--tomato-11);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.root[data-level="1"] .segment:nth-child(-n + 1) {
|
|
39
|
+
background-color: var(--tomato-9);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.root[data-level="2"] .label {
|
|
43
|
+
color: var(--amber-11);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.root[data-level="2"] .segment:nth-child(-n + 2) {
|
|
47
|
+
background-color: var(--amber-9);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.root[data-level="3"] .label {
|
|
51
|
+
color: var(--grass-11);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.root[data-level="3"] .segment {
|
|
55
|
+
background-color: var(--grass-9);
|
|
56
|
+
}
|
data/app/components/trek/form/password_strength_component/password_strength_component.html.slim
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
div(class=root_class data=data_attributes)
|
|
2
|
+
= content
|
|
3
|
+
div class=class_for("strength")
|
|
4
|
+
div class=class_for("bar") aria-hidden="true"
|
|
5
|
+
- (LEVELS.size - 1).times do
|
|
6
|
+
span class=class_for("segment")
|
|
7
|
+
span(class=class_for("label") aria-live="polite"
|
|
8
|
+
data=stimulus_target_hash(:label))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import "./password_strength_component.css";
|
|
2
|
+
|
|
3
|
+
import { Controller as BaseController } from "@hotwired/stimulus";
|
|
4
|
+
|
|
5
|
+
// Keyboard rows (AZERTY and QWERTY), the alphabet and the digits, as Trek::Users::PasswordPolicy
|
|
6
|
+
const SEQUENCES = [
|
|
7
|
+
"azertyuiop",
|
|
8
|
+
"qsdfghjklm",
|
|
9
|
+
"wxcvbn",
|
|
10
|
+
"qwertyuiop",
|
|
11
|
+
"asdfghjkl",
|
|
12
|
+
"zxcvbnm",
|
|
13
|
+
"abcdefghijklmnopqrstuvwxyz",
|
|
14
|
+
"01234567890",
|
|
15
|
+
];
|
|
16
|
+
const SEQUENCE_LENGTH = 5;
|
|
17
|
+
|
|
18
|
+
// Rates the password typed from 0 (too short) to 3 (strong). Only a guide: the server checks the
|
|
19
|
+
// common passwords and the user's name and email too.
|
|
20
|
+
export class Controller extends BaseController {
|
|
21
|
+
static targets = ["label"];
|
|
22
|
+
static values = {
|
|
23
|
+
minLength: Number,
|
|
24
|
+
passphraseLength: Number,
|
|
25
|
+
labels: Array,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
connect() {
|
|
29
|
+
this.input = this.element.querySelector("input");
|
|
30
|
+
this.update = this.update.bind(this);
|
|
31
|
+
this.input.addEventListener("input", this.update);
|
|
32
|
+
this.update();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
disconnect() {
|
|
36
|
+
this.input.removeEventListener("input", this.update);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
update() {
|
|
40
|
+
const password = this.input.value;
|
|
41
|
+
const level = password ? this.level(password) : 0;
|
|
42
|
+
|
|
43
|
+
// Read by the CSS, which colors the bar and the label
|
|
44
|
+
if (password) this.element.dataset.level = level;
|
|
45
|
+
else delete this.element.dataset.level;
|
|
46
|
+
this.labelTarget.textContent = password ? this.labelsValue[level] : "";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
level(password) {
|
|
50
|
+
if (password.length < this.minLengthValue) return 0;
|
|
51
|
+
if (this.sequence(password)) return 1;
|
|
52
|
+
if (password.length >= this.passphraseLengthValue) return 3;
|
|
53
|
+
|
|
54
|
+
const complex = /\d/.test(password) && /[^\p{L}\p{N}\s]/u.test(password);
|
|
55
|
+
if (!complex) return 1;
|
|
56
|
+
|
|
57
|
+
return password.length >= this.minLengthValue + 4 ? 3 : 2;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
sequence(password) {
|
|
61
|
+
const normalized = password.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
62
|
+
if (new RegExp(`(.)\\1{${SEQUENCE_LENGTH - 1}}`).test(normalized))
|
|
63
|
+
return true;
|
|
64
|
+
|
|
65
|
+
return SEQUENCES.some((row) => {
|
|
66
|
+
const reversed = [...row].reverse().join("");
|
|
67
|
+
for (let i = 0; i + SEQUENCE_LENGTH <= normalized.length; i++) {
|
|
68
|
+
const chunk = normalized.slice(i, i + SEQUENCE_LENGTH);
|
|
69
|
+
if (row.includes(chunk) || reversed.includes(chunk)) return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trek
|
|
4
|
+
module Form
|
|
5
|
+
# Wraps a new password field with a bar rating the password as it is typed, against the rules
|
|
6
|
+
# of Trek::Users::PasswordPolicy. Only a guide: the model has the last word.
|
|
7
|
+
#
|
|
8
|
+
# = render Trek::Form::PasswordStrengthComponent.new(min_length: User.password_min_length,
|
|
9
|
+
# passphrase_length: User.passphrase_length) do
|
|
10
|
+
# = f.password_field :password, autocomplete: "new-password"
|
|
11
|
+
class PasswordStrengthComponent < Trek::Component
|
|
12
|
+
LEVELS = %i[too_short weak fair strong].freeze
|
|
13
|
+
|
|
14
|
+
option :min_length
|
|
15
|
+
option :passphrase_length
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def data_attributes
|
|
20
|
+
{
|
|
21
|
+
controller: identifier,
|
|
22
|
+
"#{identifier}-min-length-value": min_length,
|
|
23
|
+
"#{identifier}-passphrase-length-value": passphrase_length,
|
|
24
|
+
"#{identifier}-labels-value": LEVELS.map { |level| t("trek.password_strength.#{level}") }.to_json
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -21,3 +21,10 @@
|
|
|
21
21
|
margin-bottom: 3.2rem;
|
|
22
22
|
padding-bottom: 2.4rem;
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
/* Another way in below the first form, e.g. signing in with a passkey */
|
|
26
|
+
.wrapper > form + form {
|
|
27
|
+
border-top: 1px solid var(--slate-6);
|
|
28
|
+
margin-top: 3.2rem;
|
|
29
|
+
padding-top: 3.2rem;
|
|
30
|
+
}
|
|
@@ -67,11 +67,12 @@ module Trek
|
|
|
67
67
|
# Extract inner content (children) from the second pass
|
|
68
68
|
inner_content = children_sanitized.sub(/<svg[^>]*>/, "").sub("</svg>", "")
|
|
69
69
|
|
|
70
|
-
# Combine: symbol element from first pass + children from second pass
|
|
70
|
+
# Combine: symbol element from first pass + children from second pass. Black becomes
|
|
71
|
+
# currentColor once the children are in: they carry the strokes and fills.
|
|
71
72
|
svg_sanitized
|
|
72
73
|
.sub("<svg", "<symbol id=\"c-icon-#{key}\"")
|
|
73
|
-
.gsub(/#0{3,6}/, "currentColor")
|
|
74
74
|
.sub(">", ">#{inner_content}")
|
|
75
|
+
.gsub(/#0{3,6}/, "currentColor")
|
|
75
76
|
.sub("</svg>", "</symbol>")
|
|
76
77
|
.gsub(/[\r\n]+/, "")
|
|
77
78
|
.strip
|
|
@@ -57,10 +57,10 @@ module Trek
|
|
|
57
57
|
|
|
58
58
|
def image
|
|
59
59
|
if node.image&.exists?
|
|
60
|
-
image_tag node.image
|
|
60
|
+
image_tag Trek::ThumbnailHelper.thumbnail_url(node.image, 80, 60),
|
|
61
61
|
loading: "lazy"
|
|
62
62
|
elsif node.parent&.image&.exists?
|
|
63
|
-
image_tag node.parent.image
|
|
63
|
+
image_tag Trek::ThumbnailHelper.thumbnail_url(node.parent.image, 80, 60),
|
|
64
64
|
loading: "lazy"
|
|
65
65
|
else
|
|
66
66
|
render Trek::IconComponent.new("trek/pic")
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
= form_with url: action, method: "get", class: root_class
|
|
2
|
-
label(class=class_for("label") for=
|
|
2
|
+
label(class=class_for("label") for=input_id) = label_text
|
|
3
3
|
div(class=class_for("wrapper"))
|
|
4
4
|
input (
|
|
5
|
+
id=input_id
|
|
5
6
|
name="search"
|
|
6
7
|
type="text"
|
|
7
8
|
value=value
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
module Trek
|
|
4
4
|
class SearchComponent < Trek::Component
|
|
5
5
|
option :action
|
|
6
|
-
option :label,
|
|
6
|
+
option :label, optional: true
|
|
7
7
|
option :value, optional: true
|
|
8
|
+
|
|
9
|
+
def label_text
|
|
10
|
+
label || t(".search")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def input_id
|
|
14
|
+
@input_id ||= "search-#{SecureRandom.hex(4)}"
|
|
15
|
+
end
|
|
8
16
|
end
|
|
9
17
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* Use component-local class names and add them to HTML via #class_for(name) helper */
|
|
2
|
+
|
|
3
|
+
.root {
|
|
4
|
+
line-height: 1.25;
|
|
5
|
+
margin-bottom: 3.2rem;
|
|
6
|
+
max-width: 64rem;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* As a property's title */
|
|
10
|
+
.title {
|
|
11
|
+
color: var(--slate-12);
|
|
12
|
+
font-size: inherit;
|
|
13
|
+
font-weight: var(--semibold);
|
|
14
|
+
margin: 0 0 1.2rem;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* As a form field's hint */
|
|
18
|
+
.hint {
|
|
19
|
+
color: var(--slate-11);
|
|
20
|
+
font-size: 0.8em;
|
|
21
|
+
margin: -0.6rem 0 1.2rem;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./section_component.css";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trek
|
|
4
|
+
# A titled section of a page (whose own title is the h1), e.g. a list under its heading, with an
|
|
5
|
+
# optional hint between them
|
|
6
|
+
class SectionComponent < Trek::Component
|
|
7
|
+
option :title
|
|
8
|
+
option :hint, optional: true
|
|
9
|
+
|
|
10
|
+
def heading_id
|
|
11
|
+
@heading_id ||= "section-#{SecureRandom.hex(4)}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# A document with the record holding it. Problems reported to `Rails.error` while parsing or rendering it
|
|
4
|
+
# name the record in their context (`trek_content: "Page#12"`), which error trackers like AppSignal show as
|
|
5
|
+
# a tag. Documents are often rendered later than they're parsed, in a view, so the renderer sets it too.
|
|
6
|
+
class Document < Prosemirror::Document
|
|
7
|
+
def self.parse(record, json)
|
|
8
|
+
with_context(record) { new(Trek::Content.schema.parse(json).root, schema: Trek::Content.schema, record:) }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.with_context(record, &)
|
|
12
|
+
ActiveSupport::ExecutionContext.set(trek_content: "#{record.class.name}##{record.id}", &)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attr_reader :record
|
|
16
|
+
|
|
17
|
+
def initialize(root, record:, schema: Trek::Content.schema)
|
|
18
|
+
super(root, schema:)
|
|
19
|
+
@record = record
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_phlex
|
|
23
|
+
Renderer.new(self)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Renderer < Prosemirror::HTMLRenderer
|
|
27
|
+
def around_template(&)
|
|
28
|
+
Document.with_context(@document.record) { super }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# An image added with the content editor's image panel: a figure with its caption and credit.
|
|
4
|
+
# Subclass it to render the app's own component, for example with `derivation_url`:
|
|
5
|
+
#
|
|
6
|
+
# class ImageBlock < Trek::Content::ImageBlock
|
|
7
|
+
# def view_template
|
|
8
|
+
# render Components::Figure.new(image: image&.derivation_url(:thumbnail, 930, 1200), caption: @text)
|
|
9
|
+
# end
|
|
10
|
+
# end
|
|
11
|
+
class ImageBlock < Prosemirror::NodeType
|
|
12
|
+
group :block
|
|
13
|
+
|
|
14
|
+
prop :file_data, _String?
|
|
15
|
+
prop :alt, _String?
|
|
16
|
+
prop :text, _String?
|
|
17
|
+
prop :credit, _String?
|
|
18
|
+
prop :size, _Union?(*Trek::ContentEditor::Image::SIZES.map(&:to_s))
|
|
19
|
+
|
|
20
|
+
def view_template
|
|
21
|
+
return unless (src = image && safe_url(image.url))
|
|
22
|
+
|
|
23
|
+
figure(data_size: @size) do
|
|
24
|
+
img(src:, alt: @alt.to_s)
|
|
25
|
+
figcaption { caption } if @text.present? || @credit.present?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# The uploaded file, or nil when the node has none or its data is invalid.
|
|
32
|
+
def image
|
|
33
|
+
return if @file_data.blank?
|
|
34
|
+
|
|
35
|
+
@image ||= begin
|
|
36
|
+
object = Trek::ContentEditor::Image.new(file_data: @file_data)
|
|
37
|
+
ModelImageUploader::Attacher.from_model(object, :file).load_model(object, :file)
|
|
38
|
+
object.file
|
|
39
|
+
rescue JSON::ParserError, Shrine::Error => e
|
|
40
|
+
Rails.error.report(e, handled: true)
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def caption
|
|
46
|
+
plain(@text) if @text.present?
|
|
47
|
+
whitespace if @text.present? && @credit.present?
|
|
48
|
+
span { @credit } if @credit.present?
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# Turns links to records, stored as GlobalIDs (`gid://app/Page/1`), into their URLs. Called with all the
|
|
4
|
+
# URLs of a document at once, it loads their records with one query per model. A record that doesn't
|
|
5
|
+
# exist resolves to nil, so its link is removed and its text kept.
|
|
6
|
+
class LinkResolver
|
|
7
|
+
# `url_for(page)` calls `page_url`. Included before the route helpers, so an app's own
|
|
8
|
+
# `direct :page` route takes precedence over Trek's helper.
|
|
9
|
+
include Trek::PagePathHelper
|
|
10
|
+
include Rails.application.routes.url_helpers
|
|
11
|
+
|
|
12
|
+
# A Hash from each URL to its resolved URL.
|
|
13
|
+
def call(urls)
|
|
14
|
+
records = locate(urls.select { |url| url.start_with?("gid://") })
|
|
15
|
+
urls.index_with { |url| url.start_with?("gid://") ? records[url]&.then { |record| url_for(record) } : url }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# The records of the GlobalIDs, by GlobalID. Records are matched by id rather than by their own
|
|
21
|
+
# GlobalID, which names their subclass. An unknown model raises NameError: its records are missing.
|
|
22
|
+
def locate(urls)
|
|
23
|
+
gids = urls.filter_map { |url| GlobalID.parse(url)&.then { |gid| [url, gid] } }
|
|
24
|
+
gids.group_by { |_url, gid| gid.model_name }.each_with_object({}) do |(_model, group), records|
|
|
25
|
+
found = GlobalID::Locator.locate_many(group.map(&:last), ignore_missing: true).index_by { |record| record.id.to_s }
|
|
26
|
+
group.each { |url, gid| records[url] = found[gid.model_id] }
|
|
27
|
+
rescue NameError
|
|
28
|
+
next
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# Empty list items, with no content or only empty paragraphs, render nothing, like empty paragraphs.
|
|
4
|
+
class ListItem < Prosemirror::Nodes::ListItem
|
|
5
|
+
def self.empty?(node)
|
|
6
|
+
node.content.all? { |child| child.type == :paragraph && child.content.empty? }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Whether a list has no item to render: only empty items, and whitespace.
|
|
10
|
+
def self.empty_list?(node)
|
|
11
|
+
node.content.all? { |child| child.text? ? child.text.strip.empty? : child.type == :list_item && empty?(child) }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template(&)
|
|
15
|
+
li(&) unless self.class.empty?(node)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# A call to action added with the content editor's prompt panel, rendered as a link.
|
|
4
|
+
# Subclass it to render the app's own button component.
|
|
5
|
+
class PromptsBlock < Prosemirror::NodeType
|
|
6
|
+
group :block
|
|
7
|
+
|
|
8
|
+
prop :text, _String?
|
|
9
|
+
prop :href, _String?
|
|
10
|
+
prop :target, _String?
|
|
11
|
+
prop :title, _String?
|
|
12
|
+
prop :color, _String?(/\A[\w-]+\z/)
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
href = @href.present? && safe_url(@href)
|
|
16
|
+
return if !href || @text.blank?
|
|
17
|
+
|
|
18
|
+
a(href:, target: @target, title: @title, data_color: @color) { @text }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
# Renders ProseMirror content (see Trek::Contentable) with the `prosemirror` gem.
|
|
3
|
+
#
|
|
4
|
+
# The schema is Tiptap's, with Trek's blocks. To add or replace node types:
|
|
5
|
+
#
|
|
6
|
+
# # config/initializers/trek.rb
|
|
7
|
+
# Rails.application.config.to_prepare do
|
|
8
|
+
# Trek::Content.schema = Trek::Content.default_schema.with(Content::ImageBlock)
|
|
9
|
+
# end
|
|
10
|
+
module Content
|
|
11
|
+
class << self
|
|
12
|
+
attr_writer :schema
|
|
13
|
+
|
|
14
|
+
def schema
|
|
15
|
+
@schema || (@default_schema ||= default_schema)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Called after code reloading, as the default schema holds node type classes.
|
|
19
|
+
def clear_default_schema
|
|
20
|
+
@default_schema = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def default_schema
|
|
24
|
+
Prosemirror::Schema.tiptap(
|
|
25
|
+
case: :camel,
|
|
26
|
+
resolve_urls: LinkResolver.new,
|
|
27
|
+
on_invalid: ->(error) { Rails.error.report(error, handled: true) }
|
|
28
|
+
).with(Paragraph, ListItem, BulletList, OrderedList, ImageBlock, PromptsBlock)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|