avo 4.4.3 → 4.4.4

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: 4db5afb9a352fe2f25dd355093e0fb16f466c205d4ab10f4c59a30951021c6aa
4
- data.tar.gz: aad220bc34950f2d5c53d9e7af37b6d98d4b4e26168e33df781bdae46d6e95e2
3
+ metadata.gz: a89f96a8c205ef4f0693b8b593bf09988d27968ea8013f8dcefa2b7846f87c9e
4
+ data.tar.gz: 67f740fcdd78212f5f717b4ba4ac16ae911fa9b9cec29900b19f4680133a614e
5
5
  SHA512:
6
- metadata.gz: 803ebc0900b8ce4ea49f94d0ef3f058075494894576c06975354d22024deba6485d4d3ff516711471af1231c28336085c80d88cb267fa0a77a20f6e41fcdaeaf
7
- data.tar.gz: 351edeedeb2ead0adf9c2b653d1c80f60b54367c11a06334df2f64f352d3edf86397b62a4a8c119b6b6f8c79f049efa7d8719c75ac72d52678badbf2faa5c2c2
6
+ metadata.gz: df12fa371c2240d2599b82e0fd02664ba638cb85d1aac47d7c6f9b62ca639be06177f0371bde90519416e4ff17d6e203b694fec43ae151a5061f5c90742c81ed
7
+ data.tar.gz: f2fa0792dc3c89d06bd1f082b71a91e91ee50effc4c66ef248f5634f8dfaeba6e6afe6bb43b78e08bd4550ebac263261ae86f579722ce094e72057e7c7638e03
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (4.4.3)
4
+ avo (4.4.4)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -161,7 +161,7 @@ class Avo::ResourceComponent < Avo::BaseComponent
161
161
 
162
162
  def row_actions
163
163
  @resource.get_actions
164
- .map { |action_bag| action_bag[:class].new(record: @resource.record, resource: @resource, view: @view, **action_bag.except(:class)) }
164
+ .map { |action_bag| action_bag[:class].new(record: @resource.record, resource: @resource, view: @view, parent_record: @parent_record, parent_resource: @parent_resource, **action_bag.except(:class)) }
165
165
  .select { |action| action.is_a?(Avo::Divider) || action.visible_in_view(parent_resource: @parent_resource) }
166
166
  end
167
167
 
@@ -1,7 +1,9 @@
1
1
  module Avo
2
2
  class ActionsController < Avo::ApplicationController
3
+ include Avo::Concerns::AssociationQueryScope
4
+
3
5
  before_action :set_resource_name, :set_resource
4
- before_action :set_query, :set_record, :set_action, :verify_authorization, only: [:show, :handle]
6
+ before_action :set_query, :set_record, :set_parent, :set_action, :verify_authorization, only: [:show, :handle]
5
7
  before_action :set_fields, only: :handle
6
8
 
7
9
  # Sets @record based on context:
@@ -93,7 +95,7 @@ module Avo
93
95
 
94
96
  def action_params
95
97
  @action_params ||= params.permit(
96
- :id, :authenticity_token, :resource_name, :action_id, :button, :arguments, :view_type, :resource_view, :via_related_name, fields: {}
98
+ :id, :authenticity_token, :resource_name, :action_id, :button, :arguments, :view_type, :resource_view, :via_related_name, :via_resource_class, :via_record_id, fields: {}
97
99
  )
98
100
  end
99
101
 
@@ -108,13 +110,42 @@ module Avo
108
110
  view: origin_view,
109
111
  arguments: BaseAction.decode_arguments(params[:arguments] || params.dig(:fields, :arguments)) || {},
110
112
  query: @query,
111
- index_query: decrypted_index_query
113
+ index_query: decrypted_index_query,
114
+ parent_record: @parent_record,
115
+ parent_resource: @parent_resource
112
116
  )
113
117
 
114
118
  # Fetch action's fields
115
119
  @action.fields
116
120
  end
117
121
 
122
+ # The panel's parent arrives as request params, so it is looked up the way the panel loaded it, and the run
123
+ # asks what the panel's Actions button asked: that the user may view the association and act on it.
124
+ def set_parent
125
+ return if params[:via_resource_class].blank? || params[:via_record_id].blank? || params[:via_related_name].blank?
126
+
127
+ field = set_parent_from_via_params(association: params[:via_related_name], resource_class: @resource.class)
128
+
129
+ raise Avo::NotAuthorizedError.new unless act_on_association_authorized?(field)
130
+ end
131
+
132
+ # Mirrors the `act_on_{association}?` check that shows the Actions button in the panel.
133
+ def act_on_association_authorized?(field)
134
+ return true unless Avo.configuration.authorization_enabled?
135
+
136
+ association_name = BaseResource.valid_association_name(@parent_record, field.association_name)
137
+ return true if association_name.blank?
138
+
139
+ service = @parent_resource.authorization(user: _current_user)
140
+ method_name = :"act_on_#{association_name}?"
141
+
142
+ if service.has_method?(method_name, raise_exception: false)
143
+ service.authorize_action(method_name, record: @parent_record, raise_exception: false)
144
+ else
145
+ !Avo.configuration.explicit_authorization
146
+ end
147
+ end
148
+
118
149
  # The view the action was started from: index, show, or edit. The action
119
150
  # link and the modal form both carry it as `resource_view`, but that is a
120
151
  # request param, so it is trusted only as far as the route backs it up: a
