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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ gem 'flipper-ui', '~> 1.0.0' # UI for feature flags
gem 'jbuilder' # generate JSON objects
gem 'kaminari' # Pagination
gem 'paper_trail' # Track object changes
gem 'ransack', '3.2.1' # ActiveRecord search/filter
gem 'ransack', '4.0.0' # ActiveRecord search/filter
gem 'redcarpet', '~> 3.6', require: ['redcarpet', 'redcarpet/render_strip'] # Markdown to (X)HTML parser
gem 'uuidtools'
gem 'voight_kampff', '~> 2.0', require: 'voight_kampff/rails' # bot detection
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ GEM
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
ransack (3.2.1)
ransack (4.0.0)
activerecord (>= 6.1.5)
activesupport (>= 6.1.5)
i18n
Expand Down Expand Up @@ -677,7 +677,7 @@ DEPENDENCIES
puma (~> 6.3)
pundit (= 1.1.0)
rails (~> 6.1.7)
ransack (= 3.2.1)
ransack (= 4.0.0)
rdf (~> 3.2.9)
rdf-isomorphic (~> 3.2.1)
rdf-n3 (~> 3.2.1)
Expand Down
8 changes: 8 additions & 0 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ class Announcement < ApplicationRecord
scope :current, -> { where(removed_at: nil).order(created_at: :desc) }
scope :past, -> { where.not(removed_at: nil).order(removed_at: :desc) }

def self.ransackable_attributes(_auth_object = nil)
['message', 'created_at', 'removed_at']
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

end

end
8 changes: 8 additions & 0 deletions app/models/batch_ingest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ class BatchIngest < ApplicationRecord
validates :batch_ingest_files, presence: true, length: { maximum: 50 }
validates :title, presence: true, uniqueness: { case_sensitive: false }

def self.ransackable_attributes(_auth_object = nil)
['created_at', 'status', 'title']
end

def self.ransackable_associations(_auth_object = nil)
[]
end

end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ def flipper_id
"User:#{id}"
end

def self.ransackable_attributes(_auth_object = nil)
['admin', 'created_at', 'email', 'last_seen_at', 'name', 'suspended']
end

def self.ransackable_associations(_auth_object = nil)
[]
end

end
2 changes: 1 addition & 1 deletion app/views/admin/announcements/_past_announcements.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

<th><%= sort_link(@search, :removed_at, t('.removed_at')) %></th>
</tr>
</thead>
Expand Down
Loading