Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove name column from default ransackable attributes #3180

Conversation

mdesantis
Copy link
Contributor

Fixes #3179. name column included by default within default ransackable attributes causes ransack searches with search matchers based on name column to crash when appied on models which don’t have a name column. This PR removes the name column from default ransackable attributes and adds it explicitly on models which support search by name.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)

Fixes solidusio#3179. `name` column included by default within default
ransackable attributes causes ransack searches with search matchers
based on `name` column to crash when appied on models which don’t have a
`name` column. This PR removes the `name` column from default
ransackable attributes and adds it explicitly on models which support
search by name.
Copy link
Contributor

@aitbw aitbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work @mdesantis, thanks for working on this! 👏

@mdesantis
Copy link
Contributor Author

@kennyadsl do you think this is an important change? because previous implementation could expect default_ransack_attributes to include name? I was thinking about that

@kennyadsl
Copy link
Member

Important label is needed to mark PRs that need special attention in the Changelog. I think this could potentially break user application if they were relying on having that name attribute in the ranskack attributes, so they have to be aware that, in case they really need it, they have to re-add it manually, right?

Copy link
Member

@gmacdougall gmacdougall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This makes sense

@mdesantis
Copy link
Contributor Author

mdesantis commented Apr 17, 2019

In this PR I fixed the tested models, but if we want to be 💯% sure that the functionality remains the same for the remaining models with a name column we could add name to their whitelisted_ransackable_attributes too. Here is the models list which have a name column but don't have name within whitelisted_ransackable_attributes:

Spree::AdjustmentReason
Spree::BillingIntegration
Spree::CreditCard
Spree::Gateway
Spree::Gateway::Bogus
Spree::Gateway::BogusSimple
Spree::PaymentMethod
Spree::PaymentMethod::BogusCreditCard
Spree::PaymentMethod::Check
Spree::PaymentMethod::CreditCard
Spree::PaymentMethod::SimpleBogusCreditCard
Spree::PaymentMethod::StoreCredit
Spree::PromotionCategory
Spree::RefundReason
Spree::ReimbursementType
Spree::ReimbursementType::Credit
Spree::ReimbursementType::Exchange
Spree::ReimbursementType::OriginalPayment
Spree::ReimbursementType::StoreCredit
Spree::ReturnReason
Spree::Role
Spree::ShippingCategory
Spree::ShippingMethod
Spree::StateChange
Spree::Store
Spree::StoreCreditCategory
Spree::StoreCreditReason
Spree::StoreCreditType
Spree::TaxCategory
Spree::TaxRate

I extracted this list with the following script:

ActiveRecord::Base.descendants.select do |model|
  begin
    model.respond_to?(:whitelisted_ransackable_attributes) && 
    model.columns.any? { |column| column.name == 'name' } && (
      !model.whitelisted_ransackable_attributes ||
      !model.whitelisted_ransackable_attributes.include?('name')
    )
  rescue ActiveRecord::StatementInvalid
    false
  end
end.map(&:to_s).sort

@kennyadsl kennyadsl merged commit e49c9e2 into solidusio:master Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Several models have invalid "name" included in ransackable_attributes
5 participants