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

Bump ransack from 3.2.1 to 4.0.0 #3235

Merged
merged 5 commits into from
Sep 22, 2023
Merged

Bump ransack from 3.2.1 to 4.0.0 #3235

merged 5 commits into from
Sep 22, 2023

Conversation

murny
Copy link
Contributor

@murny murny commented Sep 20, 2023

Context

The hardest part of this v4.0.0 upgrade was they forced you to require explict allowlisting of attributes and associations in your models for Ransack for added security. The PR for this was here: activerecord-hackery/ransack#1400

Basically we just have explicitly provide what columns and associations you can use in Ransack for your model like so:

class Example < ApplicationRecord
  def self.ransackable_attributes(auth_object = nil)
     ['example_attribute']
  end

  def self.ransackable_associations(auth_object = nil)
    ['example_association']
  end
 end

Note: Ransack is only used in our admin dashboard and on 3 screens as of today. The Batch Ingest, User and Announcement index admin screens. All these are working with these changes (even found a bug which is now fixed!). So this upgrade is relatively safe.

Bumps ransack from 3.2.1 to 4.0.0.

Release notes

Sourced from ransack's releases.

v4.0.0

💥 Breaking Changes

🚀 Features

🐛 Bug Fixes

📝 Documentation

💅 Polish

🏠 Internal

... (truncated)

Changelog

Sourced from ransack's changelog.

4.0.0 - 2023-02-09

💥 Breaking Changes

🚀 Features

🐛 Bug Fixes

📝 Documentation

💅 Polish

🏠 Internal

Commits

end

def self.ransackable_associations(_auth_object = nil)
['user']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have an association here as we use user_name which allows sorting on the User association name attribute

@@ -3,7 +3,7 @@
<tr>
<th><%= sort_link(@search, :message, t('.messsage')) %></th>
<th><%= sort_link(@search, :user_name, t('.creator')) %></th>
<th><%= sort_link(@search, :posted_at, t('.posted_at')) %></th>
<th><%= sort_link(@search, :created_at, t('.posted_at')) %></th>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Believe this was a bug? We have no column on Announcements for posted_at? I assume this should be created_at instead.

This basically wasn't doing anything before. Now its properly sorting by created at:

app      |   Announcement Load (2.1ms)  SELECT "announcements".* FROM "announcements" WHERE "announcements"."removed_at" IS NOT NULL ORDER BY "announcements"."created_at" ASC LIMIT $1 OFFSET $2  [["LIMIT", 10], ["OFFSET", 0]]

@murny murny marked this pull request as ready for review September 20, 2023 03:31
Copy link
Member

@pgwillia pgwillia left a comment

Choose a reason for hiding this comment

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

LGTM!

@murny murny merged commit 72cbdda into master Sep 22, 2023
2 checks passed
@murny murny deleted the upgrade-ransack-to-v4 branch September 22, 2023 23:54
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.

2 participants