Skip to content

Commit

Permalink
fix: disable select all feature when serialization raises error
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Sep 3, 2024
1 parent 2f06959 commit 8430b6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/components/avo/index/resource_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,26 @@ def before_render
prop :actions, _Nilable(_Array(Avo::BaseAction))

def encrypted_query
return :select_all_disabled if @query.nil?

# TODO: move this to the resource where we can apply the adapter pattern
if Module.const_defined?("Ransack::Search") && @query.instance_of?(Ransack::Search)
@query = @query.result
end

Avo::Services::EncryptionService.encrypt(message: @query, purpose: :select_all, serializer: Marshal)
rescue
if Rails.env.development?
Avo.error_manager.add({
url: "https://docs.avohq.io/3.0/select-all.html#serialization-known-issues",
target: "_blank",
message: "Something went wrong while serializing the query object.\n\r
Select all feature is disabled since it relies on the serialized query.\n\r
Click here for more details.\n\r"
})
end

:select_all_disabled
end

def selected_page_label
Expand Down
6 changes: 6 additions & 0 deletions spec/dummy/app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class Post < ApplicationRecord

validates :name, presence: true

# Trigger TypeError: no _dump_data is defined for class Proc when serializing query
# Test it by applying a status filter
normalizes :status, with: ->(status) {
status
}

has_one_attached :cover_photo
has_one_attached :audio
has_many_attached :attachments
Expand Down

0 comments on commit 8430b6b

Please sign in to comment.