inline_forms 8.1.75 → 8.1.78
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 +56 -1
- data/README.rdoc +1 -1
- data/app/assets/stylesheets/inline_forms/inline_forms.scss +3 -1
- data/app/controllers/inline_forms_controller.rb +61 -14
- data/app/views/inline_forms/_header.html.erb +1 -1
- data/app/views/inline_forms/row_close.html.erb +5 -0
- data/inline_forms.gemspec +0 -1
- data/lib/generators/USAGE +1 -1
- data/lib/generators/inline_forms_addto/USAGE +1 -1
- data/lib/generators/inline_forms_addto_generator.rb +30 -139
- data/lib/generators/inline_forms_attribute_list_editor.rb +211 -0
- data/lib/generators/inline_forms_attribute_overrides.rb +9 -0
- data/lib/generators/inline_forms_generator.rb +16 -35
- data/lib/inline_forms/form_elements/check_list_helper.rb +22 -6
- data/lib/inline_forms/form_elements/dropdown_helper.rb +22 -8
- data/lib/inline_forms/gem_files.rb +20 -17
- data/lib/inline_forms/refused_values.rb +33 -0
- data/lib/inline_forms/version.rb +1 -1
- data/lib/inline_forms.rb +10 -0
- data/lib/locales/inline_forms.en.yml +2 -0
- data/lib/locales/inline_forms.nl.yml +2 -0
- metadata +4 -142
- data/.document +0 -5
- data/.forgejo/brakeman-engine.sh +0 -51
- data/.forgejo/brakeman.ignore +0 -211
- data/.forgejo/workflows/ci.yml +0 -74
- data/.forgejo/workflows/full-gate.yml +0 -104
- data/.gitignore +0 -39
- data/.rubocop.yml +0 -31
- data/.rubocop_todo.yml +0 -151
- data/.ruby-version +0 -1
- data/Gemfile +0 -28
- data/Rakefile +0 -103
- data/script/migrate_form_elements.rb +0 -62
- data/test/archived_form_elements_test.rb +0 -101
- data/test/attribute_list_test.rb +0 -165
- data/test/dummy/app/controllers/application_controller.rb +0 -32
- data/test/dummy/app/controllers/daily_reports_controller.rb +0 -4
- data/test/dummy/app/controllers/documents_controller.rb +0 -4
- data/test/dummy/app/controllers/dossiers_controller.rb +0 -4
- data/test/dummy/app/controllers/gizmos_controller.rb +0 -4
- data/test/dummy/app/controllers/machines_controller.rb +0 -4
- data/test/dummy/app/controllers/parts_controller.rb +0 -4
- data/test/dummy/app/controllers/stats_controller.rb +0 -10
- data/test/dummy/app/controllers/widgets_controller.rb +0 -4
- data/test/dummy/app/helpers/application_helper.rb +0 -13
- data/test/dummy/app/models/ability.rb +0 -15
- data/test/dummy/app/models/application_record.rb +0 -27
- data/test/dummy/app/models/daily_report.rb +0 -21
- data/test/dummy/app/models/document.rb +0 -33
- data/test/dummy/app/models/dossier.rb +0 -38
- data/test/dummy/app/models/gizmo.rb +0 -25
- data/test/dummy/app/models/kind.rb +0 -8
- data/test/dummy/app/models/machine.rb +0 -24
- data/test/dummy/app/models/part.rb +0 -17
- data/test/dummy/app/models/phase.rb +0 -9
- data/test/dummy/app/models/widget.rb +0 -40
- data/test/dummy/app/views/_gizmos_search.html.erb +0 -3
- data/test/dummy/app/views/stats/show.html.erb +0 -1
- data/test/dummy/config/application.rb +0 -49
- data/test/dummy/config/database.yml +0 -3
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/initializers/inline_forms.rb +0 -6
- data/test/dummy/config/initializers/paper_trail_yaml_safe_load.rb +0 -28
- data/test/dummy/config/routes.rb +0 -51
- data/test/form_element_from_callee_test.rb +0 -73
- data/test/gem_package_modes_test.rb +0 -86
- data/test/inline_edit_polymorphic_path_test.rb +0 -81
- data/test/inline_forms_addto_generator_test.rb +0 -584
- data/test/inline_forms_generator_test.rb +0 -301
- data/test/integration/csp_nonce_test.rb +0 -50
- data/test/integration/dropdown_test.rb +0 -186
- data/test/integration/field_authorization_test.rb +0 -131
- data/test/integration/file_slots_test.rb +0 -665
- data/test/integration/html_refusal_test.rb +0 -152
- data/test/integration/inline_forms_crud_test.rb +0 -165
- data/test/integration/layout_title_test.rb +0 -56
- data/test/integration/legacy_elements_test.rb +0 -99
- data/test/integration/list_params_test.rb +0 -200
- data/test/integration/locale_test.rb +0 -234
- data/test/integration/model_top_bar_test.rb +0 -85
- data/test/integration/native_inputs_test.rb +0 -138
- data/test/integration/open_after_create_test.rb +0 -85
- data/test/integration/pending_migration_gate_test.rb +0 -75
- data/test/integration/presentation_escaping_test.rb +0 -80
- data/test/integration/revert_skipped_columns_test.rb +0 -59
- data/test/integration/schema_batch_pipeline_test.rb +0 -189
- data/test/integration/schema_edit_test.rb +0 -141
- data/test/integration/schema_preview_test.rb +0 -65
- data/test/integration/turbo_menu_test.rb +0 -60
- data/test/integration_test_helper.rb +0 -203
- data/test/plain_text_configuration_test.rb +0 -90
- data/test/schema_apply_test.rb +0 -73
- data/test/schema_intent_test.rb +0 -53
- data/test/schema_label_test.rb +0 -61
- data/test/tabs_test.rb +0 -98
- data/test/test_helper.rb +0 -10
- data/test/user_model_config_test.rb +0 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e67cd418b32c04cdfab71c7194f85cd74d29ab2a72318c73b625fc8e358d7ca2
|
|
4
|
+
data.tar.gz: a4f42e8e906151206666250f4ab9d53c6de4cac35fa8c81e95c9b3acc242d342
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01a5bdea6611e9010034ac25d4fdfa33a2d4c0e662cb26c84651c1d93a5b8fe12f66f73c5beba71069363958186c3bf9e66b3498c6f65f6ff51b42a8cc9cd554
|
|
7
|
+
data.tar.gz: 616387f11d98b8be25d5c2628c7c636502b6328ecf3ae2d5f721321138c6300b37efe21ed382353631c3fa5bc8ca649959ddc03941ecc3ee92d046fd5a9b343a
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,61 @@ 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.78] - 2026-11-22
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- **Installer: one superadmin, user 1, from the start.** A new app gets the rule the apps on inline_forms already follow:
|
|
16
|
+
- The concern `SingleSuperadmin` (`app/models/concerns/single_superadmin.rb`): `superadmin?` is true only for user 1 holding the role "superadmin". `role?` asks by name and is false without roles.
|
|
17
|
+
- Refused with a message, in the model: giving the role to anybody but user 1 (from the user's roles and from the role's users), taking it from user 1, destroying user 1 (or soft-deleting it, in a model with `InlineForms::SoftDeletable`), renaming or destroying the "superadmin" role. The messages are in `config/locales/single_superadmin.en.yml` and `.nl.yml`.
|
|
18
|
+
- `Ability` asks `superadmin?`. At its end nobody else may change user 1 or see the role, and nobody destroys or soft-deletes user 1.
|
|
19
|
+
- Tests: `test/test_helpers/the_superadmin.rb` makes user 1 (`TheSuperadmin.user`, `the_superadmin`) and `test/models/single_superadmin_test.rb` tests the rule. The example app's tests sign in as user 1 and check the messages on the screen.
|
|
20
|
+
- The role name "superadmin" is reserved: no other role is created with it or renamed to it, in any case. Role names are unique regardless of case.
|
|
21
|
+
- Apps made before keep what they have.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **A create refused by an association callback answers 422,** as the apps' own handlers for it did. Since 8.1.77 the engine shows the refusal itself, and a host's `rescue_from` for it no longer runs. A failed validation still answers 200.
|
|
26
|
+
- **`dropdown` refuses an option it shows disabled** (`disabled_for_dropdown?`), unless the record already has it.
|
|
27
|
+
- A refused dropdown value no longer shows two messages when the model's own message is on the foreign key (`phase_id`) instead of the association.
|
|
28
|
+
|
|
29
|
+
## [8.1.77] - 2026-11-22
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- **`dropdown` and `check_list` accept only the records they offer** (`accessible_by`, for a check list with the `inline_forms_list` filter). Before, any posted id was written, so hiding an option did not refuse it. A posted id that was not offered makes the record invalid and the field or new form shows why: the model's own message for that attribute, else "is not included in the list". The value a record already has may stay. `dropdown_with_other`, which looks its record up by name, is not changed.
|
|
34
|
+
- **`check_list` leaves the records it did not offer.** Saving used to remove every record the user was not shown.
|
|
35
|
+
- **The app's `User#superadmin?` decides,** where it has one: destroy, revert and the header's menu ask `InlineForms.superadmin?`, which falls back to `role?(:superadmin)`.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- **A refused destroy, soft delete or soft restore says so.** The result was ignored: a refused destroy showed the undo button of a deleted record. The row now stays, with the record's errors (or "Could not delete" / "Could not restore", new keys `inline_forms.view.destroy_failed` and `restore_failed`), as a 422.
|
|
40
|
+
- **An association callback may refuse.** A `before_add` / `before_remove` that raises `ActiveRecord::RecordInvalid` or `RecordNotSaved` was a 500; create and update now show the errors in the form, as for a failed validation.
|
|
41
|
+
|
|
42
|
+
## [8.1.76] - 2026-11-22
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- **`inline_forms_addto` no longer breaks a model's list.** Since 8.1.72 it could write a syntax error: no comma before a splat or a conditional row, none after a line with two rows, and one in the middle of `[ ... ].freeze`, a conditional row or a label with `]`. It also put a new row inside a last row of several lines (since before 8.1.72). The list is now found with Ruby's own parser (`InlineForms::AttributeListEditor`), the result is parsed again before it is written, and what cannot be placed leaves the list alone and prints the row to add by hand. The schema editor uses the same code.
|
|
47
|
+
- **`inline_forms_addto` writes precision and scale of a `decimal_field`,** 10,2 unless given as `{p,s}`, as `rails g inline_forms` does. Without them MySQL makes the column decimal(10,0) and drops the decimals. Columns that were added before are not changed.
|
|
48
|
+
- `rails g inline_forms` adds the model to `MODEL_TABS` when its name is only part of another one (`showcases` next to `form_element_showcases`).
|
|
49
|
+
- With `--allow-unknown`, the commented-out rows can be uncommented without adding a comma, and they and the commented-out columns are indented (RuboCop reported them). Columns in an addto migration are indented four spaces, not five.
|
|
50
|
+
- **Installer: an app pins a Ruby that is there.** `.ruby-version` gets the Ruby that runs the installer when 4.0.10 is not it and RVM does not have 4.0.10 (a warning says so when that Ruby is older).
|
|
51
|
+
- Installer: the Unicorn and Capistrano files no longer use figaro, which is not in the Gemfile, so Unicorn did not start. `DEPLOY_DIRECTORY` has to be in the environment.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- **Installer: no `.github/` in generated apps** (`rails new --skip-ci`): GitHub runs nothing. `bin/ci` and `config/ci.rb` stay.
|
|
56
|
+
- Installer: `bin/brakeman` no longer has `--ensure-latest`, which fails as soon as a newer Brakeman is released than the one in the app's lockfile.
|
|
57
|
+
- The gem packages only what an installed gem needs: `app`, `archived`, `lib`, `vendor/assets` and the documents. Tests, `script/`, `.forgejo/`, RuboCop and Ruby version files, `Gemfile` and `Rakefile` are left out.
|
|
58
|
+
- Installer: `brakeman`, `bundler-audit` and `rubocop-rails-omakase` are in the development group only. In the test group too, the generated Dockerfile put them in the production image.
|
|
59
|
+
- The example app's tests check that `bin/rubocop` starts, not that it finds nothing: a new RuboCop rule could make `inline_forms create --example` fail. The full gate runs `bin/ci` instead.
|
|
60
|
+
|
|
61
|
+
### CI
|
|
62
|
+
|
|
63
|
+
- The full gate runs the generated app's `bin/ci`, and pins Brakeman to the version `.forgejo/brakeman.ignore` was made with.
|
|
64
|
+
- The engine scan skips only `config/credentials*` and `config/*.key`, not app code with such a name.
|
|
65
|
+
|
|
11
66
|
## [8.1.75] - 2026-11-22
|
|
12
67
|
|
|
13
68
|
### Removed
|
|
@@ -22,7 +77,7 @@ All notable changes to this project are documented in this file.
|
|
|
22
77
|
|
|
23
78
|
### Fixed
|
|
24
79
|
|
|
25
|
-
- **Installer: the users/roles join table migration rolls back.** Its `down` said `drop_table roles_users`, without the colon, and raised `NoMethodError`. An existing app can correct that line in its own `db/migrate/*_inline_forms_create_join_table_*_role.rb`.
|
|
80
|
+
- **Installer: the users/roles join table migration rolls back.** Its `down` said `drop_table roles_users`, without the colon, and raised `NoMethodError`. An existing app can correct that line in its own `db/migrate/*_inline_forms_create_join_table_*_role.rb`. Look for it in other migrations too (`grep -rn 'drop_table [a-z]' db/migrate`): one copied from this template has to drop its own table, so do not just add the colon there.
|
|
26
81
|
|
|
27
82
|
### Tests
|
|
28
83
|
|
data/README.rdoc
CHANGED
|
@@ -4,7 +4,7 @@ Inline Forms is almost a complete admin application. You can try it out easily.
|
|
|
4
4
|
|
|
5
5
|
= Requirements
|
|
6
6
|
|
|
7
|
-
* Ruby **>= 4.0** (generated apps pin **4.0.10** via +.ruby-version
|
|
7
|
+
* Ruby **>= 4.0** (generated apps pin **4.0.10** via +.ruby-version+, or the Ruby that runs the installer when 4.0.10 is not installed)
|
|
8
8
|
* Rails **8.1.x**, at least **8.1.4.1** (+rails ~> 8.1+, +config.load_defaults 8.1+)
|
|
9
9
|
* **validation_hints** **~> 8** (companion gem; same version line as +inline_forms+ / +inline_forms_installer+)
|
|
10
10
|
|
|
@@ -503,7 +503,9 @@ turbo-frame {
|
|
|
503
503
|
|
|
504
504
|
// Inline-edit validation feedback (flash.now[:error] on failed field save).
|
|
505
505
|
// Shown in field_edit only; _edit deliberately skips flash to avoid session notices.
|
|
506
|
-
.
|
|
506
|
+
// _row_error: a refused destroy / soft delete / restore, above the closed row.
|
|
507
|
+
.inline_forms_field_error,
|
|
508
|
+
.inline_forms_row_error {
|
|
507
509
|
font-size: 100%;
|
|
508
510
|
font-weight: normal;
|
|
509
511
|
line-height: 1.3;
|
|
@@ -153,6 +153,7 @@ class InlineFormsController < ApplicationController
|
|
|
153
153
|
return head :bad_request unless html_list_flow_allowed?
|
|
154
154
|
|
|
155
155
|
attributes = @inline_forms_attribute_list || @object.inline_forms_attribute_list
|
|
156
|
+
refusals = []
|
|
156
157
|
attributes.each do | attribute, form_element |
|
|
157
158
|
# Skip a row whose column is not migrated yet (model edited, migration
|
|
158
159
|
# not run). Writing it would raise; the new form shows it as a pending
|
|
@@ -160,7 +161,9 @@ class InlineFormsController < ApplicationController
|
|
|
160
161
|
next if InlineForms.attribute_pending_migration?(@object, attribute, form_element)
|
|
161
162
|
|
|
162
163
|
InlineForms.assert_plain_text_column!(object: @object, attribute: attribute, form_element: form_element)
|
|
163
|
-
|
|
164
|
+
next if form_element == :associated || (cancan_enabled? && cannot?(:read, @object, attribute))
|
|
165
|
+
|
|
166
|
+
refusals.concat(assign_field(attribute, form_element))
|
|
164
167
|
end
|
|
165
168
|
@parent_id = params[:parent_id]
|
|
166
169
|
# See #index for the order/search/parent-fk decomposition.
|
|
@@ -171,7 +174,7 @@ class InlineFormsController < ApplicationController
|
|
|
171
174
|
@object[foreign_key] = @parent_id
|
|
172
175
|
end
|
|
173
176
|
|
|
174
|
-
if @object.save
|
|
177
|
+
if refusals.empty? && @object.save
|
|
175
178
|
flash.now[:success] = t("success", message: @object.class.model_name.human)
|
|
176
179
|
@objects = cancan_enabled? ? @Klass.accessible_by(current_ability) : @Klass.all
|
|
177
180
|
@objects = @objects.merge(@Klass.inline_forms_list) if @Klass.respond_to?(:inline_forms_list)
|
|
@@ -190,10 +193,15 @@ class InlineFormsController < ApplicationController
|
|
|
190
193
|
end
|
|
191
194
|
else
|
|
192
195
|
flash.now[:header] = [ t("inline_forms.view.create_failed", model: @object.class.model_name.human) ]
|
|
193
|
-
flash.now[:error] = @object.errors.to_a
|
|
196
|
+
flash.now[:error] = refusals.presence || @object.errors.to_a
|
|
194
197
|
respond_to do |format|
|
|
195
198
|
@object.inline_forms_attribute_list = attributes
|
|
196
|
-
|
|
199
|
+
# A refusal answers 422, as the hosts' own handlers for it did before
|
|
200
|
+
# the engine rescued it; a failed validation keeps its 200.
|
|
201
|
+
format.html do
|
|
202
|
+
render_turbo_new
|
|
203
|
+
response.status = :unprocessable_entity if refusals.any?
|
|
204
|
+
end
|
|
197
205
|
end
|
|
198
206
|
end
|
|
199
207
|
end
|
|
@@ -218,7 +226,7 @@ class InlineFormsController < ApplicationController
|
|
|
218
226
|
return
|
|
219
227
|
end
|
|
220
228
|
InlineForms.assert_plain_text_column!(object: @object, attribute: @attribute, form_element: @form_element)
|
|
221
|
-
|
|
229
|
+
refusals = assign_field(@attribute, @form_element)
|
|
222
230
|
# Branch on the actual save result. Previously the return value of
|
|
223
231
|
# `@object.save` was ignored and `field_show` was rendered
|
|
224
232
|
# unconditionally from the in-memory `@object`. When a save failed
|
|
@@ -229,12 +237,12 @@ class InlineFormsController < ApplicationController
|
|
|
229
237
|
#
|
|
230
238
|
# On failure we keep the user in the edit field with their rejected
|
|
231
239
|
# input visible and surface the validation errors (mirrors `create`).
|
|
232
|
-
if @object.save
|
|
240
|
+
if refusals.empty? && @object.save
|
|
233
241
|
respond_to do |format|
|
|
234
242
|
format.html { render_turbo_field(:field_show, turbo_field_show: true) }
|
|
235
243
|
end
|
|
236
244
|
else
|
|
237
|
-
flash.now[:error] = @object.errors.to_a
|
|
245
|
+
flash.now[:error] = refusals.presence || @object.errors.to_a
|
|
238
246
|
respond_to do |format|
|
|
239
247
|
format.html { render_turbo_field(:field_edit) }
|
|
240
248
|
end
|
|
@@ -286,7 +294,8 @@ class InlineFormsController < ApplicationController
|
|
|
286
294
|
@object = referenced_object
|
|
287
295
|
return head :bad_request unless row_html_turbo_allowed?
|
|
288
296
|
|
|
289
|
-
@object.soft_delete(current_user)
|
|
297
|
+
return render_row_refused("inline_forms.view.destroy_failed") if @object.soft_delete(current_user) == false
|
|
298
|
+
|
|
290
299
|
respond_to do |format|
|
|
291
300
|
format.html { render_row_turbo(:close) }
|
|
292
301
|
end
|
|
@@ -298,7 +307,8 @@ class InlineFormsController < ApplicationController
|
|
|
298
307
|
@object = referenced_object
|
|
299
308
|
return head :bad_request unless row_html_turbo_allowed?
|
|
300
309
|
|
|
301
|
-
@object.soft_restore
|
|
310
|
+
return render_row_refused("inline_forms.view.restore_failed") if @object.soft_restore == false
|
|
311
|
+
|
|
302
312
|
respond_to do |format|
|
|
303
313
|
format.html { render_row_turbo(:close) }
|
|
304
314
|
end
|
|
@@ -313,7 +323,8 @@ class InlineFormsController < ApplicationController
|
|
|
313
323
|
return head :forbidden unless destroy_permitted?
|
|
314
324
|
return head :bad_request unless row_html_turbo_allowed?
|
|
315
325
|
|
|
316
|
-
@object.destroy
|
|
326
|
+
return render_row_refused("inline_forms.view.destroy_failed") if @object.destroy == false
|
|
327
|
+
|
|
317
328
|
# Capture after destroy: `.last` before destroy was the latest *update*
|
|
318
329
|
# (e.g. a plain_text_area edit), so undo reified the pre-edit state.
|
|
319
330
|
@undo_version = @object.versions.last
|
|
@@ -470,17 +481,37 @@ class InlineFormsController < ApplicationController
|
|
|
470
481
|
true
|
|
471
482
|
end
|
|
472
483
|
|
|
473
|
-
#
|
|
474
|
-
#
|
|
484
|
+
# Write one field's submitted value to @object; returns the messages of a
|
|
485
|
+
# refusal, empty when there is none. A check_list on a saved record writes
|
|
486
|
+
# its join rows here, before any validation, so a model can only refuse them
|
|
487
|
+
# in an association callback (before_add / before_remove) that raises. The
|
|
488
|
+
# association is reset: its in-memory list may hold the refused change.
|
|
489
|
+
#
|
|
490
|
+
# The send names a method after form_element. In update that comes from
|
|
491
|
+
# params, but field_request_permitted?(:update) has already refused (400)
|
|
492
|
+
# anything that is not a row of the model's attribute list; in create it
|
|
493
|
+
# comes from that list itself. (Brakeman does not follow params into this
|
|
494
|
+
# method, so brakeman.ignore no longer needs an entry for it.)
|
|
495
|
+
def assign_field(attribute, form_element)
|
|
496
|
+
send("#{form_element}_update", @object, attribute)
|
|
497
|
+
[]
|
|
498
|
+
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => refusal
|
|
499
|
+
@object.association(attribute.to_sym).reset if @object.class.reflect_on_association(attribute.to_sym)
|
|
500
|
+
(refusal.record&.errors&.full_messages || []).presence || [ refusal.message ]
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
# Hard-destroy gate. Generated apps restrict destroy to a Devise user who is
|
|
504
|
+
# the superadmin (InlineForms.superadmin?: the app's own `superadmin?`, else
|
|
505
|
+
# the role). Hosts without that role
|
|
475
506
|
# system (e.g. the engine's test/dummy harness, or apps using a different
|
|
476
507
|
# auth stack) have no gatekeeper here beyond CanCan's
|
|
477
508
|
# `load_and_authorize_resource`; pre-8.1.27 this crashed with
|
|
478
509
|
# `NoMethodError` on `nil.role?` instead of deciding either way.
|
|
479
510
|
def destroy_permitted?
|
|
480
511
|
user = respond_to?(:current_user, true) ? current_user : nil
|
|
481
|
-
return true unless user.respond_to?(:role?)
|
|
512
|
+
return true unless user.respond_to?(:superadmin?) || user.respond_to?(:role?)
|
|
482
513
|
|
|
483
|
-
|
|
514
|
+
InlineForms.superadmin?(user)
|
|
484
515
|
end
|
|
485
516
|
|
|
486
517
|
# Every reify on the revert path goes through here. +unversioned_attributes:
|
|
@@ -660,6 +691,22 @@ class InlineFormsController < ApplicationController
|
|
|
660
691
|
render template, layout: layout
|
|
661
692
|
end
|
|
662
693
|
|
|
694
|
+
# The model refused a destroy, soft delete or soft restore: the row as it is
|
|
695
|
+
# in the database, with the reason. +fallback+ is for a model that gave none.
|
|
696
|
+
def render_row_refused(fallback)
|
|
697
|
+
@inline_forms_row_errors = @object.errors.to_a.presence ||
|
|
698
|
+
[ t(fallback, model: @object.class.model_name.human) ]
|
|
699
|
+
@object = referenced_object
|
|
700
|
+
@inline_forms_turbo_row = true
|
|
701
|
+
respond_to do |format|
|
|
702
|
+
format.html do
|
|
703
|
+
render "inline_forms/row_close",
|
|
704
|
+
layout: turbo_frame_request? ? "turbo_rails/frame" : "inline_forms",
|
|
705
|
+
status: 422
|
|
706
|
+
end
|
|
707
|
+
end
|
|
708
|
+
end
|
|
709
|
+
|
|
663
710
|
def render_row_turbo_destroyed
|
|
664
711
|
@inline_forms_turbo_row = true
|
|
665
712
|
layout = turbo_frame_request? ? "turbo_rails/frame" : "inline_forms"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
</div>
|
|
10
10
|
<div class="top-bar-right">
|
|
11
11
|
<ul class="dropdown menu" data-dropdown-menu>
|
|
12
|
-
<% if current_user.role?(:admin) ||
|
|
12
|
+
<% if current_user.role?(:admin) || InlineForms.superadmin?(current_user) %>
|
|
13
13
|
<li>
|
|
14
14
|
<a href="#"><%= t 'common.more' %></a>
|
|
15
15
|
<ul class="menu">
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
<% object = local_assigns[:object] || @object -%>
|
|
3
3
|
<% inline_forms_turbo_row = local_assigns.fetch(:inline_forms_turbo_row, @inline_forms_turbo_row) -%>
|
|
4
4
|
<turbo-frame id="<%= update_span %>">
|
|
5
|
+
<% if @inline_forms_row_errors.present? %>
|
|
6
|
+
<div class="flash error inline_forms_row_error" role="alert">
|
|
7
|
+
<ul><% @inline_forms_row_errors.each do |message| %><li><%= message %></li><% end %></ul>
|
|
8
|
+
</div>
|
|
9
|
+
<% end %>
|
|
5
10
|
<div class="row odd top-level">
|
|
6
11
|
<%= render partial: "inline_forms/close",
|
|
7
12
|
locals: {
|
data/inline_forms.gemspec
CHANGED
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
s.required_ruby_version = ">= 4.0.0"
|
|
18
18
|
|
|
19
19
|
s.files = InlineFormsGemFiles.gem_files(include_installer: false)
|
|
20
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
|
21
20
|
s.require_paths = [ "lib" ]
|
|
22
21
|
|
|
23
22
|
s.add_dependency("validation_hints", ">= 8.1.4", "< 9.0")
|
data/lib/generators/USAGE
CHANGED
|
@@ -29,7 +29,7 @@ Value-bearing form elements:
|
|
|
29
29
|
Choice elements (dropdown_with_values, dropdown_with_integers,
|
|
30
30
|
dropdown_with_values_with_stars, radio_button, check_box,
|
|
31
31
|
scale_with_integers, scale_with_values) need a values hash as the 3rd row
|
|
32
|
-
element. The generator inserts a placeholder `{ 1 =>
|
|
32
|
+
element. The generator inserts a placeholder `{ 1 => "one", 2 => "two" }`
|
|
33
33
|
and warns; edit it to your real values.
|
|
34
34
|
|
|
35
35
|
Constraints and caveats:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
require "inline_forms"
|
|
3
3
|
require_relative "inline_forms_attribute_overrides"
|
|
4
|
+
require_relative "inline_forms_attribute_list_editor"
|
|
4
5
|
|
|
5
6
|
# == Usage
|
|
6
7
|
#
|
|
@@ -40,11 +41,6 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
40
41
|
# (shared with the schema GUI/preview).
|
|
41
42
|
VALUE_BEARING_ELEMENTS = InlineForms::VALUE_BEARING_FORM_ELEMENTS
|
|
42
43
|
|
|
43
|
-
# attribute_list rows whose form element (or name) marks the start of the
|
|
44
|
-
# trailing "metadata" block. The smart-default placement inserts new rows
|
|
45
|
-
# above this block instead of at the very end of the list.
|
|
46
|
-
METADATA_ROW_NAMES = %w[created_at updated_at].freeze
|
|
47
|
-
|
|
48
44
|
argument :attributes, type: :array, banner: "[name:form_element]..."
|
|
49
45
|
class_option :allow_unknown, type: :boolean, default: false,
|
|
50
46
|
desc: "Allow unknown field types (legacy behavior: comment generated lines instead of failing)."
|
|
@@ -124,8 +120,9 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
124
120
|
@migration_lines << " add_column :#{table_name}, :#{columns[:data]}, :binary, **(connection.adapter_name.match?(/mysql|trilogy/i) ? { size: :long } : {})\n"
|
|
125
121
|
@migration_lines << " add_column :#{table_name}, :#{columns[:content_type]}, :string\n"
|
|
126
122
|
else
|
|
127
|
-
commenter = attribute.attribute_type == :unknown ? "#" : "
|
|
128
|
-
@migration_lines << "#{commenter}
|
|
123
|
+
commenter = attribute.attribute_type == :unknown ? "# " : ""
|
|
124
|
+
@migration_lines << " #{commenter}add_column :#{table_name}, :#{attribute.name}, " \
|
|
125
|
+
":#{attribute.column_type}#{attribute.inline_forms_column_options}\n"
|
|
129
126
|
end
|
|
130
127
|
end
|
|
131
128
|
|
|
@@ -290,10 +287,8 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
290
287
|
# generator-shaped list (e.g. only the inherited
|
|
291
288
|
# `attr_writer :inline_forms_attribute_list` and no body).
|
|
292
289
|
#
|
|
293
|
-
#
|
|
294
|
-
#
|
|
295
|
-
# matching `]`, so the edit survives `].freeze`, trailing comments, and
|
|
296
|
-
# any methods defined after the list. Placement honors `--after`/`--before`
|
|
290
|
+
# InlineForms::AttributeListEditor finds the list with Ruby's parser and
|
|
291
|
+
# places the row. Placement honors `--after`/`--before`
|
|
297
292
|
# (by attribute name) and otherwise lands above the trailing metadata block
|
|
298
293
|
# (`:info` rows / created_at / updated_at, and a `:header` directly above
|
|
299
294
|
# them) instead of after it.
|
|
@@ -307,8 +302,10 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
307
302
|
return
|
|
308
303
|
end
|
|
309
304
|
|
|
310
|
-
|
|
311
|
-
unless
|
|
305
|
+
editor = attribute_list_editor(content, attribute)
|
|
306
|
+
return unless editor
|
|
307
|
+
|
|
308
|
+
unless editor.list?
|
|
312
309
|
say_status :warn, "#{model_file_path}: no inline_forms_attribute_list found, appending a fresh method", :yellow
|
|
313
310
|
body = <<~RUBY.gsub(/^(?=.)/, " ")
|
|
314
311
|
def inline_forms_attribute_list
|
|
@@ -322,143 +319,37 @@ class InlineFormsAddtoGenerator < Rails::Generators::NamedBase
|
|
|
322
319
|
end
|
|
323
320
|
|
|
324
321
|
warn_if_value_bearing!(attribute)
|
|
325
|
-
|
|
326
|
-
open_idx, close_idx = bounds
|
|
327
|
-
inner = content[(open_idx + 1)...close_idx]
|
|
328
|
-
lines = inner.lines
|
|
329
|
-
indent = detect_row_indent(lines)
|
|
330
|
-
|
|
331
|
-
insert_at, note = insertion_index(lines, attribute)
|
|
332
|
-
|
|
333
|
-
# A comma only when a row follows (RuboCop omakase wants none after the
|
|
334
|
-
# last one).
|
|
335
|
-
comma = lines.drop(insert_at).any? { |l| l.match?(/\A\s*\[/) } ? "," : ""
|
|
336
|
-
new_line = "#{indent}#{attribute_row_literal(attribute)}#{comma}\n"
|
|
337
|
-
|
|
338
|
-
# Keep the array valid: ensure the row we insert after ends with a comma.
|
|
339
|
-
if insert_at.positive?
|
|
340
|
-
prev = lines[insert_at - 1]
|
|
341
|
-
lines[insert_at - 1] = with_trailing_comma(prev) if prev
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
lines.insert(insert_at, new_line)
|
|
345
|
-
new_content = content[0..open_idx] + lines.join + content[close_idx..-1]
|
|
322
|
+
new_content, note = editor.insert(attribute_row_literal(attribute), **row_anchor(editor))
|
|
346
323
|
File.write(path, new_content)
|
|
347
324
|
say_status :insert, "#{model_file_path}: row :#{attribute.name}#{note}", :green
|
|
325
|
+
rescue InlineForms::AttributeListEditor::Unplaceable => e
|
|
326
|
+
row_not_added(attribute, e.message)
|
|
348
327
|
end
|
|
349
328
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return line if line.match?(/\A\s*(#|\z)/)
|
|
355
|
-
|
|
356
|
-
if row
|
|
357
|
-
depth = 0
|
|
358
|
-
ending = nil
|
|
359
|
-
line.each_char.with_index do |char, index|
|
|
360
|
-
depth += 1 if char == "["
|
|
361
|
-
depth -= 1 if char == "]"
|
|
362
|
-
if char == "]" && depth.zero?
|
|
363
|
-
ending = index
|
|
364
|
-
break
|
|
365
|
-
end
|
|
366
|
-
end
|
|
367
|
-
end
|
|
368
|
-
# Not a whole row on one line (the end of a longer one): its last `]`
|
|
369
|
-
# outside a comment.
|
|
370
|
-
ending ||= line.sub(/\s#.*/, "").rindex("]")
|
|
371
|
-
return line if ending.nil? || line[(ending + 1)..].match?(/\A\s*,/)
|
|
372
|
-
|
|
373
|
-
line.dup.insert(ending + 1, ",")
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
# Returns [open_bracket_index, close_bracket_index] for the
|
|
377
|
-
# `@inline_forms_attribute_list ||= [ ... ]` array literal, or nil when the
|
|
378
|
-
# model has no such list. Bracket-depth scan; nested `[ ]` (e.g. an
|
|
379
|
-
# options_disabled array inside a choice row) balances correctly.
|
|
380
|
-
def attribute_list_bounds(content)
|
|
381
|
-
m = content.match(/@inline_forms_attribute_list\s*\|\|=\s*\[/)
|
|
382
|
-
return nil unless m
|
|
383
|
-
|
|
384
|
-
open_idx = m.end(0) - 1 # index of the '[' itself
|
|
385
|
-
depth = 0
|
|
386
|
-
i = open_idx
|
|
387
|
-
while i < content.length
|
|
388
|
-
case content[i]
|
|
389
|
-
when "[" then depth += 1
|
|
390
|
-
when "]"
|
|
391
|
-
depth -= 1
|
|
392
|
-
return [ open_idx, i ] if depth.zero?
|
|
393
|
-
end
|
|
394
|
-
i += 1
|
|
395
|
-
end
|
|
329
|
+
def attribute_list_editor(content, attribute)
|
|
330
|
+
InlineForms::AttributeListEditor.new(content)
|
|
331
|
+
rescue InlineForms::AttributeListEditor::Unplaceable => e
|
|
332
|
+
row_not_added(attribute, e.message)
|
|
396
333
|
nil
|
|
397
334
|
end
|
|
398
335
|
|
|
399
|
-
#
|
|
400
|
-
def
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
say_status :warn, "#{model_file_path}: --after #{anchor} not found; using default placement", :yellow
|
|
405
|
-
elsif (anchor = options[:before].to_s) != ""
|
|
406
|
-
idx = row_line_index(lines, anchor)
|
|
407
|
-
return [ idx, " (before :#{anchor})" ] if idx
|
|
408
|
-
say_status :warn, "#{model_file_path}: --before #{anchor} not found; using default placement", :yellow
|
|
409
|
-
end
|
|
410
|
-
|
|
411
|
-
if (meta = metadata_start_index(lines))
|
|
412
|
-
return [ meta, " (above metadata)" ]
|
|
413
|
-
end
|
|
414
|
-
|
|
415
|
-
[ last_row_index(lines) + 1, "" ]
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
def row_line_index(lines, name)
|
|
419
|
-
lines.index { |l| row_name(l) == name.to_s }
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
def row_name(line)
|
|
423
|
-
m = line.match(/\A\s*\[\s*:(\w+)\s*,/)
|
|
424
|
-
m && m[1]
|
|
336
|
+
# Better no row than a model that does not load.
|
|
337
|
+
def row_not_added(attribute, reason)
|
|
338
|
+
say_status :error,
|
|
339
|
+
"#{model_file_path}: #{reason}; row not added. Add it by hand: #{attribute_row_literal(attribute)}",
|
|
340
|
+
:red
|
|
425
341
|
end
|
|
426
342
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
# Index of the first row that starts the trailing metadata block. If a
|
|
433
|
-
# `:header` sits directly above that row, the header is treated as the
|
|
434
|
-
# block start (so the new field lands above the header, not between it and
|
|
435
|
-
# its info rows). nil when the list has no metadata block.
|
|
436
|
-
def metadata_start_index(lines)
|
|
437
|
-
first = nil
|
|
438
|
-
lines.each_with_index do |l, i|
|
|
439
|
-
if row_element(l) == "info" || METADATA_ROW_NAMES.include?(row_name(l))
|
|
440
|
-
first = i
|
|
441
|
-
break
|
|
442
|
-
end
|
|
443
|
-
end
|
|
444
|
-
return nil unless first
|
|
343
|
+
# { after: name } or { before: name } when that row exists, else {}.
|
|
344
|
+
def row_anchor(editor)
|
|
345
|
+
key = %i[after before].find { |option| options[option].to_s != "" }
|
|
346
|
+
return {} unless key
|
|
445
347
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
end
|
|
449
|
-
|
|
450
|
-
def last_row_index(lines)
|
|
451
|
-
idx = nil
|
|
452
|
-
lines.each_with_index { |l, i| idx = i if row_name(l) }
|
|
453
|
-
idx || (lines.length - 1)
|
|
454
|
-
end
|
|
348
|
+
name = options[key].to_s
|
|
349
|
+
return { key => name } if editor.row?(name)
|
|
455
350
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
m = l.match(/\A(\s*)\[/)
|
|
459
|
-
return m[1] if m
|
|
460
|
-
end
|
|
461
|
-
" " # 6 spaces, matching the create-time template
|
|
351
|
+
say_status :warn, "#{model_file_path}: --#{key} #{name} not found; using default placement", :yellow
|
|
352
|
+
{}
|
|
462
353
|
end
|
|
463
354
|
|
|
464
355
|
# `[ :name, :element ]`, or `[ :name, :element, { 1 => "one", 2 => "two" } ]`
|