@@ -172,7 +203,13 @@ module Avo
172
203
  turbo_stream.avo_flash_alerts
173
204
  ]
174
205
  when :navigate_to_action
175
- src, _ = @response[:action].link_arguments(resource: @action.resource, **@response[:navigate_to_action_args])
206
+ # The next action runs from the same panel, so it gets the same parent.
207
+ src, _ = @response[:action].link_arguments(
208
+ resource: @action.resource,
209
+ **@action.parent_query,
210
+ via_related_name: params[:via_related_name],
211
+ **@response[:navigate_to_action_args]
212
+ )
176
213
 
177
214
  turbo_stream.turbo_frame_set_src(Avo::MODAL_FRAME_ID, src)
178
215
  when :redirect
@@ -110,6 +110,7 @@ module Avo
110
110
  def set_related_resource
111
111
  # Find the field from the parent resource
112
112
  association_field = find_association_field(resource: @resource, association: params[:related_name])
113
+ raise ActiveRecord::RecordNotFound if association_field.nil?
113
114
 
114
115
  # Find the resource from the related field
115
116
  related_resource = association_field.hydrate(record: @record).resource_class(params)
@@ -403,7 +403,7 @@ module Avo
403
403
  @actions = @resource
404
404
  .get_actions
405
405
  .map do |action_bag|
406
- action_bag[:class].new(record:, resource: @resource, view: @view, **action_bag.except(:class))
406
+ action_bag[:class].new(record:, resource: @resource, view: @view, parent_record: @parent_record, parent_resource: @parent_resource, **action_bag.except(:class))
407
407
  end
408
408
  .select do |action|
409
409
  action.is_a?(DividerComponent) || action.visible_in_view(parent_resource: @parent_resource)
@@ -264,6 +264,27 @@ module Avo
264
264
  Avo::Filters::BaseFilter.encode_filters(filter_params)
265
265
  end
266
266
 
267
+ # Filter `options` map each id to its label. A Hash in place of a label is a group: its key labels an <optgroup>
268
+ # and the Hash holds that group's own id => label options.
269
+ def filter_options_for_select(options, selected)
270
+ return options_for_select(options.invert, selected) if options.values.none?(Hash)
271
+
272
+ safe_join(
273
+ options.map do |key, value|
274
+ if value.is_a?(Hash)
275
+ content_tag :optgroup, options_for_select(value.invert, selected), label: key
276
+ else
277
+ options_for_select([[value, key]], selected)
278
+ end
279
+ end
280
+ )
281
+ end
282
+
283
+ # The rows a select box needs to list the filter's `options`, counting each group's label as a row.
284
+ def filter_options_rows(options)
285
+ options.values.sum { |value| value.is_a?(Hash) ? value.size + 1 : 1 }
286
+ end
287
+
267
288
  def number_to_social(number, start_at: 10_000)
268
289
  return number_with_delimiter(number) if number < start_at
269
290
 
@@ -11,7 +11,7 @@
11
11
  class="hidden text-content"
12
12
  >
13
13
  <%= form_with scope: 'fields',
14
- url: @action.link_arguments(resource: @resource, resource_view: params[:resource_view]).first,
14
+ url: @action.link_arguments(resource: @resource, resource_view: params[:resource_view], via_related_name: params[:via_related_name]).first,
15
15
  local: true,
16
16
  html: {
17
17
  novalidate: true,
@@ -3,10 +3,11 @@
3
3
  data-controller="multiple-select-filter"
4
4
  data-filter-name="<%= filter.name %>"
5
5
  data-multiple-select-filter-keep-filters-panel-open-value="<%= @resource.keep_filters_panel_open %>">
6
- <%= select_tag filter.id, options_for_select(filter.options.invert, filter.selected_value(@applied_filters)),
6
+ <% options = filter.options %>
7
+ <%= select_tag filter.id, filter_options_for_select(options, filter.selected_value(@applied_filters)),
7
8
  class: input_classes("filters-multi-select w-full"),
8
9
  multiple: true,
9
- size: filter.options.size.clamp(2, 4),
10
+ size: filter_options_rows(options).clamp(2, 4),
10
11
  id: "avo_filters_#{filter.id.parameterize.underscore}",
11
12
  "data-filter-class": filter.class.to_s,
12
13
  "data-multiple-select-filter-target": "selector" %>
@@ -3,7 +3,7 @@
3
3
  data-controller="select-filter"
4
4
  data-filter-name="<%= filter.name %>"
5
5
  data-select-filter-keep-filters-panel-open-value="<%= @resource.keep_filters_panel_open %>">
6
- <%= select_tag filter.id, options_for_select(filter.options.invert, filter.applied_or_default_value(@applied_filters)),
6
+ <%= select_tag filter.id, filter_options_for_select(filter.options, filter.applied_or_default_value(@applied_filters)),
7
7
  class: input_classes("w-full mb-0"),
8
8
  include_blank: filter.class.empty_message || "—",
9
9
  id: "avo_filters_#{filter.id.parameterize.underscore}",
@@ -36,6 +36,10 @@ module Avo
36
36
  attr_accessor :record
37
37
  attr_accessor :resource
38
38
  attr_accessor :user
39
+ # The record and resource of the association panel the action was started from, like the
40
+ # team whose members panel lists the selected users. Both are nil anywhere else.
41
+ attr_accessor :parent_record
42
+ attr_accessor :parent_resource
39
43
  attr_reader :arguments
40
44
  attr_reader :icon
41
45
  attr_reader :appended_turbo_streams
@@ -53,7 +57,6 @@ module Avo
53
57
  delegate :avo, to: :view_context
54
58
  delegate :main_app, to: :view_context
55
59
  delegate :to_param, to: :class
56
- delegate :link_arguments, to: :class
57
60
  delegate :translation_key, to: :class
58
61
 
59
62
  class << self
@@ -129,6 +132,8 @@ module Avo
129
132
  target: name,
130
133
  resource: @resource,
131
134
  record: @record,
135
+ parent_record: @parent_record,
136
+ parent_resource: @parent_resource,
132
137
  view: @view,
133
138
  arguments: @arguments,
134
139
  query: @query,
@@ -139,9 +144,11 @@ module Avo
139
144
  self.class.to_s.demodulize.underscore.humanize(keep_id_suffix: true)
140
145
  end
141
146
 
142
- def initialize(record: nil, resource: nil, user: nil, view: nil, arguments: {}, icon: "tabler/outline/player-play", query: nil, index_query: nil)
147
+ def initialize(record: nil, resource: nil, user: nil, view: nil, arguments: {}, icon: "tabler/outline/player-play", query: nil, index_query: nil, parent_record: nil, parent_resource: nil)
143
148
  @record = record
144
149
  @resource = resource
150
+ @parent_record = parent_record
151
+ @parent_resource = parent_resource
145
152
  @user = user
146
153
  @view = Avo::ViewInquirer.new(view)
147
154
  @icon = icon
@@ -159,6 +166,18 @@ module Avo
159
166
  @response[:messages] = []
160
167
  end
161
168
 
169
+ # The action's link carries the panel's parent, so the actions controller can find it again.
170
+ def link_arguments(resource:, arguments: {}, **args)
171
+ self.class.link_arguments(resource:, arguments:, **parent_query, **args)
172
+ end
173
+
174
+ # The `via_*` params that name the parent, or an empty hash when there is none.
175
+ def parent_query
176
+ return {} if @parent_record.blank? || @parent_resource.blank?
177
+
178
+ {via_resource_class: @parent_resource.class.to_s, via_record_id: @parent_record.to_param}
179
+ end
180
+
162
181
  # Blank method
163
182
  def fields
164
183
  end
@@ -237,7 +256,8 @@ module Avo
237
256
  Avo::ExecutionContext.new(
238
257
  target: visible,
239
258
  params: params,
240
- parent_resource: parent_resource,
259
+ parent_record: @parent_record,
260
+ parent_resource: parent_resource || @parent_resource,
241
261
  resource: @resource,
242
262
  view: @view,
243
263
  arguments: arguments
@@ -349,6 +369,8 @@ module Avo
349
369
  target: authorize,
350
370
  action: self,
351
371
  resource: @resource,
372
+ parent_record: @parent_record,
373
+ parent_resource: @parent_resource,
352
374
  view: @view,
353
375
  arguments: arguments
354
376
  ).handle
@@ -372,6 +394,8 @@ module Avo
372
394
  target: confirmation,
373
395
  action: self,
374
396
  resource: @resource,
397
+ parent_record: @parent_record,
398
+ parent_resource: @parent_resource,
375
399
  view: @view,
376
400
  arguments:
377
401
  ).handle
@@ -393,6 +417,8 @@ module Avo
393
417
  action: self,
394
418
  resource: @resource,
395
419
  record: @record,
420
+ parent_record: @parent_record,
421
+ parent_resource: @parent_resource,
396
422
  view: @view,
397
423
  arguments:,
398
424
  query: @query,
@@ -412,6 +438,8 @@ module Avo
412
438
  target: self.class.public_send(option),
413
439
  resource: @resource,
414
440
  record: @record,
441
+ parent_record: @parent_record,
442
+ parent_resource: @parent_resource,
415
443
  view: @view,
416
444
  arguments: @arguments,
417
445
  query: @query,
@@ -29,15 +29,7 @@ module Avo
29
29
  end
30
30
 
31
31
  def build_association_scope_from_params(resource:, authorization:)
32
- parent_resource_class = Avo.resource_manager.get_resource(params[:via_resource_class])
33
- @parent_record = parent_resource_class.find_record(params[:via_record_id], params: params)
34
- @parent_resource = parent_resource_class.new(
35
- record: @parent_record,
36
- view: Avo::ViewInquirer.new("show")
37
- )
38
- @parent_resource.detect_fields
39
- field = find_association_field(resource: @parent_resource, association: params[:association_name] || params[:related_name])
40
- authorize_via_association field, resource.class
32
+ field = set_parent_from_via_params(association: params[:association_name] || params[:related_name], resource_class: resource.class)
41
33
 
42
34
  association_query_scope(
43
35
  parent_resource: @parent_resource,
@@ -48,6 +40,26 @@ module Avo
48
40
  resource: resource
49
41
  )
50
42
  end
43
+
44
+ # Returns the parent's association field once it is known to list `resource_class` and the user may view it.
45
+ def set_parent_from_via_params(association:, resource_class:)
46
+ parent_resource_class = Avo.resource_manager.get_resource(params[:via_resource_class])
47
+ raise ActiveRecord::RecordNotFound if parent_resource_class.nil?
48
+
49
+ @parent_record = parent_resource_class.find_record(params[:via_record_id], params: params)
50
+ @parent_resource = parent_resource_class.new(
51
+ record: @parent_record,
52
+ view: Avo::ViewInquirer.new("show")
53
+ )
54
+ @parent_resource.detect_fields
55
+ field = find_association_field(resource: @parent_resource, association: association)
56
+ # Only the panel fields (has_one, has_many, has_and_belongs_to_many, array) list records through the parent.
57
+ raise ActiveRecord::RecordNotFound unless field.is_a?(Avo::Fields::FrameBaseField)
58
+
59
+ authorize_via_association field, resource_class
60
+
61
+ field
62
+ end
51
63
  end
52
64
  end
53
65
  end
@@ -41,11 +41,13 @@ module Avo::Concerns::RendersControls
41
41
 
42
42
  def render_action(action)
43
43
  return if !can_see_the_actions_button?
44
+ # Inside an association panel the action's blocks see the panel's parent, and its link carries it.
45
+ action.action.hydrate(parent_record: @parent_record, parent_resource: @parent_resource) if @parent_record.present?
44
46
  return if !action.action.visible_in_view(parent_resource: @parent_resource)
45
47
 
46
48
  tooltip = avo_tooltip_attributes(action.title)
47
49
 
48
- a_link Avo::Services::URIService.parse(action.path).append_query(via_related_name_query).to_s,
50
+ a_link Avo::Services::URIService.parse(action.path).append_query(via_related_name_query.merge(action.action.parent_query)).to_s,
49
51
  color: action.color,
50
52
  style: action.style,
51
53
  icon: action.icon,
@@ -37,6 +37,10 @@ module Avo
37
37
  # Field labels fall back to the model's attribute translations (activerecord.attributes / attributes).
38
38
  attr_accessor :model_attribute_translations
39
39
  attr_accessor :currency
40
+ # Default Luxon display formats for date, date_time, and time fields. A field's own `format:` wins.
41
+ attr_accessor :date_format
42
+ attr_accessor :date_time_format
43
+ attr_accessor :time_format
40
44
  attr_accessor :default_view_type
41
45
  attr_accessor :license_key
42
46
  attr_accessor :authorization_methods
@@ -180,6 +184,9 @@ module Avo
180
184
  @locale_selector = true
181
185
  @model_attribute_translations = true
182
186
  @currency = "USD"
187
+ @date_format = "yyyy-LL-dd"
188
+ @date_time_format = "yyyy-LL-dd TT"
189
+ @time_format = "TT"
183
190
  @default_view_type = :table
184
191
  @map_view = {}
185
192
  @license_key = nil
@@ -12,6 +12,11 @@ module Avo
12
12
  def resource_class(params)
13
13
  use_resource || Avo.resource_manager.get_resource_by_name(@id.to_s)
14
14
  end
15
+
16
+ # There's no Active Record association to reflect on, so the panel lists the resource named after the field.
17
+ def target_resource
18
+ resource_class(nil)
19
+ end
15
20
  end
16
21
  end
17
22
  end
@@ -0,0 +1,38 @@
1
+ module Avo
2
+ module Fields
3
+ module Concerns
4
+ # The `key` option of the `file` and `files` fields: the blob key Active Storage stores an uploaded file under,
5
+ # instead of a random token. A string, or a block that sees the `record`, `resource`, `field` and `file`.
6
+ module HasStorageKey
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ attr_reader :key
11
+ end
12
+
13
+ private
14
+
15
+ # Direct uploads and Media Library files arrive as signed ids of blobs that are already stored, so they keep
16
+ # their key. Only a file uploaded through the form becomes the attachable hash that carries one.
17
+ def with_storage_key(file, record:)
18
+ return file if @key.nil? || !file.is_a?(ActionDispatch::Http::UploadedFile)
19
+
20
+ storage_key = Avo::ExecutionContext.new(target: @key, record:, resource: @resource, field: self, file:).handle.to_s
21
+ return file if storage_key.blank?
22
+
23
+ # Keys are unique and a replaced file's blob is purged after the new one is saved, so a re-upload of the same
24
+ # key would fail the save with the database's error. save_record stops on this field error instead.
25
+ taken = ActiveStorage::Blob.exists?(key: storage_key) || !storage_keys.add?(storage_key)
26
+ record.errors.add(id, :taken) if taken
27
+
28
+ {io: file.open, filename: file.original_filename, content_type: file.content_type, key: storage_key}
29
+ end
30
+
31
+ # Keys given out during this fill, so two files of one upload can't share a key either
32
+ def storage_keys
33
+ @storage_keys ||= Set.new
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -12,7 +12,7 @@ module Avo
12
12
 
13
13
  add_string_prop args, :first_day_of_week, 1
14
14
  add_string_prop args, :picker_format, "Y-m-d"
15
- add_string_prop args, :format, "yyyy-LL-dd"
15
+ add_string_prop args, :format, Avo.configuration.date_format
16
16
  add_boolean_prop args, :disable_mobile
17
17
  add_object_prop args, :picker_options
18
18
  end
@@ -11,7 +11,7 @@ module Avo
11
11
 
12
12
  add_boolean_prop args, :time_24hr
13
13
  add_string_prop args, :picker_format, "Y-m-d H:i:S"
14
- add_string_prop args, :format, "yyyy-LL-dd TT"
14
+ add_string_prop args, :format, Avo.configuration.date_time_format
15
15
  add_string_prop args, :timezone
16
16
  add_boolean_prop args, :relative, true
17
17
  end
@@ -1,6 +1,8 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class FileField < BaseField
4
+ include Avo::Fields::Concerns::HasStorageKey
5
+
4
6
  attr_accessor :link_to_record
5
7
  attr_accessor :is_avatar
6
8
  attr_accessor :direct_upload
@@ -17,6 +19,7 @@ module Avo
17
19
  @accept = args[:accept].present? ? args[:accept] : nil
18
20
  @display_filename = args[:display_filename].nil? || args[:display_filename]
19
21
  @lightbox = args[:lightbox].nil? || args[:lightbox]
22
+ @key = args[:key]
20
23
  end
21
24
 
22
25
  # Images open in an in-page lightbox on the Show view unless the field opts
@@ -38,6 +41,11 @@ module Avo
38
41
  rails_blob_url value
39
42
  end
40
43
 
44
+ # The storage key goes on last, so `update_using` still gets the uploaded file.
45
+ def apply_update_using(record, key, value, resource)
46
+ with_storage_key(super, record:)
47
+ end
48
+
41
49
  def value
42
50
  final_value = super
43
51
 
@@ -1,6 +1,8 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class FilesField < BaseField
4
+ include Avo::Fields::Concerns::HasStorageKey
5
+
4
6
  attr_accessor :direct_upload
5
7
  attr_accessor :accept
6
8
  attr_reader :display_filename
@@ -17,6 +19,7 @@ module Avo
17
19
  @lightbox = args[:lightbox].nil? || args[:lightbox]
18
20
  @view_type = args[:view_type] || :grid
19
21
  @hide_view_type_switcher = args[:hide_view_type_switcher]
22
+ @key = args[:key]
20
23
  end
21
24
 
22
25
  # Images open in an in-page lightbox on the Show view unless the field opts
@@ -47,7 +50,7 @@ module Avo
47
50
 
48
51
  # `attach` without its immediate save on a persisted record, so the files are saved with the record and a form
49
52
  # that fails saves none. One assignment avoids an index_active_storage_attachments_uniqueness violation.
50
- record.public_send(:"#{key}=", record.public_send(key).blobs + value.compact_blank)
53
+ record.public_send(:"#{key}=", record.public_send(key).blobs + value.compact_blank.map { |file| with_storage_key(file, record:) })
51
54
 
52
55
  record
53
56
  end
@@ -8,7 +8,7 @@ module Avo
8
8
  super
9
9
 
10
10
  add_string_prop args, :picker_format, "H:i:S"
11
- add_string_prop args, :format, "TT"
11
+ add_string_prop args, :format, Avo.configuration.time_format
12
12
  end
13
13
  end
14
14
  end
@@ -261,7 +261,7 @@ When an index spans multiple pages, checking "Select all" offers to select **eve
261
261
 
262
262
  - **`query` is an array** (a relation only on Select all across pages). Even a single-record action gets `[record]`; relation methods like `update_all`, `where` or `find_each` aren't available on it, so iterate, or use `Model.where(id: query.map(&:id))`. Use `query.first` for the one-record case; don't call record methods on `query` directly. `records` is an alias.
263
263
  - **Records deleted after selection are omitted.** Another user may delete a checked record before the action request arrives. Avo drops that missing record and still passes every surviving selection to `handle`; action authors do not need to rescue `ActiveRecord::RecordNotFound` for this race. `query` can therefore come back **empty** when every selected record is gone — guard with `return error "No record selected" if query.blank?` if that matters.
264
- - **"My action doesn't show up", or is refused, is usually the policy.** With Pundit, `act_on?` in the resource's policy gates the Actions dropdown and every run: Avo asks it of the record in the URL and of each selected record (of the model class when there are none, and for a "Select all" run), and one refusal refuses the whole run. An action started from an association panel shows under the parent's `act_on_<assoc>?`, but still runs only on children whose own `act_on?` allows it. `authorize` on the action gates it further. Check the policy first. See the **`avo-authorization`** skill.
264
+ - **"My action doesn't show up", or is refused, is usually the policy.** With Pundit, `act_on?` in the resource's policy gates the Actions dropdown and every run: Avo asks it of the record in the URL and of each selected record (of the model class when there are none, and for a "Select all" run), and one refusal refuses the whole run. An action started from an association panel shows under the parent's `act_on_<assoc>?`, and from `avo` 4.4.4 its run asks the parent's `view_<assoc>?` and `act_on_<assoc>?` again; it still runs only on children whose own `act_on?` allows it. `authorize` on the action gates it further. Check the policy first. See the **`avo-authorization`** skill.
265
265
  - **`view` is the view the action was started from.** In `authorize`, `visible`, the modal text blocks, `fields`, and `handle`, `view` (and `resource.view`) is `index`, `show`, or `edit` — the page the user opened the action from — both while the modal renders and while the action runs. It is never `new`; the modal is not a view. It arrives with the request and is checked against the route (`show` and `edit` need a record in the URL), so use it to adapt behavior (`reload_records if view.index?`), never as the only gate on who may run the action: gate people on `current_user`, and single-versus-bulk on `query.size` or `record`.
266
266
  - **Every field in `fields` renders in the modal.** `hide_on`/`show_on` marks are for resource views and are ignored here. A field with a form component (text, select, hidden...) renders as an input; a display-only field (badge, key/value) renders read-only, as on Show. The one mark that counts: a badge declared with `show_on: :forms` renders as a select. The modal focuses its first input; a field with `autofocus: true` takes the focus instead (avo-fields lists the fields that support it). Use it to show context next to the inputs.
