inline_forms 8.1.83 → 8.1.85

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3532bd1d698fa7928f3815b0ff11768480c683e5027b5da39370ba838a5cc4fe
4
- data.tar.gz: 628c9cdd6dd4a1d9dff64de4fa1d3ca29df787cce9328a226c1b5d709fd5aa8f
3
+ metadata.gz: bfea9f6d48988ef6cb10aa6631e6b35b61ab2c1833bdd3c574f1ece144c72b3e
4
+ data.tar.gz: 8b7d53c69dd60028833cf4b7112162baee37b4fdf18ea441d8f5cda0592bee39
5
5
  SHA512:
6
- metadata.gz: e1cdaa160a5c5768328dc85a87efadbac34ad64fa57926c03caef798bbace22ddc573684fed74dccd6c93dd821e213862db86ca6a215a7a501cb7033a5e31a78
7
- data.tar.gz: db9338b05cec3cd75d2d17b4a1286091c451d57ccbea02263571a0d6f674bbbb4352083f762b5b212381c29974caefdcf0bc2327447a909f7036a7cc786b301f
6
+ metadata.gz: dba83a8ec7081f256cc836f45bd05bbc64a39683f2937f5ea99ec9421ff70c7a19979119db93dd2bd8c54e1c5b22d29a30423514965ac6194c19a8c266de9c82
7
+ data.tar.gz: db81917c887f949c399cfd4c2a217fd90073142f260802b956e8bb830563a5963e72a24fbc08a3f0714ccf90733d6837676eebb5b00604f14b99f4b64400038d
data/CHANGELOG.md CHANGED
@@ -8,6 +8,56 @@ All notable changes to this project are documented in this file.
8
8
 
9
9
  - Known issues, parked (local note `stuff/2026-10-31-dropdown-rule-3-parked.md`) with dropdown order rule 3: `includes`, `group` or `select` in `inline_forms_list` make `dropdown` and `dropdown_with_other` raise while `/index` works, so 8.1.65's fix for a list order on a joined table holds only for `joins`, `left_joins` and `eager_load`; a has_many join gives duplicate options. Present since 8.1.60. No host's list scope has these today. Parked; not changed.
10
10
 
11
+ ## [8.1.85] - 2026-11-25
12
+
13
+ From a review of 8.1.81 to 8.1.84 (local note `stuff/reviews/2026-11-25-review-8.1.81-8.1.84.md`).
14
+
15
+ ### Security
16
+
17
+ - **`form_element=rich_text` on a `:text_area` row is refused when the app overrides any of `text_area_show`, `_edit` or `_update`**, in its helpers or on the controller. 8.1.84 looked only at `text_area_show` in the view helpers, so an app that replaced only `text_area_update` (where its checks are) or included its override only into the controller was still sent around to the engine's `rich_text_update`, and the raw HTML was saved. The same holds for `:plain_text_area` delegating to `:plain_text`. This corrects 8.1.84's Security note, which said an app's own `text_area_*` helpers were covered. No host overrides these.
18
+
19
+ ### Fixed
20
+
21
+ - **The archived-element check runs after the app's own `to_prepare` blocks.** It was the engine's `config.to_prepare`, which runs before the application's, so on a reload in development it did not yet see a vendored element's helpers that the app includes into `InlineFormsHelper` in its own `to_prepare` (yavetracker's `geo_code_curacao`). It is now registered on the app's reloader from `after_initialize` (`InlineForms.validate_loaded_models!`), after the app's blocks. The boot's own first prepare, which ran before eager loading and saw almost no models, is no longer checked; every reload is, as before. This is what 8.1.84's "yavetracker's boot exception can go now" needed: the private-helper fix alone did not change the order.
22
+ - **A values list that mixes numbers and strings works again.** Since 8.1.83 kept numbers as numbers, `[1, 2, "many"]` (or a `nil` entry) raised `ArgumentError: comparison of Array with Array failed` in every element that lists the values (dropdown_with_values, radio_button, scale, slider, check_box, dropdown_with_integers). Numbers now sort as numbers and anything else as text.
23
+
24
+ ### Documentation
25
+
26
+ - **Vendoring an archived element:** `archived/README.md` and the boot check's hint said to put `<name>_update` in an app helper. The save calls it on the controller, which does not get the app's helpers, so such a field showed and edited but every save was refused (400; a 500 before 8.1.84). Include the module into both `InlineFormsHelper` and `InlineFormsController` in a `to_prepare`, as the README now shows (yavetracker already does).
27
+ - **8.1.83, not mentioned then:** a values list given as an integer Range (`0..12`) is in numeric order since 8.1.83 (0, 1, 2 … 12; it was 0, 1, 10, 11, 12, 2 …). yavetracker's `0..40`, `0..7` and `1..8` dropdowns change order.
28
+ - README: the tabs section's `+link_options+` renders as code again.
29
+
30
+ ### Tests
31
+
32
+ - The engine header's logout link is a Turbo DELETE; an `update` override written `super and return` stops after a refusal; `MissingAttributeListError` on a field's show and save, not only on edit.
33
+
34
+ ## [8.1.84] - 2026-11-24
35
+
36
+ From the second RACVS / yavetracker ladder prompt (`ladder/inline_forms-PROMPT-2-2026-11-24.md`).
37
+
38
+ ### Security
39
+
40
+ - **`:rich_text` (and `:text_area`) on a plain column no longer puts the stored HTML on the page as it is.** Without `has_rich_text` the element reads the model's own column, and `rich_text_show` marked that value `html_safe`: a stored `<script>` ran when the field was shown, an `onerror` on load, an `onclick` on a click (confirmed in yavetracker). Such a value is now shown through an allowlist (`InlineForms.rich_text_display_html`): Trix's tags plus the formatting older editors wrote (tables, underline, sub/sup, headings, span), `href` with safe protocols only, and `style` with the sanitizer's safe CSS properties only (no `url()`). The stored value is not changed. An Action Text value is unchanged (Action Text sanitizes it). yavetracker's own `rich_text_show` can go.
41
+ - **`form_element=rich_text` on a `:text_area` row is accepted only while `:text_area` is the engine's own.** An app with its own `text_area_*` helpers (a vendored CKEditor element) could be sent around them to the engine's `rich_text_update`, past whatever the app's update checks.
42
+
43
+ ### Fixed
44
+
45
+ - **A field request for a row that is not a field answers 400.** A listed `:associated` (or `:has_one`) row requested through `show` passed the row check and then raised NoMethodError on `associated_show` (a 500 in RACVS). The check now also asks for the helper the action calls (`<element>_show`, `_edit` or `_update`). The unused `@associated_record` lookup in `show` is gone.
46
+ - **A model without an instance `inline_forms_attribute_list` gets an error that names it** (`InlineForms::MissingAttributeListError`) on a field request, instead of a bare NoMethodError. RACVS's Ouderbrief, Schoolbrief and Vibrief had their rows only in a class-level tab structure. The README's tabs section says what to define.
47
+ - **`show`, `edit` and `update` return true once they have answered, a refusal included.** An app override written `super and return if params[:form_element]` went on after a refused request (400, `nil`) and rendered again: DoubleRenderError, a 500. `return super if …` was and stays the recommended form.
48
+ - **The vendored-element opt-out (8.1.81) sees private helpers.** `InlineForms.vendored_form_element?` asked `respond_to?` without the private flag, so yavetracker's private `geo_code_curacao_show` still needed its own boot exception, which can go now.
49
+ - **The `info` element formats a DateTime.** It formatted only `instance_of?(Date)` and `is_a?(Time)`; a DateTime (a Date subclass) printed `2026-11-24 22:13:13 UTC` (RACVS's client sheet). A Time, TimeWithZone or DateTime now reads as in the versions panel (`24 Nov 2026 22:13`) with how long ago; a Date stays dd-mm-yyyy. **Visible change:** a Time shown by `info` no longer prints its raw `to_s`.
50
+ - **The "Versions (n)" header follows a field save.** The update response carries a `<turbo-stream>` that replaces the open record's versions panel (closed, with the new count). An open versions list closes on a save.
51
+ - **Trix's toolbar wraps** onto a second line instead of scrolling sideways in a narrow value column, and **has no attach button on a plain column**, where nothing can be stored (the editor gets `inline_forms-trix-no-files`).
52
+
53
+ ### Upgrade notes
54
+
55
+ - **Correction to 8.1.81's `:text_area` note.** It is true only with `has_rich_text` on the model. Without it, `:text_area` (delegating to `:rich_text`) reads the model's own column: CKEditor's HTML is shown (through the allowlist above since 8.1.84) and loaded into Trix, and **Trix rewrites it on the next save**: tables, underline, colours, fonts and alignment are lost. Keep such a column read-mostly, declare it `:plain_text_area`, or move the HTML into Action Text as that note says (the same loss happens there, once, when the HTML is first edited in Trix).
56
+ - **Apps made before 8.1.66:** if `app/assets/stylesheets/inline_forms_install/*_main.scss` `@use`s the gem's stylesheet without the `.scss` extension, Dart Sass resolves it to the app's own previous build, and the gem's CSS never changes again. Write the extension (`@use "inline_forms/inline_forms.scss"`), as the installer does since 8.1.66.
57
+ - **`order_by_clause` is not read since 8.1.0.** Replacing it with `inline_forms_list` also re-sorts the model's dropdowns, which follow `inline_forms_list` (RACVS: alphabetical where 8.0 had database order; `inline_forms_dropdown_order :id` puts that back, see 8.1.59), and rows with a NULL in the order column, which 8.0.4 hid through its `LIKE '%%'`, now show.
58
+ - **The attribute list rows lost their label slot at 8.1.0** (`[ :name, "Name", :text_field ]` became `[ :name, :text_field ]`), and the field request check (8.1.76) reads slot 1 as the form element. An app coming up from 8.0 rewrites every row, and any code of its own that reads rows by position, before a field can be edited.
59
+ - **`CanCan::AccessDenied`:** do not add a `format.turbo_stream` branch to the handler; it broke Devise's sign-out in RACVS. The README now shows the installer's handler.
60
+
11
61
  ## [8.1.83] - 2026-11-24
12
62
 
13
63
  From items 13-18 of the RACVS / yavetracker ladder prompt (`ladder/inline_forms-PROMPT-2026-11-24.md`).
data/README.rdoc CHANGED
@@ -257,6 +257,11 @@ Active-tab highlighting is unchanged from upstream (still driven by +set_tab :fo
257
257
 
258
258
  The +--example+ app uses option *2* because the only per-tab difference is which attribute subset to render, and +inline_forms/_show+ already drives off +@inline_forms_attribute_list+ — so a single filter in +OwnersController#show+ is enough and a per-tab partial would be over-engineering. For real apps with heterogeneous tabs, option *4* is usually a better fit; option *5* layers on top of any of the others when you need visual grouping.
259
259
 
260
+ Two rules hold for every pattern:
261
+
262
+ - *The model keeps an instance +inline_forms_attribute_list+ with the rows of every tab.* Each field request (edit, update, a field's show) is checked against the record's list since 8.1.76, not against the tab's +@inline_forms_attribute_list+ of the page that linked to it. A model whose rows live only in a class-level structure raises +InlineForms::MissingAttributeListError+, naming the model; give it e.g. <tt>def inline_forms_attribute_list = @inline_forms_attribute_list ||= self.class.tab_fields.values.flatten(1)</tt>.
263
+ - *A +show+ override hands field requests to the engine with <tt>return super if params[:form_element] || …</tt>*, as above. Since 8.1.84 +show+ returns true after it has answered, a refusal included, so the older <tt>super and return if …</tt> works too; before, a refused request (400) fell through to the override's own render (DoubleRenderError).
264
+
260
265
  In every case the Turbo wiring is the same: +link_options: { data: { turbo_frame: @update_span } }+ on the +<a>+, surrounding +<turbo-frame id="<%= @update_span %>">+ in the show view, and a controller that picks the active tab via +set_tab+ + +params[:tab]+. The +InlineForms::TurboTabsBuilder+ choice is independent of which partial layout you adopt.
261
266
 
262
267
  == Generated application +rails-i18n+
@@ -367,6 +372,10 @@ Once inside the box, goto /vagrant and install_stuff:
367
372
 
368
373
  This should update your box, install rvm and ruby and inline_forms, and create an example app.
369
374
 
375
+ == Handling +CanCan::AccessDenied+
376
+
377
+ The installer's +ApplicationController+ has the handler the engine expects: JSON and JS get a 403, HTML a redirect to the root with the message. A frame request gets that redirect too; Turbo then shows the frame's "content missing", which is the intended signal for a refused field. Do *not* add a <tt>format.turbo_stream</tt> branch: Turbo accepts a stream on a form or <tt>data-turbo-method</tt> request, Devise's sign-out link included, and with that branch the sign-out broke (RACVS tried it and took it out again). The engine has no other recommended handler for frame or stream requests.
378
+
370
379
 
371
380
  == Disclaimer
372
381
 
@@ -573,3 +573,18 @@ turbo-frame {
573
573
  .inline_forms-file-trash-history {
574
574
  opacity: 0.55;
575
575
  }
576
+
577
+ // Trix's toolbar is one row that scrolls sideways when the value column is
578
+ // narrower than it: let the button groups wrap onto a second line instead.
579
+ // The class is doubled to outweigh trix.css, which the layout loads later.
580
+ trix-toolbar .trix-button-row.trix-button-row {
581
+ flex-wrap: wrap;
582
+ overflow-x: visible;
583
+ row-gap: 0.25rem;
584
+ }
585
+
586
+ // A :rich_text on a plain column (no has_rich_text) cannot store an
587
+ // attachment: no attach button there (rich_text_edit sets the class).
588
+ trix-toolbar:has(+ trix-editor.inline_forms-trix-no-files) .trix-button-group--file-tools {
589
+ display: none;
590
+ }
@@ -150,11 +150,12 @@ class InlineFormsController < ApplicationController
150
150
  @form_element = params[:form_element]
151
151
  @sub_id = params[:sub_id]
152
152
  @update_span = params[:update]
153
- return unless field_request_permitted?(:update)
154
- return unless file_replace_permitted?
153
+ return true unless field_request_permitted?(:update)
154
+ return true unless file_replace_permitted?
155
155
  respond_to do |format|
156
156
  format.html { render_turbo_field(:field_edit) }
157
157
  end
158
+ true
158
159
  end
159
160
 
160
161
  # :create creates the object made with :new.
@@ -228,8 +229,8 @@ class InlineFormsController < ApplicationController
228
229
  @form_element = params[:form_element]
229
230
  @sub_id = params[:sub_id]
230
231
  @update_span = params[:update]
231
- return unless field_request_permitted?(:update)
232
- return unless file_replace_permitted?
232
+ return true unless field_request_permitted?(:update)
233
+ return true unless file_replace_permitted?
233
234
  # Defense-in-depth: the UI renders a pending field as a read-only
234
235
  # placeholder (never links to edit/update), but a hand-crafted request
235
236
  # could still target a column that is not migrated yet. Refuse cleanly
@@ -238,7 +239,7 @@ class InlineFormsController < ApplicationController
238
239
  respond_to do |format|
239
240
  format.html { render "inline_forms/field_pending", layout: "turbo_rails/frame", status: :unprocessable_entity }
240
241
  end
241
- return
242
+ return true
242
243
  end
243
244
  InlineForms.assert_plain_text_column!(object: @object, attribute: @attribute, form_element: @form_element)
244
245
  refusals = assign_field(@attribute, @form_element)
@@ -253,6 +254,9 @@ class InlineFormsController < ApplicationController
253
254
  # On failure we keep the user in the edit field with their rejected
254
255
  # input visible and surface the validation errors (mirrors `create`).
255
256
  if refusals.empty? && @object.save
257
+ # The save added a version: the open record's "Versions (n)" header
258
+ # is refreshed with the field (field_show.html.erb).
259
+ @inline_forms_refresh_versions = true
256
260
  respond_to do |format|
257
261
  format.html { render_turbo_field(:field_show, turbo_field_show: true) }
258
262
  end
@@ -262,30 +266,23 @@ class InlineFormsController < ApplicationController
262
266
  format.html { render_turbo_field(:field_edit) }
263
267
  end
264
268
  end
269
+ true
265
270
  end
266
271
 
267
- # :show shows one attribute (attribute) from a record (object).
268
- # It includes the link to 'edit'
272
+ # :show shows one attribute (attribute) from a record (object), with the
273
+ # link to 'edit', or the whole record when no attribute is given.
274
+ #
275
+ # Returns true once it has answered, a refusal (400) included, so an app
276
+ # override written as `super and return if params[:form_element]` stops
277
+ # there instead of rendering a second time (DoubleRenderError).
269
278
  def show
270
279
  @object = referenced_object
271
280
  @attribute = params[:attribute]
272
281
  @form_element = params[:form_element]
273
282
  close = params[:close] || false
274
283
  # Single-field show (cancel link, post-update render): same whitelist as
275
- # edit/update -- the associated/has_one branches below `send` the
276
- # attribute name to the record.
277
- return if @attribute && !field_request_permitted?(:read)
278
- if @form_element == "associated"
279
- @sub_id = params[:sub_id]
280
- if @sub_id.to_i > 0
281
- @associated_record_id = @object.send(@attribute.to_s.singularize + "_ids").index(@sub_id.to_i)
282
- @associated_record = @object.send(@attribute)[@associated_record_id]
283
- end
284
- end
285
- if @form_element == "has_one"
286
- @associated_record = @object.send(@attribute)
287
- @associated_record_id = @associated_record.id
288
- end
284
+ # edit/update.
285
+ return true if @attribute && !field_request_permitted?(:read)
289
286
  @update_span = params[:update]
290
287
  if @attribute.nil?
291
288
  respond_to do |format|
@@ -301,6 +298,7 @@ class InlineFormsController < ApplicationController
301
298
  format.html { render_turbo_field(:field_show, turbo_field_show: true) }
302
299
  end
303
300
  end
301
+ true
304
302
  end
305
303
 
306
304
  # :soft_delete
@@ -472,11 +470,19 @@ class InlineFormsController < ApplicationController
472
470
  # element went straight into `send("#{form_element}_update")`.
473
471
  #
474
472
  # Refuse (400) unless attribute + form_element name a row of the model's
475
- # attribute list (as the UI's links do), then authorize the attribute
476
- # itself. Renders and returns false when the request is refused.
473
+ # attribute list (as the UI's links do) whose form element has the helper
474
+ # this action calls, then authorize the attribute itself. Renders and
475
+ # returns false when the request is refused.
476
+ #
477
+ # A row without that helper is refused too: :associated and :has_one rows
478
+ # are lists, not fields, and have no `<element>_show` (a listed :associated
479
+ # row requested through show raised NoMethodError, a 500). A delegated name (form_element=rich_text on a
480
+ # :text_area row) only counts while the row's element is the engine's own.
477
481
  def field_request_permitted?(action)
478
- attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list
479
- unless InlineForms.attribute_list_row_for(attributes, @attribute, @form_element)
482
+ attributes = @inline_forms_attribute_list || inline_forms_attribute_list_of!(@object)
483
+ row = InlineForms.attribute_list_row_for(attributes, @attribute, @form_element,
484
+ delegate_allowed: ->(declared) { engine_form_element?(declared) })
485
+ unless row && form_element_helper?(@form_element, FIELD_REQUEST_HELPER_SUFFIX.fetch(action_name, "show"))
480
486
  head :bad_request
481
487
  return false
482
488
  end
@@ -484,6 +490,51 @@ class InlineFormsController < ApplicationController
484
490
  true
485
491
  end
486
492
 
493
+ FIELD_REQUEST_HELPER_SUFFIX = { "edit" => "edit", "update" => "update", "show" => "show" }.freeze
494
+ private_constant :FIELD_REQUEST_HELPER_SUFFIX
495
+
496
+ # The record's attribute list, or an error that names the model. Field
497
+ # requests are checked against it (8.1.76); a model whose rows live only in
498
+ # a class-level structure (tabs) raised a bare NoMethodError on every edit.
499
+ def inline_forms_attribute_list_of!(object)
500
+ return object.inline_forms_attribute_list if object.respond_to?(:inline_forms_attribute_list)
501
+
502
+ raise InlineForms::MissingAttributeListError,
503
+ "#{object.class.name} has no instance method inline_forms_attribute_list. Every field " \
504
+ "request (edit, update, a field's show) is checked against it since inline_forms 8.1.76: " \
505
+ "define it on #{object.class.name} and return all rows the UI can show " \
506
+ "(for a model with tabs: the rows of every tab)."
507
+ end
508
+
509
+ # `<form_element>_<suffix>` exists for this request: `_update` is called on
510
+ # the controller (assign_field), `_show` and `_edit` in the view.
511
+ def form_element_helper?(form_element, suffix)
512
+ name = :"#{form_element}_#{suffix}"
513
+ suffix == "update" ? respond_to?(name, true) : helpers.respond_to?(name, true)
514
+ end
515
+
516
+ # The element is the engine's own, not an app's copy of the same name:
517
+ # its _show, _edit and _update, in the view and on the controller, are all
518
+ # defined in the engine's lib/inline_forms/form_elements/. An app that
519
+ # overrides any one of them (only the _update with its own checks, say)
520
+ # keeps the delegate away. By file, not owner: `private` on an included
521
+ # helper (the controller makes them private, 8.1.83) gives a stub whose
522
+ # owner is InlineFormsController but whose source is still the engine's.
523
+ ENGINE_FORM_ELEMENTS_DIR = File.expand_path("../../lib/inline_forms/form_elements", __dir__) + File::SEPARATOR
524
+ private_constant :ENGINE_FORM_ELEMENTS_DIR
525
+
526
+ def engine_form_element?(form_element)
527
+ %w[show edit update].all? do |suffix|
528
+ name = :"#{form_element}_#{suffix}"
529
+ [ helpers, self ].all? do |target|
530
+ !target.respond_to?(name, true) ||
531
+ target.method(name).source_location&.first.to_s.start_with?(ENGINE_FORM_ELEMENTS_DIR)
532
+ end
533
+ end
534
+ rescue NameError
535
+ false
536
+ end
537
+
487
538
  # Uploading over a file that is already in a declared slot is a replace:
488
539
  # the old file goes to the trash, i.e. it is removed. That needs
489
540
  # :replace_file on top of :update (an empty slot only needs :update).
@@ -404,17 +404,24 @@ module InlineFormsHelper
404
404
  values.to_a.each do |k, v|
405
405
  temp << [ k, inline_forms_value_label(v) ]
406
406
  end
407
- values = temp.sort { |a, b| a[0]<=>b[0] }
407
+ values = temp.sort { |a, b| inline_forms_compare_values(a[0], b[0]) }
408
408
  else
409
409
  temp = Array.new
410
410
  values.to_a.each_index do |i|
411
411
  temp << [ i, inline_forms_value_label(values.to_a[i]) ]
412
412
  end
413
- values = temp.sort { |a, b| a[1]<=>b[1] }
413
+ values = temp.sort { |a, b| inline_forms_compare_values(a[1], b[1]) }
414
414
  end
415
415
  values
416
416
  end
417
417
 
418
+ # Numbers in numeric order, anything else as text: a list that mixes
419
+ # numbers and strings ([1, 2, "many"]) raised ArgumentError in 8.1.83,
420
+ # once labels stopped being the strings t() returned.
421
+ def inline_forms_compare_values(a, b)
422
+ (a <=> b) || (a.to_s <=> b.to_s)
423
+ end
424
+
418
425
  # A value as text for the screen: a Date as dd-mm-yyyy (since Rails 7.1 a
419
426
  # bare Date prints ISO), a time as inline_forms_time_text, anything else
420
427
  # as it is. Used by the info elements and the versions panel.
@@ -1,3 +1,14 @@
1
1
  <turbo-frame id="<%= @update_span %>">
2
2
  <%= inline_forms_field_show(@object, @attribute, @form_element, turbo_frame: @turbo_field_show_turbo_frame) %>
3
+ <%# After a save: replace the record's versions panel (closed, with the new
4
+ count). Turbo performs a <turbo-stream> when the frame's content is
5
+ inserted, so the field's frame response can update that other frame. -%>
6
+ <% if @inline_forms_refresh_versions && (cancan_disabled? || can?(:list_versions, @object)) -%>
7
+ <% versions_frame_id = inline_forms_versions_turbo_frame_id(@object) -%>
8
+ <turbo-stream action="replace" target="<%= versions_frame_id %>"><template>
9
+ <turbo-frame id="<%= versions_frame_id %>">
10
+ <%= render "inline_forms/versions", object: @object %>
11
+ </turbo-frame>
12
+ </template></turbo-stream>
13
+ <% end -%>
3
14
  </turbo-frame>
data/archived/README.md CHANGED
@@ -43,11 +43,27 @@ Active form elements load from `app/helpers/form_elements/*.rb` only (top-level
43
43
 
44
44
  An app can keep using an archived element without changing the gem: put its
45
45
  helper methods (`<name>_show`, `<name>_edit`, `<name>_update`, and `_info` if it
46
- has one) in a module under the app's own `app/helpers/`, plus the models,
47
- controllers, views, routes and assets its README lists. Since 8.1.81 the boot
48
- check (`InlineForms.validate_no_archived_form_elements_for!`) skips an archived
46
+ has one) in a module, plus the models, controllers, views, routes and assets
47
+ its README lists. The views call `_show` and `_edit`, but the save calls
48
+ `_update` on the controller, which does not get the app's helpers. So include
49
+ the module into both, in a `to_prepare` (both are reloadable engine
50
+ constants):
51
+
52
+ ```ruby
53
+ # config/initializers/inline_forms_vendored_form_elements.rb
54
+ require Rails.root.join("lib/form_elements/geo_code_curacao").to_s
55
+
56
+ Rails.application.config.to_prepare do
57
+ [InlineFormsHelper, InlineFormsController].each { |target| target.include(GeoCodeCuracaoHelper) }
58
+ end
59
+ ```
60
+
61
+ A module only under `app/helpers/` shows and edits, but every save is refused
62
+ (400). Since 8.1.81 the boot check
63
+ (`InlineForms.validate_no_archived_form_elements_for!`) skips an archived
49
64
  symbol when the app's helpers (`ApplicationController.helpers`) answer
50
- `<name>_show`, so the element is then the app's. The archived files are
65
+ `<name>_show`, so the element is then the app's. Since 8.1.85 that check runs
66
+ after the app's own `to_prepare` blocks, so the include above is seen. The archived files are
51
67
  written in the old top-level `def` style; wrap them in a helper module
52
68
  (`module GeoCodeCuracaoHelper … end`) and replace any jQuery/UJS they use.
53
69
 
@@ -72,7 +72,7 @@ module InlineForms
72
72
 
73
73
  # An app that vendors an archived element (copies its helper into its own
74
74
  # app/helpers, see archived/README.md) defines `<element>_show` itself: the
75
- # element is then the app's, and allowed. `helpers` is the view helper
75
+ # element is then the app's, and allowed. The helper may be private. `helpers` is the view helper
76
76
  # proxy to ask (default: ApplicationController's, with all app helpers).
77
77
  def self.validate_no_archived_form_elements_for!(klass, helpers: nil)
78
78
  return unless klass.instance_methods.include?(:inline_forms_attribute_list)
@@ -85,7 +85,8 @@ module InlineForms
85
85
  meta = ARCHIVED_FORM_ELEMENTS[key]
86
86
  version = meta[:archived_in_version] || meta[:removed_in_version]
87
87
  hint = if meta[:archive_path]
88
- "Vendor it into your app: define #{key}_show (and _edit, _update) in an app helper " \
88
+ "Vendor it into your app: define #{key}_show, _edit and _update in a module and " \
89
+ "include it into InlineFormsHelper and InlineFormsController in a to_prepare " \
89
90
  "(#{meta[:archive_path]}/README.md, archived/README.md)."
90
91
  else
91
92
  "See archived/README.md and CHANGELOG #{version}."
@@ -99,7 +100,7 @@ module InlineForms
99
100
 
100
101
  def self.vendored_form_element?(key, helpers = nil)
101
102
  helpers ||= ::ApplicationController.helpers if defined?(::ApplicationController)
102
- !!helpers&.respond_to?(:"#{key}_show")
103
+ !!helpers&.respond_to?(:"#{key}_show", true)
103
104
  rescue StandardError
104
105
  false
105
106
  end
@@ -21,7 +21,12 @@ module InlineForms
21
21
  # when +attribute+/+form_element+ (both from params) do not name a row the
22
22
  # UI could have linked to. The controller uses this as a whitelist before
23
23
  # it dispatches +send("#{form_element}_update")+ or touches the attribute.
24
- def self.attribute_list_row_for(attribute_list, attribute, form_element)
24
+ #
25
+ # A delegate's name (+rich_text+ on a +:text_area+ row) is accepted only
26
+ # when +delegate_allowed+ says so for the declared element: the controller
27
+ # refuses it when the app has its own +text_area_*+, which the engine's
28
+ # +rich_text_update+ would otherwise bypass.
29
+ def self.attribute_list_row_for(attribute_list, attribute, form_element, delegate_allowed: nil)
25
30
  attribute = attribute.to_s
26
31
  form_element = form_element.to_s
27
32
  return nil if attribute.empty? || form_element.empty?
@@ -29,8 +34,10 @@ module InlineForms
29
34
  attribute_list.find do |listed_attribute, declared, *|
30
35
  next false unless listed_attribute.to_s == attribute
31
36
 
32
- declared.to_s == form_element ||
33
- FORM_ELEMENT_DELEGATES[declared.to_s.to_sym].to_s == form_element
37
+ next true if declared.to_s == form_element
38
+
39
+ FORM_ELEMENT_DELEGATES[declared.to_s.to_sym].to_s == form_element &&
40
+ (delegate_allowed.nil? || delegate_allowed.call(declared))
34
41
  end
35
42
  end
36
43
  end
@@ -8,20 +8,30 @@ module InlineForms
8
8
  def info_show(object, attribute)
9
9
  # show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
10
10
  o = object.send(attribute)
11
- o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
12
- o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
11
+ o = info_time_or_date_text(o)
13
12
  o = o._presentation if o.respond_to?(:_presentation)
14
13
  o
15
14
  end
16
15
 
17
16
  def info_edit(object, attribute)
18
17
  o = object.send(attribute)
19
- o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
20
- o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
18
+ o = info_time_or_date_text(o)
21
19
  o = o._presentation if o.respond_to?(:_presentation)
22
20
  o
23
21
  end
24
22
 
23
+ # A time (Time, TimeWithZone or DateTime) as the versions panel shows it,
24
+ # with how long ago; a Date as dd-mm-yyyy. A DateTime used to print raw
25
+ # ("2026-11-24 22:13:13 UTC"): it is a Date, not a Time.
26
+ def info_time_or_date_text(o)
27
+ case o
28
+ when Time, DateTime, ActiveSupport::TimeWithZone
29
+ "#{inline_forms_time_text(o)} (#{distance_of_time_in_words_to_now(o)})"
30
+ when Date then o.strftime(InlineForms::DATE_FORMAT)
31
+ else o
32
+ end
33
+ end
34
+
25
35
  def info_update(object, attribute)
26
36
  # do absolutely nothing
27
37
  end
@@ -29,8 +39,7 @@ module InlineForms
29
39
  def info_info(object, attribute)
30
40
  # show the attribute. if it's a date/time, make it nicer. If it has a _presentation, show that instead
31
41
  o = object.send(attribute)
32
- o = o.to_s + " (" + distance_of_time_in_words_to_now(o) + ")" if o.is_a?(Time)
33
- o = o.strftime(InlineForms::DATE_FORMAT) if o.instance_of?(Date)
42
+ o = info_time_or_date_text(o)
34
43
  o = o._presentation if o.respond_to?(:_presentation)
35
44
  o
36
45
  end
@@ -11,7 +11,16 @@ module InlineForms
11
11
  rich.nil? ||
12
12
  (rich.respond_to?(:blank?) && rich.blank?) ||
13
13
  (rich.respond_to?(:to_plain_text) && rich.to_plain_text.to_s.strip.empty?)
14
- display_value = is_blank ? "<i class='fi-plus'></i>".html_safe : rich.to_s.html_safe
14
+ # A plain column's HTML goes through the display allowlist; Action Text
15
+ # sanitizes its own (InlineForms.rich_text_display_html).
16
+ display_value =
17
+ if is_blank
18
+ "<i class='fi-plus'></i>".html_safe
19
+ elsif rich.is_a?(String)
20
+ InlineForms.rich_text_display_html(rich)
21
+ else
22
+ rich.to_s.html_safe
23
+ end
15
24
  link_to_inline_edit object, attribute, display_value, from_callee: __callee__
16
25
  end
17
26
 
@@ -26,8 +35,12 @@ module InlineForms
26
35
  ''
27
36
  end
28
37
  input_id = "trix_input_#{object.class.name.underscore}_#{object.id || 'new'}_#{attribute}"
38
+ # A plain column (no has_rich_text) cannot hold attachments: the class
39
+ # hides Trix's attach button there.
40
+ classes = 'trix-content attribute_rich_text_area'
41
+ classes += ' inline_forms-trix-no-files' unless rich.respond_to?(:body)
29
42
  hidden_field_tag(attribute, body, id: input_id) +
30
- content_tag(:'trix-editor', ''.html_safe, input: input_id, class: 'trix-content attribute_rich_text_area')
43
+ content_tag(:'trix-editor', ''.html_safe, input: input_id, class: classes)
31
44
  end
32
45
 
33
46
  def rich_text_update(object, attribute)
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module InlineForms
4
- VERSION = "8.1.83"
4
+ VERSION = "8.1.85"
5
5
  end
data/lib/inline_forms.rb CHANGED
@@ -22,6 +22,38 @@ require "inline_forms/turbo_tabs_builder"
22
22
  # easy. Please install it as a gem or include it in your Gemfile.
23
23
  module InlineForms
24
24
  class PlainTextColumnMissingError < StandardError; end
25
+ # A model without an instance inline_forms_attribute_list got a field
26
+ # request (edit, update, a field's show); the message names the model.
27
+ class MissingAttributeListError < StandardError; end
28
+
29
+ # ---- :rich_text on a plain column ----------------------------------------
30
+ #
31
+ # :rich_text (and :text_area, which delegates to it) on a model without
32
+ # has_rich_text reads the model's own text column. That HTML was put on the
33
+ # page as it was stored (CKEditor's, or anything posted around the editor):
34
+ # a <script>, an onerror or a javascript: link in it ran. It is shown through
35
+ # this allowlist now: Trix's tags plus the formatting older editors wrote
36
+ # (tables, underline, sub/sup, h2-h6, span), and their attributes. `style`
37
+ # keeps only the sanitizer's safe CSS properties (never url() or
38
+ # expression()); href keeps only safe protocols. The stored value is not
39
+ # changed. An Action Text value is not passed through here: Action Text
40
+ # sanitizes it itself.
41
+ RICH_TEXT_DISPLAY_TAGS = %w[
42
+ a b strong i em u s strike del ins sub sup small big
43
+ p div span br hr blockquote pre code
44
+ h1 h2 h3 h4 h5 h6 ul ol li dl dt dd
45
+ table thead tbody tfoot tr th td caption colgroup col
46
+ figure figcaption
47
+ ].freeze
48
+ RICH_TEXT_DISPLAY_ATTRIBUTES = %w[
49
+ href title style align valign width border cellpadding cellspacing colspan rowspan
50
+ ].freeze
51
+
52
+ def self.rich_text_display_html(html)
53
+ Rails::HTML::Sanitizer.best_supported_vendor.safe_list_sanitizer.new.sanitize(
54
+ html.to_s, tags: RICH_TEXT_DISPLAY_TAGS, attributes: RICH_TEXT_DISPLAY_ATTRIBUTES
55
+ ).to_s.html_safe
56
+ end
25
57
 
26
58
  # ---- File slots and the file trash (InlineForms::StoredFiles) ------------
27
59
  #
@@ -307,6 +339,24 @@ module InlineForms
307
339
  attribute.to_s
308
340
  end
309
341
 
342
+ # Every loaded model's attribute list: no archived element the app has not
343
+ # vendored, and plain_text columns present. Run on every reload, after the
344
+ # app's own to_prepare blocks (see the engine).
345
+ def self.validate_loaded_models!
346
+ return unless defined?(ActiveRecord::Base)
347
+
348
+ ActiveRecord::Base.descendants.each do |klass|
349
+ validate_no_archived_form_elements_for!(klass)
350
+ validate_plain_text_configuration_for!(klass)
351
+ rescue PlainTextColumnMissingError, ArchivedFormElementError
352
+ raise
353
+ rescue StandardError
354
+ # Some descendants might be abstract or temporarily unresolved while
355
+ # the app boots/reloads; runtime checks in controllers still enforce
356
+ # plain_text column presence for active resources.
357
+ end
358
+ end
359
+
310
360
  def self.validate_plain_text_configuration_for!(klass)
311
361
  return unless klass.respond_to?(:table_exists?) &&
312
362
  klass.respond_to?(:column_names) &&
@@ -434,21 +484,18 @@ module InlineForms
434
484
  ]
435
485
  end
436
486
 
437
- config.to_prepare do
438
- next unless defined?(ActiveRecord::Base)
439
-
440
- ActiveRecord::Base.descendants.each do |klass|
441
- begin
442
- InlineForms.validate_no_archived_form_elements_for!(klass)
443
- InlineForms.validate_plain_text_configuration_for!(klass)
444
- rescue InlineForms::PlainTextColumnMissingError, InlineForms::ArchivedFormElementError
445
- raise
446
- rescue StandardError
447
- # Some descendants might be abstract or temporarily unresolved while
448
- # the app boots/reloads; runtime checks in controllers still enforce
449
- # plain_text column presence for active resources.
450
- end
451
- end
487
+ # The checks of the loaded models run after the app's own to_prepare
488
+ # blocks (8.1.85): an app that includes a vendored element's helpers into
489
+ # InlineFormsHelper in its config/initializers' to_prepare must have done
490
+ # so before the archived-element check asks for <name>_show. A plain
491
+ # config.to_prepare here ran first, before the app's (engine blocks are
492
+ # registered before the application's), so on a reload in development
493
+ # the check did not see the app's helper. Registered from after_initialize,
494
+ # so it lands after the app's blocks; it then runs on every reload, as
495
+ # before. (The boot's own first prepare, before eager loading, saw almost
496
+ # no models; it is no longer checked.)
497
+ config.after_initialize do |app|
498
+ app.reloader.to_prepare { InlineForms.validate_loaded_models! }
452
499
  end
453
500
 
454
501
  # .rb too: inline_forms_titles.rb holds the title keys as lambdas.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.83
4
+ version: 8.1.85
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares