solidusio-contrib / solidus_importer

Solidus importer extension to migrate data from other eCommerce systems
BSD 3-Clause "New" or "Revised" License
15 stars 30 forks source link

Define ransackable_attributes for Import and Row #99

Closed malakada closed 1 week ago

malakada commented 2 months ago

With a fresh install of Solidus and the solidus_importer gem (using gem "solidus_importer", github: "solidusio-contrib/solidus_importer"), navigating to the import page in the admin GUI results in this RuntimeError:

RuntimeError in Spree::Admin::SolidusImporter::Imports#index Showing /Users/malak/.gem/ruby/3.3.2/bundler/gems/solidus_importer-109f0c1f9790/app/views/spree/admin/solidus_importer/imports/index.html.erb where line #16 raised:

Ransack needs SolidusImporter::Import attributes explicitly allowlisted as searchable. Define a ransackable_attributes class method in your SolidusImporter::Import model, watching out for items you DON'T want searchable (for example, encrypted_password, password_reset_token, owner or other sensitive information). You can use the following as a base:

class SolidusImporter::Import < ApplicationRecord

  # ...

  def self.ransackable_attributes(auth_object = nil)
    ["created_at", "file", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "id", "id_value", "import_type", "messages", "state", "updated_at"]
  end

  # ...

end

I have tested that this fix works in my environment.


When I run bundle exec rspec it says 0 examples, 0 failures so I'm not sure where to go to update the "Run specs on supported Solidus versions" that's failing on this PR.

jarednorman commented 2 months ago

Not sure why your tests aren't running, but the CI on this project is currently broken too. Do you have any idea why this is broken for you now? We use this extension on a bunch of projects and haven't run into this issue before.

malakada commented 2 months ago

No clue @jarednorman! 😅 We just did a plain fresh install and ran into it. 🤷‍♀️ I'd assume our setup is probably pretty similar to yours then.

I do find that if you use the installer directly (such as in a seed file) like SolidusImporter.import! 'path/to/file.csv', type: :thing it works just fine. It's just specifically navigating there in the browser that triggers this.

jarednorman commented 2 months ago

Yeah, that makes sense that using it directly would work. The issue is definitely with the search functionality on the admin pages.

jarednorman commented 1 week ago

Thank you! I was going to wait until CI was sorted out before merging this, but I encountered it myself on a new store and verified that your fix works.