inline_forms 8.1.76 → 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 +31 -0
- 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/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/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 +2 -1
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,37 @@ 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
|
+
|
|
11
42
|
## [8.1.76] - 2026-11-22
|
|
12
43
|
|
|
13
44
|
### Fixed
|
|
@@ -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: {
|
|
@@ -20,11 +20,7 @@ module InlineForms
|
|
|
20
20
|
def check_list_edit(object, attribute)
|
|
21
21
|
object.send(attribute).build if object.send(attribute).empty?
|
|
22
22
|
klass = object.send(attribute).first.class
|
|
23
|
-
values =
|
|
24
|
-
# check_list has always applied the list scope's filter (a where in
|
|
25
|
-
# inline_forms_list hides records here); the order is DropdownOrder's.
|
|
26
|
-
values = values.merge(klass.inline_forms_list.unscope(:order)) if klass.respond_to?(:inline_forms_list)
|
|
27
|
-
values = InlineForms::DropdownOrder.apply(values)
|
|
23
|
+
values = InlineForms::DropdownOrder.apply(check_list_offered(klass))
|
|
28
24
|
out = ''
|
|
29
25
|
values.each do | item |
|
|
30
26
|
out << "<div class='row #{cycle('odd', 'even')}'>"
|
|
@@ -35,9 +31,29 @@ module InlineForms
|
|
|
35
31
|
out.html_safe
|
|
36
32
|
end
|
|
37
33
|
|
|
34
|
+
# The records the check list offers; check_list_update accepts no others.
|
|
35
|
+
def check_list_offered(klass)
|
|
36
|
+
values = cancan_enabled? ? klass.accessible_by(current_ability) : klass.all
|
|
37
|
+
# check_list has always applied the list scope's filter (a where in
|
|
38
|
+
# inline_forms_list hides records here); the order is DropdownOrder's.
|
|
39
|
+
values = values.merge(klass.inline_forms_list.unscope(:order)) if klass.respond_to?(:inline_forms_list)
|
|
40
|
+
values
|
|
41
|
+
end
|
|
42
|
+
|
|
38
43
|
def check_list_update(object, attribute)
|
|
39
44
|
params[attribute] ||= {}
|
|
40
|
-
|
|
45
|
+
ids = attribute.to_s.singularize + '_ids'
|
|
46
|
+
posted = params[attribute].keys.map(&:to_s)
|
|
47
|
+
held = object.send(ids).map(&:to_s)
|
|
48
|
+
offered = check_list_offered(object.class.reflect_on_association(attribute.to_sym).klass).map { |item| item.id.to_s }
|
|
49
|
+
# A hidden record is also a refused one. Nothing is assigned: on a saved
|
|
50
|
+
# record that would write the join rows at once.
|
|
51
|
+
if (posted - offered - held).any?
|
|
52
|
+
InlineForms::RefusedValues.add(object, attribute)
|
|
53
|
+
return
|
|
54
|
+
end
|
|
55
|
+
# Records the user was not shown stay: not ticked is not unticked.
|
|
56
|
+
object.send(ids + '=', posted | (held - offered))
|
|
41
57
|
object.touch unless object.new_record? # Check for new_record needed for Rails > 3; TODO we should have a flag to turn this on or of.
|
|
42
58
|
end
|
|
43
59
|
INLINE_FORMS_FORM_ELEMENT
|
|
@@ -20,12 +20,7 @@ module InlineForms
|
|
|
20
20
|
presentation = "_presentation"
|
|
21
21
|
presentation = "_dropdown_presentation" if attr.respond_to? "_dropdown_presentation"
|
|
22
22
|
klass = object.send(attribute).class
|
|
23
|
-
|
|
24
|
-
values = klass.accessible_by(current_ability)
|
|
25
|
-
else
|
|
26
|
-
values = klass.all
|
|
27
|
-
end
|
|
28
|
-
values = InlineForms::DropdownOrder.apply(values)
|
|
23
|
+
values = InlineForms::DropdownOrder.apply(dropdown_offered(klass))
|
|
29
24
|
options_disabled = nil
|
|
30
25
|
if klass.method_defined? :disabled_for_dropdown?
|
|
31
26
|
# loads values; collection_select below reuses the loaded records
|
|
@@ -42,6 +37,17 @@ module InlineForms
|
|
|
42
37
|
)
|
|
43
38
|
end
|
|
44
39
|
|
|
40
|
+
# The records the dropdown offers; dropdown_update accepts no others.
|
|
41
|
+
def dropdown_offered(klass)
|
|
42
|
+
cancan_enabled? ? klass.accessible_by(current_ability) : klass.all
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# An option shown disabled (disabled_for_dropdown?) is not offered either.
|
|
46
|
+
def dropdown_offers?(klass, value)
|
|
47
|
+
record = dropdown_offered(klass).find_by(klass.primary_key => value.to_s)
|
|
48
|
+
record.present? && !(record.respond_to?(:disabled_for_dropdown?) && record.disabled_for_dropdown?)
|
|
49
|
+
end
|
|
50
|
+
|
|
45
51
|
def dropdown_update(object, attribute)
|
|
46
52
|
# Inline edit posts the value under the leading-underscore wrapper key
|
|
47
53
|
# (`params[:_apartment][:owner_id]`); top-level create through a
|
|
@@ -51,8 +57,16 @@ module InlineForms
|
|
|
51
57
|
# walks do not raise NoMethodError on nil[:owner_id].
|
|
52
58
|
scope = params[('_' + object.class.to_s.underscore).to_sym]
|
|
53
59
|
return if scope.blank?
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
reflection = object.class.reflect_on_association(attribute.to_sym)
|
|
61
|
+
foreign_key = reflection.options[:foreign_key] || attribute.to_s.foreign_key.to_sym
|
|
62
|
+
value = scope[attribute.to_s.foreign_key.to_sym]
|
|
63
|
+
# A hidden option is also a refused value. The value the record already
|
|
64
|
+
# has may stay. It is assigned all the same, so that a model that refuses
|
|
65
|
+
# it says so in its own words; RefusedValues keeps it from being saved.
|
|
66
|
+
if value.present? && value.to_s != object[foreign_key].to_s && !dropdown_offers?(reflection.klass, value)
|
|
67
|
+
InlineForms::RefusedValues.add(object, attribute)
|
|
68
|
+
end
|
|
69
|
+
object[foreign_key] = value
|
|
56
70
|
end
|
|
57
71
|
|
|
58
72
|
def dropdown_info(object, attribute)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module InlineForms
|
|
4
|
+
# A field got a value it did not offer (a dropdown or check_list id outside
|
|
5
|
+
# the records the user may read). The record stays invalid while that value
|
|
6
|
+
# is on it, whoever saves it: the engine's create / update, or a host's own.
|
|
7
|
+
#
|
|
8
|
+
# The model's own validations run first, so a model that refuses the value
|
|
9
|
+
# with a message of its own keeps that message; :inclusion is only added
|
|
10
|
+
# when the attribute, or its foreign key, has no error yet.
|
|
11
|
+
module RefusedValues
|
|
12
|
+
def self.add(object, attribute)
|
|
13
|
+
object.extend(self)
|
|
14
|
+
object.inline_forms_refused_values << attribute.to_sym
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def inline_forms_refused_values
|
|
18
|
+
@inline_forms_refused_values ||= Set.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def valid?(...)
|
|
22
|
+
super
|
|
23
|
+
inline_forms_refused_values.each do |attribute|
|
|
24
|
+
foreign_key = self.class.reflect_on_association(attribute)&.foreign_key
|
|
25
|
+
next if errors.include?(attribute) || (foreign_key && errors.include?(foreign_key.to_sym))
|
|
26
|
+
|
|
27
|
+
errors.add(attribute, :inclusion)
|
|
28
|
+
end
|
|
29
|
+
errors.empty?
|
|
30
|
+
end
|
|
31
|
+
alias_method :validate, :valid?
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/inline_forms/version.rb
CHANGED
data/lib/inline_forms.rb
CHANGED
|
@@ -11,6 +11,7 @@ require "inline_forms/schema_label"
|
|
|
11
11
|
require "inline_forms/form_element_from_callee"
|
|
12
12
|
require "inline_forms/searchable"
|
|
13
13
|
require "inline_forms/dropdown_order"
|
|
14
|
+
require "inline_forms/refused_values"
|
|
14
15
|
require "inline_forms/archived_form_elements"
|
|
15
16
|
require "inline_forms/form_element_registry"
|
|
16
17
|
require "inline_forms/form_elements"
|
|
@@ -65,6 +66,15 @@ module InlineForms
|
|
|
65
66
|
end
|
|
66
67
|
end
|
|
67
68
|
|
|
69
|
+
# Is this user the superadmin? An app that has its own answer
|
|
70
|
+
# (`User#superadmin?`, e.g. only user 1) is asked first; otherwise it is
|
|
71
|
+
# whoever holds the role. A user class with neither is not a superadmin.
|
|
72
|
+
def self.superadmin?(user)
|
|
73
|
+
return !!user.superadmin? if user.respond_to?(:superadmin?)
|
|
74
|
+
|
|
75
|
+
user.respond_to?(:role?) && !!user.role?(:superadmin)
|
|
76
|
+
end
|
|
77
|
+
|
|
68
78
|
# The cross-record trash page (superadmin). One line in routes.rb:
|
|
69
79
|
# InlineForms.draw_file_trash_routes(self)
|
|
70
80
|
def self.draw_file_trash_routes(router)
|
|
@@ -34,6 +34,8 @@ nl:
|
|
|
34
34
|
close: sluiten
|
|
35
35
|
add_new: Maak een nieuw %{model}
|
|
36
36
|
create_failed: Kan %{model} niet aanmaken.
|
|
37
|
+
destroy_failed: Kan %{model} niet verwijderen.
|
|
38
|
+
restore_failed: Kan %{model} niet terugzetten.
|
|
37
39
|
undo: terughalen
|
|
38
40
|
restore: terugzetten
|
|
39
41
|
trash: weggooien
|
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.
|
|
4
|
+
version: 8.1.78
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ace Suares
|
|
@@ -255,6 +255,7 @@ files:
|
|
|
255
255
|
- lib/inline_forms/form_elements/text_field_helper.rb
|
|
256
256
|
- lib/inline_forms/form_elements/time_helper.rb
|
|
257
257
|
- lib/inline_forms/gem_files.rb
|
|
258
|
+
- lib/inline_forms/refused_values.rb
|
|
258
259
|
- lib/inline_forms/schema_apply.rb
|
|
259
260
|
- lib/inline_forms/schema_intent.rb
|
|
260
261
|
- lib/inline_forms/schema_label.rb
|