267
267
  - **The modal is a NEW request.** Params from the Index/Show page that opened it are **not** available in `fields`/`handle`. To prefill from the triggering page, parse `request.referer`:
@@ -271,7 +271,7 @@ When an index spans multiple pages, checking "Select all" offers to select **eve
271
271
  }
272
272
  ```
273
273
  - **A `belongs_to` field arrives in `handle` under its foreign key.** `field :user, as: :belongs_to` is `fields[:user_id]`; a polymorphic one arrives as `fields[:reviewable_type]` and `fields[:reviewable_id]` (4.2.7+). Both are the submitted strings, and an action does not check the type against the field's `types`, so validate it before constantizing. On `avo` older than 4.2.9 the field doesn't render in a bulk or standalone action: use `as: :select` or `as: :tags, mode: :select, fetch_values_from: "..."` and assign the ID yourself.
274
- - **Actions also run from association panels (4.3.3+).** A `has_many` or `has_and_belongs_to_many` panel offers the actions declared on the *associated* resource, on the rows checked in the panel. `record` is `nil` while the dropdown renders (as on Index), so `name` and `arguments` blocks must handle that; the panel's parent record reaches `visible` as `parent_resource.record` (`parent_resource` is `nil` outside a panel).
274
+ - **Actions also run from association panels (4.3.3+).** A `has_many` or `has_and_belongs_to_many` panel offers the actions declared on the *associated* resource, on the rows checked in the panel. `record` is `nil` while the dropdown renders (as on Index), so `name` and `arguments` blocks must handle that. From `avo` 4.4.4 the action reads the panel's parent as `parent_record` and `parent_resource` in `fields`, `handle` and every block, and keeps it through `navigate_to_action`; use it instead of passing the parent id in `arguments`. Both are `nil` outside a panel, so guard in an action that also runs on Index. Before 4.4.4 only `visible` got it, as `parent_resource.record`.
275
275
  - **`reload_records` is Index-only.** It doesn't work on association tables — use `reload` there.
276
276
  - **Notification bodies truncate at ~320 characters.** Keep `succeed`/`error` messages short; put long output in a `download` or a redirect.
277
277
  - **File downloads need `self.turbo = false`.** Otherwise Turbo intercepts the response and the download won't fire.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: avo-admin-config
3
- description: Configure Avo's app-wide admin settings in config/initializers/avo.rb via Avo.configure — app name, timezone/currency, per-page and index behavior, layout width, home redirect, open-in-editor links, and the other global knobs that don't belong to a single feature. Use when the user wants to change how many records per page, rename the admin / change the app name, set the timezone or currency for the admin, default the index to grid view, make the admin full-width, keep clicking a row from opening the record, skip the show view / go straight to edit, open Avo files in Cursor or VS Code from the UI, keep the sidebar always open, redirect the admin home to a dashboard, add a class to the body tag, make rows denser, widen the sidebar or turn off sidebar resizing, remove or retune the floating "Back to top" button, persist filters/pagination across requests, choose which map tiles the admin renders, or opt out of usage metadata.
3
+ description: Configure Avo's app-wide admin settings in config/initializers/avo.rb via Avo.configure — app name, timezone/currency, date and time display formats, per-page and index behavior, layout width, home redirect, open-in-editor links, and the other global knobs that don't belong to a single feature. Use when the user wants to change how many records per page, rename the admin / change the app name, set the timezone or currency for the admin, show every date as dd.mm.yyyy, default the index to grid view, make the admin full-width, keep clicking a row from opening the record, skip the show view / go straight to edit, open Avo files in Cursor or VS Code from the UI, keep the sidebar always open, redirect the admin home to a dashboard, add a class to the body tag, make rows denser, widen the sidebar or turn off sidebar resizing, remove or retune the floating "Back to top" button, persist filters/pagination across requests, choose which map tiles the admin renders, or opt out of usage metadata.
4
4
  allowed-tools: Read, Edit, Write, Glob, Grep, Bash, WebFetch
5
5
  metadata:
6
6
  requires-gem: none — Community
@@ -59,6 +59,9 @@ config.app_name = -> { I18n.t "app_name" } # block form for dynamic/i18n na
59
59
  config.timezone = "UTC" # for date/datetime fields
60
60
  config.use_browser_timezone = false # render everyone in the app's configured zone instead; default true renders each visitor's own zone (cookie-detected, one soft reload + alert). Defaults to false in the test environment — the soft reload races browser specs
61
61
  config.currency = "USD" # stored for your own code; no built-in field reads it (the Money field takes `currencies:`)
62
+ config.date_format = "dd.LL.yyyy" # Luxon display format for every `date` field on Index/Show (default "yyyy-LL-dd"); a field's own `format:` wins
63
+ config.date_time_format = "dd.LL.yyyy HH:mm" # same for `date_time` fields (default "yyyy-LL-dd TT")
64
+ config.time_format = "HH:mm" # same for `time` fields (default "TT"); `time` never reads date_time_format. Forms keep each field's flatpickr `picker_format`
62
65
  config.locale = "en-US" # force Avo's UI locale (default: I18n.default_locale)
63
66
  config.locale_selector = [:en, :ro] # profile-menu language picker, stored per user (default: true; false hides it)
64
67
  config.model_attribute_translations = false # field labels stop falling back to the model's activerecord.attributes / attributes keys (default: true)
@@ -152,6 +152,7 @@ Every field accepts these common options (full list + types at the field-options
152
152
  - **`autofocus:`** — puts the cursor in the field when the New/Edit form or an action modal opens: `autofocus: true`, or `autofocus: -> { view.new? }` for New only. In an action modal it replaces the default first-input focus; if several fields set it, the first one on the page wins. Honored by `text`, `textarea`, `number`, `password`, `select`, `status`, `boolean`, `code`, `easy_mde`, `area`, `external_image`, `file`, `files`, `progress_bar`, `country`, non-searchable `belongs_to` (a polymorphic one focuses its type select) and fields generated with `avo:field`; every other field ignores it. Only set it on one of those: in an action modal, a field that ignores it leaves nothing focused. A readonly/disabled field or one in a tab that isn't open can't take focus. It is also ignored in nested association forms, in reactive (`react_on`) re-renders, and in the action card of an Avo AI chat, which keep focus where the surrounding form or chat composer put it.
153
153
  - **`sortable:`** — makes the Index column sortable. `true` for real columns; a `-> { query.order(...) }` lambda (receives `query` and `direction`) for computed fields.
154
154
  - **Number `format:`** — formats `:number` fields on Index and Show with `:delimited`, `:percentage`, or `:human`; forms keep the raw number. A formatted number is end-aligned in tables, while a bare number stays start-aligned for identifier/year-shaped values. Rails i18n controls delimiters and separators. For money use the `:money` field, and for anything else `format_display_using:`.
155
+ - **Date and time `format:`** - Luxon tokens for `:date`, `:date_time` and `:time` on Index and Show: `field :starts_at, as: :date_time, format: "dd LLL yyyy HH:mm"`. To change every field at once, set `config.date_format`, `config.date_time_format` or `config.time_format` in the initializer (see the avo-admin-config skill); a field's own `format:` wins. New and Edit use `picker_format` with flatpickr tokens, which the config options don't touch.
155
156
  - **`format_using:`** — reshape the displayed value. **Runs on form views too**, so branch on the view when the form should stay editable: `format_using: -> { view.form? ? value : value.upcase }`. View-scoped variants exist (`format_display_using`, `format_index_using`, `format_show_using`, `format_form_using`, …) — the most specific one wins, they don't chain. Rails view helpers are callable directly inside the block — `-> { number_to_currency(value) }`, no `view_context` receiver.
156
157
  - **`update_using:`** — parse the raw form `value` before it's saved.
157
158
  - **`nullable:`** / **`null_values:`** — store empty input as `NULL` (optionally define which values count as null).
@@ -159,6 +160,7 @@ Every field accepts these common options (full list + types at the field-options
159
160
  - **`always_show:`** — editor fields only (`trix`, `rhino`, `lexxy`, `markdown`, `easy_mde`, `tip_tap`, `code`). `true` renders the full value on Show instead of the collapsed preview. Defaults to `false`.
160
161
  - **`link_to_record:`** — make the Index cell a link to the record. Only on `:id`, `:text`, `:number`, `:date`, `:date_time`, `:time`, `:gravatar`, `:file`, `:external_image`, and `belongs_to`.
161
162
  - **`lightbox:`** — `:file` and `:files` only. On Show, images open in an in-page lightbox (prev/next, arrow keys, Escape, a link to the original) by default; `lightbox: false` renders the plain image. Non-image files are unaffected.
163
+ - **`key:`** - `:file` and `:files` only. The Active Storage blob key a file uploaded through the form is stored under, instead of a random token: a string, or a block with `record`, `resource`, `field` and the uploaded `file`, run once per file. A blank result keeps the random key. Keys are unique: a taken key, a re-upload of the same name included, shows "has already been taken" on the field and saves nothing, so add a random segment (`"posts/#{SecureRandom.base36(8)}/#{file.original_filename}"`). `record.to_param` is nil on New. Direct uploads and Media Library picks keep their key.
162
164
  - **`for_attribute:`** — back the field with a different attribute than its id (lets you show one column two ways).
163
165
  - **`width:`** / **`stacked:`** — column width (`25/33/50/66/75/100`; any value <100 auto-stacks) and label-above-value layout. `stacked:` on the field wins everywhere, so `stacked: false` opts out of the auto-stacking and of sidebars/preview stacking too.
164
166
  - **`html:`** — attach `style`/`classes`/`data` to the field's wrapper/label/input per view (e.g. allow wrapping on Index: `html: {index: {wrapper: {classes: "whitespace-normal"}}}`). See the html page.
@@ -159,6 +159,7 @@ The same filter class can be registered on many resources. To vary behavior per
159
159
 
160
160
  - **Default state:** define `default` returning the same shape `apply` expects (`:published`, `{is_featured: true}`, `["a", "b"]`).
161
161
  - **Dynamic options:** `options` is plain Ruby — query the DB or an API.
162
+ - **Grouped options:** on select and multiple select filters, a Hash in place of a label is a group — `{"Europe" => {fr: "France", de: "Germany"}}` lists France and Germany under an `<optgroup>` labeled "Europe". `apply` still receives the option ids (`"fr"`). This is not the select field's `grouped_options` format, which lists the label first; flip each pair to reuse a field's list.
162
163
  - **Conditional visibility:** `self.visible = -> { current_user.admin? }`.
163
164
  - **Filters that depend on each other:** read `applied_filters` in `options`, or override `react` to change a filter's own value when another changes.
164
165
  - **Link to a pre-filtered view:** `Avo::Filters::BaseFilter.encode_filters({"Avo::Filters::Name" => "Apple"})` → pass as `encoded_filters:`.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "repo": "avo-hq/docs.avohq.io",
3
3
  "docs_path": "docs/4.0",
4
- "commit": "c54913692157757c342802a3b9e1d5f167798624",
5
- "date": "2026-11-09",
4
+ "commit": "52cd4fe38a73692266edd911dc22c432eea8af73",
5
+ "date": "2026-11-10",
6
6
  "note": "The docs commit these skills were last indexed from. Run ruby lib/avo/skills/bin/docs_drift.rb to see what changed since, and --update after a refresh."
7
7
  }
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "4.4.3" unless const_defined?(:VERSION)
2
+ VERSION = "4.4.4" unless const_defined?(:VERSION)
3
3
  end
@@ -176,6 +176,10 @@ Avo.configure do |config|
176
176
  # config.timezone = 'UTC'
177
177
  # config.use_browser_timezone = true # set false to render dates/times in the app's configured zone for everyone; off automatically in the test environment
178
178
  # config.currency = 'USD'
179
+ # Default display formats (Luxon tokens) for date, date_time, and time fields. A field's own `format:` wins.
180
+ # config.date_format = 'yyyy-LL-dd'
181
+ # config.date_time_format = 'yyyy-LL-dd TT'
182
+ # config.time_format = 'TT'
179
183
  # config.hide_layout_when_printing = false
180
184
  # config.container_width = :lg # :full, :lg, :md, or :sm. Hash for per-view: { index: :full, single: :md }
181
185
  # config.use_stacked_fields = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avo
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.3
4
+ version: 4.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -967,7 +967,6 @@ files:
967
967
  - config/i18n-tasks.yml
968
968
  - config/importmap.rb
969
969
  - config/initializers/avo_icons.rb
970
- - config/initializers/pagy.rb
971
970
  - config/routes.rb
972
971
  - config/routes/dynamic_routes.rb
973
972
  - config/spring.rb
@@ -1045,6 +1044,7 @@ files:
1045
1044
  - lib/avo/fields/concerns/has_field_name.rb
1046
1045
  - lib/avo/fields/concerns/has_html_attributes.rb
1047
1046
  - lib/avo/fields/concerns/has_resizable_editor.rb
1047
+ - lib/avo/fields/concerns/has_storage_key.rb
1048
1048
  - lib/avo/fields/concerns/is_disabled.rb
1049
1049
  - lib/avo/fields/concerns/is_readonly.rb
1050
1050
  - lib/avo/fields/concerns/is_required.rb
@@ -1247,8 +1247,6 @@ files:
1247
1247
  - lib/generators/avo/templates/locales/avo.ua.yml
1248
1248
  - lib/generators/avo/templates/locales/avo.zh-TW.yml
1249
1249
  - lib/generators/avo/templates/locales/avo.zh.yml
1250
- - lib/generators/avo/templates/locales/pagy/nn.yml
1251
- - lib/generators/avo/templates/locales/pagy/ro.yml
1252
1250
  - lib/generators/avo/templates/resource/controller.tt
1253
1251
  - lib/generators/avo/templates/resource/resource.tt
1254
1252
  - lib/generators/avo/templates/resource_tools/partial.tt
@@ -1,6 +0,0 @@
1
- if defined?(Pagy::I18n)
2
- if Pagy::I18n.respond_to?(:pathnames)
3
- # Load custom dictionaries that are not bundled by Pagy.
4
- Pagy::I18n.pathnames << Avo::Engine.root.join("lib", "generators", "avo", "templates", "locales", "pagy")
5
- end
6
- end
@@ -1,15 +0,0 @@
1
- nn:
2
- pagy:
3
- item_name:
4
- one: "resultat"
5
- other: "resultat"
6
- nav:
7
- prev: "&lsaquo;&nbsp;Førre"
8
- next: "Neste&nbsp;&rsaquo;"
9
- gap: "&hellip;"
10
- info:
11
- no_items: "Ingen %{item_name} funne"
12
- single_page: "Viser <b>%{count}</b> %{item_name}"
13
- multiple_pages: "Viser %{item_name} <b>%{from}-%{to}</b> av totalt <b>%{count}</b>"
14
- combo_nav_js: "<label>Side %{page_input} av %{pages}</label>"
15
- items_selector_js: "<label>Vis %{items_input} %{item_name} per side</label>"
@@ -1,17 +0,0 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
-
3
- ro:
4
- pagy:
5
- item_name:
6
- one: "un record"
7
- other: "recorduri"
8
- nav:
9
- prev: "&lsaquo;&nbsp;Înapoi"
10
- next: "Înainte&nbsp;&rsaquo;"
11
- gap: "&hellip;"
12
- info:
13
- no_items: "Nici %{item_name} găsit"
14
- single_page: "<b>%{count}</b> %{item_name}"
15
- multiple_pages: "<b>%{from}-%{to}</b> din totalul de <b>%{count}</b>"
16
- combo_nav_js: "<label>Pagina %{page_input} din %{pages}</label>"
17
- items_selector_js: "<label>Show %{items_input} %{item_name} per page</label>"