inline_forms 8.1.83 → 8.1.84
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/CHANGELOG.md +27 -0
- data/README.rdoc +10 -1
- data/app/assets/stylesheets/inline_forms/inline_forms.scss +15 -0
- data/app/controllers/inline_forms_controller.rb +63 -25
- data/app/views/inline_forms/field_show.html.erb +11 -0
- data/lib/inline_forms/archived_form_elements.rb +2 -2
- data/lib/inline_forms/form_element_from_callee.rb +10 -3
- data/lib/inline_forms/form_elements/info_helper.rb +15 -6
- data/lib/inline_forms/form_elements/rich_text_helper.rb +15 -2
- data/lib/inline_forms/version.rb +1 -1
- data/lib/inline_forms.rb +32 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1d75751950448c427cecf87e64fe3e4dc6c59b3801ebe8724a15312d26c2a34b
|
|
4
|
+
data.tar.gz: 6c35978ef33487025fec7cfaa4cbc7d6b52e27c03098b2150d3e278c40d614f1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9afef54387ecf3129c658133c00efdd78a7c1ea35b22ff54c59dd19b26824a87c92d48f79061c9409f2b2abe3ab74ee75c471b6ad7ac3699732047afcf0503dc
|
|
7
|
+
data.tar.gz: d8379842ec2f9e052ba7984921457598d45b05b596d779dd31f6df3883f3ccdfb2dbdf9859a9028364ea0c08b70421f1d30f66a33b8069b584b6f886fac84096
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,33 @@ 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.84] - 2026-11-24
|
|
12
|
+
|
|
13
|
+
From the second RACVS / yavetracker ladder prompt (`ladder/inline_forms-PROMPT-2-2026-11-24.md`).
|
|
14
|
+
|
|
15
|
+
### Security
|
|
16
|
+
|
|
17
|
+
- **`: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.
|
|
18
|
+
- **`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.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **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.
|
|
23
|
+
- **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.
|
|
24
|
+
- **`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.
|
|
25
|
+
- **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.
|
|
26
|
+
- **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`.
|
|
27
|
+
- **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.
|
|
28
|
+
- **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`).
|
|
29
|
+
|
|
30
|
+
### Upgrade notes
|
|
31
|
+
|
|
32
|
+
- **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).
|
|
33
|
+
- **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.
|
|
34
|
+
- **`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.
|
|
35
|
+
- **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.
|
|
36
|
+
- **`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.
|
|
37
|
+
|
|
11
38
|
## [8.1.83] - 2026-11-24
|
|
12
39
|
|
|
13
40
|
From items 13-18 of the RACVS / yavetracker ladder prompt (`ladder/inline_forms-PROMPT-2026-11-24.md`).
|
data/README.rdoc
CHANGED
|
@@ -257,7 +257,12 @@ 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
|
-
|
|
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
|
+
|
|
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+
|
|
263
268
|
|
|
@@ -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
|
-
#
|
|
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
|
|
276
|
-
|
|
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)
|
|
476
|
-
#
|
|
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
|
|
479
|
-
|
|
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,38 @@ 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's show helper is the engine's own, not an app's vendored copy
|
|
517
|
+
# of the same name (InlineForms::FormElements::*).
|
|
518
|
+
def engine_form_element?(form_element)
|
|
519
|
+
owner = helpers.method(:"#{form_element}_show").owner
|
|
520
|
+
owner.name.to_s.start_with?("InlineForms::FormElements::")
|
|
521
|
+
rescue NameError
|
|
522
|
+
false
|
|
523
|
+
end
|
|
524
|
+
|
|
487
525
|
# Uploading over a file that is already in a declared slot is a replace:
|
|
488
526
|
# the old file goes to the trash, i.e. it is removed. That needs
|
|
489
527
|
# :replace_file on top of :update (an empty slot only needs :update).
|
|
@@ -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>
|
|
@@ -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)
|
|
@@ -99,7 +99,7 @@ module InlineForms
|
|
|
99
99
|
|
|
100
100
|
def self.vendored_form_element?(key, helpers = nil)
|
|
101
101
|
helpers ||= ::ApplicationController.helpers if defined?(::ApplicationController)
|
|
102
|
-
!!helpers&.respond_to?(:"#{key}_show")
|
|
102
|
+
!!helpers&.respond_to?(:"#{key}_show", true)
|
|
103
103
|
rescue StandardError
|
|
104
104
|
false
|
|
105
105
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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:
|
|
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)
|
data/lib/inline_forms/version.rb
CHANGED
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
|
#
|