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
|
@@ -31,12 +31,3 @@
|
|
|
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")
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "content_disposition"
|
|
4
|
+
|
|
3
5
|
module Trek
|
|
4
6
|
module Form
|
|
5
7
|
class ImageFieldComponent < ViewComponent::Form::FileFieldComponent
|
|
@@ -16,27 +18,48 @@ module Trek
|
|
|
16
18
|
|
|
17
19
|
private
|
|
18
20
|
|
|
21
|
+
# The thumbnail, with links opening the uploaded file in a new tab and downloading it. A file just picked,
|
|
22
|
+
# not yet saved, has no URL: the JS replaces the preview with its own thumbnail.
|
|
19
23
|
def preview
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
return render(Trek::IconComponent.new("trek/pic")) unless image&.exists?
|
|
25
|
+
|
|
26
|
+
tag.div(class: class_for("original")) do
|
|
27
|
+
safe_join([
|
|
28
|
+
image_tag(image_url, loading: "lazy", alt: ""),
|
|
29
|
+
tag.div(class: class_for("original-actions")) do
|
|
30
|
+
safe_join([
|
|
31
|
+
original_link(image.url, "trek/external", t("admin.actions.see_original"),
|
|
32
|
+
target: "_blank", rel: "noopener"),
|
|
33
|
+
original_link(download_url, "trek/download", t("admin.actions.download_original"),
|
|
34
|
+
download: image.original_filename.to_s)
|
|
35
|
+
])
|
|
36
|
+
end
|
|
37
|
+
])
|
|
29
38
|
end
|
|
30
39
|
end
|
|
31
40
|
|
|
32
|
-
def
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
else
|
|
36
|
-
image.url
|
|
41
|
+
def original_link(url, icon, label, **options)
|
|
42
|
+
link_to url, class: class_for("original-action"), title: label, "aria-label": label, **options do
|
|
43
|
+
render Trek::IconComponent.new(icon, aria_hidden: true)
|
|
37
44
|
end
|
|
38
45
|
end
|
|
39
46
|
|
|
47
|
+
def image_url
|
|
48
|
+
Trek::ThumbnailHelper.thumbnail_url(image, 300, 150)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The `download` attribute only applies to a file on the admin's own host. On S3, the file is served from
|
|
52
|
+
# the bucket's host, so it's a URL signed to answer as an attachment: signed for the bucket itself, without
|
|
53
|
+
# the `url_options` host (a CDN's), and valid for a day, as the page may stay open a while.
|
|
54
|
+
def download_url
|
|
55
|
+
image.url(
|
|
56
|
+
public: false,
|
|
57
|
+
host: nil,
|
|
58
|
+
expires_in: 1.day.to_i,
|
|
59
|
+
response_content_disposition: ContentDisposition.attachment(image.original_filename)
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
|
|
40
63
|
def image
|
|
41
64
|
object.public_send(:"#{method_name}")
|
|
42
65
|
end
|
|
@@ -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,53 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
module Content
|
|
3
|
+
# Removes from a document what rendering skips (Paragraph, ListItem, BulletList, OrderedList): empty
|
|
4
|
+
# paragraphs, empty list items, and lists left without items. Trek::Contentable calls it before saving.
|
|
5
|
+
#
|
|
6
|
+
# The document stays one the editor can open, without the schema adding anything back: an empty
|
|
7
|
+
# document keeps one paragraph, a list item keeps its first paragraph, which it needs before a nested
|
|
8
|
+
# list, and a node left with only empty paragraphs, like a quote, is kept as it was. Whatever the schema
|
|
9
|
+
# doesn't know, node types or attributes of other Tiptap extensions, is kept.
|
|
10
|
+
class Cleaner
|
|
11
|
+
LISTS = %i[bullet_list ordered_list].freeze
|
|
12
|
+
|
|
13
|
+
# A Prosemirror::Document, cleaned
|
|
14
|
+
def call(document)
|
|
15
|
+
root = document.root
|
|
16
|
+
content = clean_content(root.content)
|
|
17
|
+
content = [Prosemirror::Node.new(type: :paragraph)] if content.empty?
|
|
18
|
+
Prosemirror::Document.new(content == root.content ? root : root.with(content:), schema: document.schema)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def clean_content(nodes)
|
|
24
|
+
nodes.filter_map { |node| clean(node) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The node, cleaned, or nil to remove it
|
|
28
|
+
def clean(node)
|
|
29
|
+
return if empty_paragraph?(node)
|
|
30
|
+
return node if node.text? || node.content.empty?
|
|
31
|
+
return clean_list_item(node) if node.type == :list_item
|
|
32
|
+
|
|
33
|
+
content = clean_content(node.content)
|
|
34
|
+
return content.presence && node.with(content:) if LISTS.include?(node.type)
|
|
35
|
+
return node if content.empty? || content == node.content
|
|
36
|
+
|
|
37
|
+
node.with(content:)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def clean_list_item(item)
|
|
41
|
+
return if ListItem.empty?(item)
|
|
42
|
+
|
|
43
|
+
first, *rest = item.content
|
|
44
|
+
content = [empty_paragraph?(first) ? first : clean(first), *clean_content(rest)]
|
|
45
|
+
content == item.content ? item : item.with(content:)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def empty_paragraph?(node)
|
|
49
|
+
node.type == :paragraph && node.content.empty?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
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(heading_ids: false)
|
|
23
|
+
Renderer.new(self, heading_ids:)
|
|
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,21 @@
|
|
|
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
|
+
|
|
13
|
+
def view_template
|
|
14
|
+
href = @href.present? && safe_url(@href)
|
|
15
|
+
return if !href || @text.blank?
|
|
16
|
+
|
|
17
|
+
a(href:, target: @target, title: @title) { @text }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
# The content without what rendering skips (see Cleaner), as a Hash. Problems with the content are
|
|
24
|
+
# reported when it's rendered, not when it's cleaned.
|
|
25
|
+
def clean(json)
|
|
26
|
+
Cleaner.new.call(schema.with_options(on_invalid: nil).parse(json)).to_h
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def default_schema
|
|
30
|
+
Prosemirror::Schema.tiptap(
|
|
31
|
+
case: :camel,
|
|
32
|
+
resolve_urls: LinkResolver.new,
|
|
33
|
+
on_invalid: ->(error) { Rails.error.report(error, handled: true) }
|
|
34
|
+
).with(Paragraph, ListItem, BulletList, OrderedList, ImageBlock, PromptsBlock)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -7,13 +7,18 @@ module Trek
|
|
|
7
7
|
before_action :set_mode, only: [:index]
|
|
8
8
|
# rubocop:enable Rails/LexicallyScopedActionFilter
|
|
9
9
|
|
|
10
|
+
# The index's reorder form posts there
|
|
11
|
+
helper_method :reorder_path
|
|
12
|
+
|
|
10
13
|
def reorder
|
|
11
14
|
authorize!
|
|
12
15
|
objects = reorderable_objects.index_by(&:id)
|
|
16
|
+
ordered = reorder_params.sort_by { |_id, index| index }.filter_map { |id, _index| objects[id.to_i] }
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
# Saving the records one at a time repeats queries, which Prosopite, in development and test, would
|
|
19
|
+
# take for an N+1
|
|
20
|
+
without_n_plus_one_detection do
|
|
21
|
+
model.transaction { without_list_updates { place_in_order(ordered) } }
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
redirect_to reorder_success_redirect, notice: reorder_notice
|
|
@@ -42,6 +47,30 @@ module Trek
|
|
|
42
47
|
[:admin, *model_collection_route]
|
|
43
48
|
end
|
|
44
49
|
|
|
50
|
+
# The JS posts the whole list in its new order. A tree ordered by closure_tree (`numeric_order`, which
|
|
51
|
+
# gives `append_sibling`) renumbers the siblings at each save: the first record takes the place of the
|
|
52
|
+
# current first one, and each other record goes after the previous one. Otherwise, each record gets its
|
|
53
|
+
# position from the top of the list, 1 unless acts_as_list's `top_of_list` says otherwise.
|
|
54
|
+
def place_in_order(ordered)
|
|
55
|
+
if ordered.first.respond_to?(:append_sibling)
|
|
56
|
+
current_first = ordered.min_by(&:position)
|
|
57
|
+
current_first.prepend_sibling(ordered.first) unless current_first == ordered.first
|
|
58
|
+
ordered.each_cons(2) { |previous, object| previous.append_sibling(object) }
|
|
59
|
+
else
|
|
60
|
+
top = ordered.first.respond_to?(:acts_as_list_top) ? ordered.first.acts_as_list_top : 0
|
|
61
|
+
ordered.each.with_index(top) { |object, position| object.update(position:) unless object.position == position }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# acts_as_list would shift the other records at each save, moving those already placed
|
|
66
|
+
def without_list_updates(&)
|
|
67
|
+
model.respond_to?(:acts_as_list_no_update) ? model.acts_as_list_no_update(&) : yield
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def without_n_plus_one_detection(&)
|
|
71
|
+
defined?(Prosopite) ? Prosopite.pause(&) : yield
|
|
72
|
+
end
|
|
73
|
+
|
|
45
74
|
def reorder_notice
|
|
46
75
|
t("admin.#{model_collection}.reorder.success")
|
|
47
76
|
end
|
|
@@ -17,15 +17,14 @@ module Trek
|
|
|
17
17
|
# A report is a few hundred bytes; the Reporting API may group a few
|
|
18
18
|
MAX_BODY = 64.kilobytes
|
|
19
19
|
NEW_VIOLATIONS_PER_HOUR = 20
|
|
20
|
+
# AppSignal drops a tag of 256 characters or more, without a warning
|
|
21
|
+
TAG_LENGTH = 255
|
|
20
22
|
|
|
21
23
|
# Browsers send no CSRF token; the endpoint only logs and reports, with no session nor user
|
|
22
24
|
skip_forgery_protection
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# Against a flood from many addresses
|
|
27
|
-
rate_limit to: 600, within: 1.minute, by: -> { "all" }, with: -> { head :too_many_requests }
|
|
28
|
-
end
|
|
25
|
+
rate_limit to: 60, within: 1.minute, with: -> { head :too_many_requests }
|
|
26
|
+
# Against a flood from many addresses
|
|
27
|
+
rate_limit to: 600, within: 1.minute, by: -> { "all" }, with: -> { head :too_many_requests }
|
|
29
28
|
|
|
30
29
|
def create
|
|
31
30
|
body = request.body.read(MAX_BODY + 1).to_s
|
|
@@ -43,10 +42,21 @@ module Trek
|
|
|
43
42
|
::Appsignal.report_error(CspViolation.new(violation.to_s)) do
|
|
44
43
|
::Appsignal.set_namespace("csp")
|
|
45
44
|
::Appsignal.set_action(incident(violation))
|
|
46
|
-
::Appsignal.add_tags(
|
|
45
|
+
::Appsignal.add_tags(tags(violation))
|
|
47
46
|
end
|
|
48
47
|
end
|
|
49
48
|
|
|
49
|
+
# What tells the violation apart, within its incident: where, what, and in which browser
|
|
50
|
+
def tags(violation)
|
|
51
|
+
{
|
|
52
|
+
page: violation.page,
|
|
53
|
+
disposition: violation.disposition,
|
|
54
|
+
source: violation.source,
|
|
55
|
+
sample: violation.sample,
|
|
56
|
+
user_agent: request.user_agent
|
|
57
|
+
}.compact_blank.transform_values { |value| value.truncate(TAG_LENGTH) }
|
|
58
|
+
end
|
|
59
|
+
|
|
50
60
|
# AppSignal groups the violations by action: the directive and the blocked origin
|
|
51
61
|
def incident(violation)
|
|
52
62
|
"#{violation.directive} #{violation.blocked}"
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module Trek
|
|
2
2
|
module Panels
|
|
3
3
|
class BaseController < Trek::BaseController
|
|
4
|
+
# Stands in for a page in the link and prompt panels' choices when the current
|
|
5
|
+
# href isn't a page's global id (another site, a path, a mailto:…), so the select keeps it
|
|
6
|
+
HrefPlaceholder = Data.define(:to_global_id, :title)
|
|
4
7
|
end
|
|
5
8
|
end
|
|
6
9
|
end
|
|
@@ -29,7 +29,7 @@ module Trek
|
|
|
29
29
|
|
|
30
30
|
def set_pages
|
|
31
31
|
@pages = []
|
|
32
|
-
@pages <<
|
|
32
|
+
@pages << HrefPlaceholder.new(to_global_id: object_params[:href], title: object_params[:href]) if object_params[:href] && !object_params[:href].start_with?("gid")
|
|
33
33
|
@pages += Page.alpha_ordered if defined?(Page)
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -29,12 +29,12 @@ module Trek
|
|
|
29
29
|
|
|
30
30
|
def set_pages
|
|
31
31
|
@pages = []
|
|
32
|
-
@pages <<
|
|
32
|
+
@pages << HrefPlaceholder.new(to_global_id: object_params[:href], title: object_params[:href]) if object_params[:href] && !object_params[:href].start_with?("gid")
|
|
33
33
|
@pages += Page.alpha_ordered if defined?(Page)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def object_params
|
|
37
|
-
params.require(:prompt).permit(:turbo_frame_id, :
|
|
37
|
+
params.require(:prompt).permit(:turbo_frame_id, :href, :text, :target, :title)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -37,9 +37,9 @@ module Trek
|
|
|
37
37
|
else
|
|
38
38
|
format.html do
|
|
39
39
|
flash.now[:alert] = t("admin.errors.message", count: @object.errors.count)
|
|
40
|
-
render :new, status: :
|
|
40
|
+
render :new, status: :unprocessable_content
|
|
41
41
|
end
|
|
42
|
-
format.json { render json: @object.errors, status: :
|
|
42
|
+
format.json { render json: @object.errors, status: :unprocessable_content }
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -54,9 +54,9 @@ module Trek
|
|
|
54
54
|
else
|
|
55
55
|
format.html do
|
|
56
56
|
flash.now[:alert] = t("admin.errors.message", count: @object.errors.count)
|
|
57
|
-
render :edit, status: :
|
|
57
|
+
render :edit, status: :unprocessable_content
|
|
58
58
|
end
|
|
59
|
-
format.json { render json: @object.errors, status: :
|
|
59
|
+
format.json { render json: @object.errors, status: :unprocessable_content }
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -66,7 +66,7 @@ module Trek
|
|
|
66
66
|
unless @object.destroy
|
|
67
67
|
return respond_to do |format|
|
|
68
68
|
format.html { redirect_back_or_to [:admin, @object], alert: @object.errors.full_messages.to_sentence }
|
|
69
|
-
format.json { render json: @object.errors, status: :
|
|
69
|
+
format.json { render json: @object.errors, status: :unprocessable_content }
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
# The URL of an uploaded image's thumbnail: through Shrine's derivation endpoint when the uploader loads
|
|
3
|
+
# it (the generated ImageUploader comments it out), or the image itself otherwise
|
|
4
|
+
module ThumbnailHelper
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
def thumbnail_url(file, width, height)
|
|
8
|
+
file.respond_to?(:derivation_url) ? file.derivation_url(:thumbnail, width, height) : file.url
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
module Trek
|
|
4
4
|
# Deletes the signed-in browsers past their idle timeout or lifetime (Trek::Users::SessionLifetime):
|
|
5
5
|
# they can't sign anyone in anymore. Schedule it daily with the app's Active Job backend, e.g. a
|
|
6
|
-
# GoodJob cron entry.
|
|
6
|
+
# GoodJob cron entry. Purges User::Session, or the session model named, e.g. a public account's
|
|
7
|
+
# ("Customer::Session").
|
|
7
8
|
# rubocop:disable Rails/ApplicationJob -- the gem can't rely on the host app's ApplicationJob
|
|
8
9
|
class PurgeExpiredSessionsJob < ActiveJob::Base
|
|
9
|
-
def perform
|
|
10
|
-
|
|
10
|
+
def perform(session_class = "User::Session")
|
|
11
|
+
session_class.constantize.expired.in_batches(of: 1000).delete_all
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
# rubocop:enable Rails/ApplicationJob
|