diff --git a/Gemfile.lock b/Gemfile.lock index 82e8b3c60f..afb16a9c04 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: 4fa56814f18fd3da49c83931fa773caa727d8096 + revision: 69d904e60f78300270ecbb01e4cf68e78074b30d branch: main specs: actioncable (8.0.0.alpha) @@ -115,7 +115,7 @@ GIT PATH remote: . specs: - avo (3.10.2) + avo (3.10.5) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -166,8 +166,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -352,7 +352,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -390,7 +390,7 @@ GEM meta-tags (2.2.0) actionpack (>= 3.2.0) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) mini_portile2 (2.8.7) minitest (5.24.1) @@ -422,7 +422,7 @@ GEM orm_adapter (0.5.0) pagy (8.6.3) parallel (1.25.1) - parser (3.3.3.0) + parser (3.3.4.0) ast (~> 2.4.1) racc path_expander (1.1.1) @@ -437,7 +437,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -527,7 +527,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.0) @@ -542,7 +542,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index b719b0fe5a..f7f6bedc3a 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -89,13 +89,13 @@ def respond respond_to do |format| format.turbo_stream do - case @response[:type] + turbo_response = case @response[:type] when :keep_modal_open # Only render the flash messages if the action keeps the modal open - render turbo_stream: turbo_stream.flash_alerts + turbo_stream.flash_alerts when :download # Trigger download, removes modal and flash the messages - render turbo_stream: [ + [ turbo_stream.download(content: Base64.encode64(@response[:path]), filename: @response[:filename]), turbo_stream.close_action_modal, turbo_stream.flash_alerts @@ -104,16 +104,16 @@ def respond frame_id = Avo::ACTIONS_TURBO_FRAME_ID src, _ = @response[:action].link_arguments(resource: @action.resource, **@response[:navigate_to_action_args]) - render turbo_stream: turbo_stream.turbo_frame_set_src(frame_id, src) + turbo_stream.turbo_frame_set_src(frame_id, src) when :redirect - render turbo_stream: turbo_stream.redirect_to( + turbo_stream.redirect_to( Avo::ExecutionContext.new(target: @response[:path]).handle, turbo_frame: @response[:redirect_args][:turbo_frame], **@response[:redirect_args].except(:turbo_frame) ) when :close_modal # Close the modal and flash the messages - render turbo_stream: [ + [ turbo_stream.close_action_modal, turbo_stream.flash_alerts ] @@ -121,8 +121,16 @@ def respond # Reload the page back_path = request.referer || params[:referrer].presence || resources_path(resource: @resource) - render turbo_stream: turbo_stream.redirect_to(back_path) + turbo_stream.redirect_to(back_path) end + + responses = if @action.appended_turbo_streams.present? + Array(turbo_response) + Array(instance_exec(&@action.appended_turbo_streams)) + else + Array(turbo_response) + end + + render turbo_stream: responses end end end diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 8b7da8fea2..a53c0094ef 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -34,6 +34,13 @@ def index @query = @query.includes(*@resource.includes) end + # Eager load attachments + if @resource.attachments.present? + @resource.attachments.each do |attachment| + @query = @query.send(:"with_attached_#{attachment}") + end + end + apply_sorting # Apply filters to the current query diff --git a/app/controllers/avo/debug_controller.rb b/app/controllers/avo/debug_controller.rb index 682d2eb38f..3cea463e26 100644 --- a/app/controllers/avo/debug_controller.rb +++ b/app/controllers/avo/debug_controller.rb @@ -12,7 +12,7 @@ def send_to_hq body = params[:body] body = {license_key: license_key, body: body, payload: Avo::Services::DebugService.debug_report(request).to_json}.to_json - Avo::Licensing::Request.post url, body:, timeout: + Avo::Licensing::Request.post(url, body:, timeout:) render turbo_stream: turbo_stream.replace(:send_to_hq, plain: "Payload sent to Avo HQ.") end diff --git a/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock b/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock index 089f2b5c08..440fdaa90d 100644 --- a/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -118,8 +118,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -309,7 +309,7 @@ GEM meta-tags (2.21.0) actionpack (>= 6.0.0, < 7.2) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -393,7 +393,7 @@ GEM thor (~> 1.0) rainbow (3.1.1) rake (13.2.1) - ransack (4.1.1) + ransack (4.2.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -458,7 +458,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -473,7 +473,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock b/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock index 089f2b5c08..440fdaa90d 100644 --- a/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -118,8 +118,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -309,7 +309,7 @@ GEM meta-tags (2.21.0) actionpack (>= 6.0.0, < 7.2) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -393,7 +393,7 @@ GEM thor (~> 1.0) rainbow (3.1.1) rake (13.2.1) - ransack (4.1.1) + ransack (4.2.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -458,7 +458,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -473,7 +473,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock b/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock index 037b67c8f1..b34c175a1b 100644 --- a/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -133,8 +133,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -292,7 +292,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -330,7 +330,7 @@ GEM meta-tags (2.21.0) actionpack (>= 6.0.0, < 7.2) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -375,7 +375,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -421,7 +421,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - ransack (4.1.1) + ransack (4.2.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -489,7 +489,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -504,7 +504,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock b/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock index 037b67c8f1..b34c175a1b 100644 --- a/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock @@ -13,7 +13,7 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -133,8 +133,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -292,7 +292,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -330,7 +330,7 @@ GEM meta-tags (2.21.0) actionpack (>= 6.0.0, < 7.2) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -375,7 +375,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -421,7 +421,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - ransack (4.1.1) + ransack (4.2.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -489,7 +489,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -504,7 +504,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock b/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock index 0494e7cf4f..a8c1ecb462 100644 --- a/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock @@ -13,14 +13,13 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) activesupport (>= 6.1) addressable docile - httparty inline_svg literal (~> 0.2) meta-tags @@ -128,8 +127,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -290,7 +289,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -328,7 +327,7 @@ GEM meta-tags (2.21.0) actionpack (>= 6.0.0, < 7.2) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -372,7 +371,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -418,7 +417,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - ransack (4.1.1) + ransack (4.2.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -486,7 +485,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -501,7 +500,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock b/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock index 0494e7cf4f..a8c1ecb462 100644 --- a/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock @@ -13,14 +13,13 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) activesupport (>= 6.1) addressable docile - httparty inline_svg literal (~> 0.2) meta-tags @@ -128,8 +127,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -290,7 +289,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -328,7 +327,7 @@ GEM meta-tags (2.21.0) actionpack (>= 6.0.0, < 7.2) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -372,7 +371,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -418,7 +417,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - ransack (4.1.1) + ransack (4.2.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -486,7 +485,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -501,7 +500,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock b/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock index bef5414e41..9dc90edcf8 100644 --- a/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock +++ b/gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock @@ -17,7 +17,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: 4fa56814f18fd3da49c83931fa773caa727d8096 + revision: 69d904e60f78300270ecbb01e4cf68e78074b30d branch: main specs: actioncable (8.0.0.alpha) @@ -120,7 +120,7 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -166,8 +166,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -325,7 +325,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -364,7 +364,7 @@ GEM meta-tags (2.2.0) actionpack (>= 3.2.0) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -408,7 +408,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -496,7 +496,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -511,7 +511,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock b/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock index bef5414e41..9dc90edcf8 100644 --- a/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock +++ b/gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock @@ -17,7 +17,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: 4fa56814f18fd3da49c83931fa773caa727d8096 + revision: 69d904e60f78300270ecbb01e4cf68e78074b30d branch: main specs: actioncable (8.0.0.alpha) @@ -120,7 +120,7 @@ PATH PATH remote: .. specs: - avo (3.10.1) + avo (3.10.2) actionview (>= 6.1) active_link_to activerecord (>= 6.1) @@ -166,8 +166,8 @@ GEM avo-record_link_field (0.0.1) awesome_print (1.9.2) aws-eventstream (1.3.0) - aws-partitions (1.951.0) - aws-sdk-core (3.201.0) + aws-partitions (1.955.0) + aws-sdk-core (3.201.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -325,7 +325,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.2) - irb (1.13.2) + irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) iso (0.4.0) @@ -364,7 +364,7 @@ GEM meta-tags (2.2.0) actionpack (>= 3.2.0) method_source (1.1.0) - mini_magick (4.13.1) + mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.24.1) monetize (1.13.0) @@ -408,7 +408,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) - rack (3.1.6) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -496,7 +496,7 @@ GEM ruby-progressbar (1.13.0) ruby-vips (2.2.1) ffi (~> 1.12) - ruby_parser (3.21.0) + ruby_parser (3.21.1) racc (~> 1.5) sexp_processor (~> 4.16) rubycritic (4.9.1) @@ -511,7 +511,7 @@ GEM simplecov (>= 0.22.0) tty-which (~> 0.5.0) virtus (~> 2.0) - sexp_processor (4.17.1) + sexp_processor (4.17.2) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) diff --git a/lib/avo/base_action.rb b/lib/avo/base_action.rb index 17ab2e5d37..702080d718 100644 --- a/lib/avo/base_action.rb +++ b/lib/avo/base_action.rb @@ -21,6 +21,7 @@ class BaseAction attr_accessor :user attr_reader :arguments attr_reader :icon + attr_reader :appended_turbo_streams # TODO: find a differnet way to delegate this to the uninitialized Current variable delegate :context, to: Avo::Current @@ -291,6 +292,10 @@ def authorized? ).handle end + def append_to_response(turbo_stream) + @appended_turbo_streams = turbo_stream + end + private def add_message(body, type = :info) diff --git a/lib/avo/base_resource.rb b/lib/avo/base_resource.rb index b1113701a7..5a1d76a28b 100644 --- a/lib/avo/base_resource.rb +++ b/lib/avo/base_resource.rb @@ -48,6 +48,9 @@ def current_user class_attribute :title class_attribute :search, default: {} class_attribute :includes, default: [] + class_attribute :attachments, default: [] + class_attribute :single_includes, default: [] + class_attribute :single_attachments, default: [] class_attribute :authorization_policy class_attribute :translation_key class_attribute :default_view_type, default: :table @@ -205,9 +208,21 @@ def navigation_label end def find_record(id, query: nil, params: nil) + query ||= find_scope # If no record is given we'll use the default + + if single_includes.present? + query = query.includes(*single_includes) + end + + if single_attachments.present? + single_attachments.each do |attachment| + query = query.send(:"with_attached_#{attachment}") + end + end + Avo::ExecutionContext.new( target: find_record_method, - query: query || find_scope, # If no record is given we'll use the default + query: query, id: id, params: params ).handle diff --git a/lib/avo/version.rb b/lib/avo/version.rb index dce203747f..6d95e286a2 100644 --- a/lib/avo/version.rb +++ b/lib/avo/version.rb @@ -1,3 +1,3 @@ module Avo - VERSION = "3.10.2" unless const_defined?(:VERSION) + VERSION = "3.10.5" unless const_defined?(:VERSION) end diff --git a/lib/generators/avo/templates/resource/resource.tt b/lib/generators/avo/templates/resource/resource.tt index e05f004a40..a583f44436 100644 --- a/lib/generators/avo/templates/resource/resource.tt +++ b/lib/generators/avo/templates/resource/resource.tt @@ -1,5 +1,6 @@ class Avo::Resources::<%= resource_class %> < Avo::BaseResource - self.includes = []<%= model_class_from_args %> + # self.includes = [] + # self.attachments = []<%= model_class_from_args %> # self.search = { # query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) } # } diff --git a/spec/dummy/app/avo/actions/test/close_modal.rb b/spec/dummy/app/avo/actions/test/close_modal.rb index 7f4e3bf1fa..5a28fc98e0 100644 --- a/spec/dummy/app/avo/actions/test/close_modal.rb +++ b/spec/dummy/app/avo/actions/test/close_modal.rb @@ -9,5 +9,9 @@ def handle(**args) TestBuddy.hi "Hello from Avo::Actions::Test::CloseModal handle method" succeed "Modal closed!!" close_modal + + append_to_response -> { + turbo_stream.set_title("Cool title") + } end end diff --git a/spec/dummy/app/avo/resources/post.rb b/spec/dummy/app/avo/resources/post.rb index b74a70e5ae..e99173b743 100644 --- a/spec/dummy/app/avo/resources/post.rb +++ b/spec/dummy/app/avo/resources/post.rb @@ -7,7 +7,10 @@ class Avo::Resources::Post < Avo::BaseResource help: "- search by id, name or body" } - self.includes = [:user] + self.includes = [:user, :comments] + self.attachments = [:cover_photo, :audio, :attachments] + self.single_includes = [:user, :reviews] + self.single_attachments = [:cover_photo, :audio, :attachments] self.default_view_type = -> { mobile_user = request.user_agent =~ /Mobile/ diff --git a/spec/dummy/app/avo/resources/project.rb b/spec/dummy/app/avo/resources/project.rb index 96b228c5e9..19ea9b9cbe 100644 --- a/spec/dummy/app/avo/resources/project.rb +++ b/spec/dummy/app/avo/resources/project.rb @@ -6,7 +6,8 @@ class Avo::Resources::Project < Avo::BaseResource query.ransack(id_eq: params[:q], name_cont: params[:q], country_cont: params[:q], m: "or").result(distinct: false) } } - self.includes = [files_attachments: :blob, users: [:comments, :teams, post: [comments: :user]]] + self.includes = [users: [:comments, :teams, post: [comments: :user]]] + self.attachments = [:files] self.index_query = -> { query.unscoped } diff --git a/spec/dummy/app/avo/resources/user.rb b/spec/dummy/app/avo/resources/user.rb index 6502dd85fe..c2a758ea86 100644 --- a/spec/dummy/app/avo/resources/user.rb +++ b/spec/dummy/app/avo/resources/user.rb @@ -34,6 +34,7 @@ class Avo::Resources::User < Avo::BaseResource end } self.includes = [:posts, :post] + self.attachments = [:cv] self.devise_password_optional = true self.grid_view = { card: -> do diff --git a/spec/system/avo/actions_spec.rb b/spec/system/avo/actions_spec.rb index 18a5cbb872..700a01dc6a 100644 --- a/spec/system/avo/actions_spec.rb +++ b/spec/system/avo/actions_spec.rb @@ -210,6 +210,7 @@ fill_in "user_first_name", with: "First name should persist after action." + expect(page).to have_title("Create new user — Avocadelicious") click_on "Actions" click_on "Close modal" @@ -218,7 +219,8 @@ click_on "Run" expect(page).not_to have_selector(modal) expect(page).to have_text "Modal closed!!" - expect(page).to have_field('user_first_name', with: 'First name should persist after action.') + expect(page).to have_title("Cool title") + expect(page).to have_field("user_first_name", with: "First name should persist after action.") end end