effective_resources 2.21.0 → 2.21.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 325c0f900b5e2d964f5d3bece938f7a936106d5545f7a4fa43ca84b078ad3662
4
- data.tar.gz: c97aa499db357d7f0a897ffa2118d3c8939d8f97069ed40aba7f64c215cdfdcf
3
+ metadata.gz: e624b078e296ebd81ef3c2ba6f2678ac0fbf0b4686c4fd5ec6b8a3452566e4aa
4
+ data.tar.gz: 9f7aa12a6c35a9dffc9930187766edbceda2507c577705da7cf471d4c5f71f57
5
5
  SHA512:
6
- metadata.gz: 0affaea2159469810208e0f19e4ff83dbec90c236702a6a5c32a95b2f45ee3522f65eac8aa39255951eace3d7765636ee525a2cb6f955ee7e6ff64c051aa288a
7
- data.tar.gz: 55ef59912a00a3d643119e78ea9e79865807beb25c59b42a66ded59061405459e629e45e1227a33e1b7eb2f59f4758d1923ef6a1fd7337fc1f9b2754111549ed
6
+ metadata.gz: fe36963bfbe005989dd2f46e68cba00c051ff976a145436be023afdc233c8f9a741004d31d4364ee948fadb583e0d5fe49206362501252aa9cd6fb4bcc45d2f6
7
+ data.tar.gz: 57876da1721f9083a1b142de9471e117b03665d263a3830e9281b00721397b80d163c08b277f35b6e22f3c03117e4995630fa9bde032d45fb715acb482979c14
@@ -8,12 +8,6 @@ module Admin
8
8
  def users
9
9
  collection = current_user.class.all
10
10
 
11
- if collection.respond_to?(:to_select2)
12
- collection = collection.to_select2
13
- elsif collection.respond_to?(:sorted)
14
- collection = collection.sorted
15
- end
16
-
17
11
  respond_with_select2_ajax(collection) do |user|
18
12
  { id: user.to_param, text: user.try(:to_select2) || to_select2(user) }
19
13
  end
@@ -27,12 +21,6 @@ module Admin
27
21
 
28
22
  collection = klass.all
29
23
 
30
- if collection.respond_to?(:to_select2)
31
- collection = collection.to_select2
32
- elsif collection.respond_to?(:sorted)
33
- collection = collection.sorted
34
- end
35
-
36
24
  respond_with_select2_ajax(collection) do |organization|
37
25
  { id: organization.to_param, text: organization.try(:to_select2) || to_select2(organization) }
38
26
  end
@@ -2,7 +2,7 @@ module Effective
2
2
  module Select2AjaxController
3
3
  extend ActiveSupport::Concern
4
4
 
5
- def respond_with_select2_ajax(collection, skip_search: false, skip_authorize: false, &block)
5
+ def respond_with_select2_ajax(collection, skip_search: false, skip_authorize: false, skip_scope: false, &block)
6
6
  raise('collection should be an ActiveRecord::Relation') unless collection.kind_of?(ActiveRecord::Relation)
7
7
 
8
8
  # Authorize
@@ -15,6 +15,11 @@ module Effective
15
15
  collection = collection.sorted
16
16
  end
17
17
 
18
+ if (scope = params[:scope]).present? && !skip_scope
19
+ raise("invalid scope #{scope}") unless Effective::Resource.new(collection.klass).scope?(scope)
20
+ collection = collection.send(scope)
21
+ end
22
+
18
23
  # Search
19
24
  if (term = params[:term]).present? && !skip_search
20
25
  columns = collection.klass.new.try(:to_select2_search_columns).presence
@@ -3,6 +3,8 @@
3
3
  module Effective
4
4
  module Resources
5
5
  module Associations
6
+ INVALID_SCOPE_NAMES = ['delete_all', 'destroy_all', 'update_all', 'update_counters', 'load', 'reload', 'reset', 'to_a', 'to_sql', 'explain', 'inspect']
7
+
6
8
  def macros
7
9
  [:belongs_to, :belongs_to_polymorphic, :has_many, :has_and_belongs_to_many, :has_one]
8
10
  end
@@ -147,17 +149,23 @@ module Effective
147
149
  end
148
150
 
149
151
  def scope?(name)
152
+ return false unless name.present?
153
+
154
+ name = name.to_s
150
155
  return false unless klass.respond_to?(name)
151
156
 
157
+ return false if INVALID_SCOPE_NAMES.include?(name)
158
+ return false if name.include?('?') || name.include?('!') || name.include?('=')
159
+
152
160
  is_scope = false
153
161
 
154
162
  EffectiveResources.transaction(klass) do
155
163
  begin
156
- relation = klass.public_send(name).kind_of?(ActiveRecord::Relation)
164
+ is_scope = klass.public_send(name).kind_of?(ActiveRecord::Relation)
157
165
  rescue => e
158
166
  end
159
167
 
160
- raise ActiveRecord::Rollback
168
+ raise ActiveRecord::Rollback unless is_scope
161
169
  end
162
170
 
163
171
  is_scope
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.21.0'.freeze
2
+ VERSION = '2.21.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.21.0
4
+ version: 2.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-14 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails