Skip to content

Commit 990ced2

Browse files
Merge pull request #499 from rootstrap/hotfix/ransack_4.0.0
Hotfix Ransack 4.0.0
2 parents 9a7c17f + 339d562 commit 990ced2

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

.reek.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ detectors:
1010
exclude: []
1111
ControlParameter:
1212
enabled: true
13-
exclude: []
13+
exclude:
14+
- 'Ransackable#ransackable_associations'
15+
- 'Ransackable#ransackable_attributes'
1416
DataClump:
1517
enabled: true
1618
exclude: []

app/models/admin_user.rb

+3
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ class AdminUser < ApplicationRecord
2929
# :confirmable, :lockable, :timeoutable and :omniauthable
3030
devise :database_authenticatable,
3131
:recoverable, :rememberable, :trackable, :validatable
32+
33+
RANSACK_ATTRIBUTES = %w[id email sign_in_count current_sign_in_at last_sign_in_at
34+
current_sign_in_ip last_sign_in_ip created_at updated_at].freeze
3235
end

app/models/application_record.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class ApplicationRecord < ActiveRecord::Base
44
include ActiveStorageSupport::SupportForBase64
5+
include Ransackable
56

67
self.abstract_class = true
78
end

app/models/concerns/ransackable.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Ransackable
4+
extend ActiveSupport::Concern
5+
6+
class_methods do
7+
def ransackable_attributes(auth_object = nil)
8+
return (column_names + ransackers.keys) if auth_object == :admin
9+
10+
const_defined?(:RANSACK_ATTRIBUTES) ? self::RANSACK_ATTRIBUTES : []
11+
end
12+
13+
def ransackable_associations(auth_object = nil)
14+
return reflect_on_all_associations.map { |association| association.name.to_s } if auth_object == :admin
15+
16+
const_defined?(:RANSACK_ASSOCIATIONS) ? self::RANSACK_ASSOCIATIONS : []
17+
end
18+
end
19+
end

app/models/setting.rb

+2
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717

1818
class Setting < ApplicationRecord
1919
validates :key, uniqueness: true, presence: true
20+
21+
RANSACK_ATTRIBUTES = %w[id key value].freeze
2022
end

app/models/user.rb

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class User < ApplicationRecord
4242

4343
before_validation :init_uid
4444

45+
RANSACK_ATTRIBUTES = %w[id email first_name last_name username sign_in_count current_sign_in_at
46+
last_sign_in_at current_sign_in_ip last_sign_in_ip provider uid
47+
created_at updated_at].freeze
48+
4549
def self.from_social_provider(provider, user_params)
4650
where(provider:, uid: user_params['id']).first_or_create! do |user|
4751
user.password = Devise.friendly_token[0, 20]

0 commit comments

Comments
 (0)