effective_resources 2.21.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 325c0f900b5e2d964f5d3bece938f7a936106d5545f7a4fa43ca84b078ad3662
4
- data.tar.gz: c97aa499db357d7f0a897ffa2118d3c8939d8f97069ed40aba7f64c215cdfdcf
3
+ metadata.gz: bf772c98b5fdf940a4fabb5138b37d2d34244f62bd6ee35b44e9d5bc2b6980d6
4
+ data.tar.gz: fc4cd66e588ccb8cc6aebe24bbb5b9101c67d1a7a667a0e8f38d2f4c83cc90ab
5
5
  SHA512:
6
- metadata.gz: 0affaea2159469810208e0f19e4ff83dbec90c236702a6a5c32a95b2f45ee3522f65eac8aa39255951eace3d7765636ee525a2cb6f955ee7e6ff64c051aa288a
7
- data.tar.gz: 55ef59912a00a3d643119e78ea9e79865807beb25c59b42a66ded59061405459e629e45e1227a33e1b7eb2f59f4758d1923ef6a1fd7337fc1f9b2754111549ed
6
+ metadata.gz: 45b9292be198f62c61313e7762930c8d5752f36223aeea93702069a5189b1c2c02b93fe8ce0061683784beddc936bf903e47cd850f25fb617c8d2e52ec938333
7
+ data.tar.gz: 24f95b7eceeb74f84b0bda8275e4a3dccd29858cee58dd2bceb8728ff215a1603705a3083d4b0d080559692f6834318f0576b279196571af74364fb4599e642c
@@ -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
@@ -102,6 +102,9 @@ module ActsAsPurchasableWizard
102
102
  # Handle effective_memberships coupon fees price reduction
103
103
  reduce_order_item_coupon_fee_price(order)
104
104
 
105
+ # Handle effective_events date delayed payments
106
+ assign_order_delayed_payment_attributes(order)
107
+
105
108
  # Hook to extend for coupon fees
106
109
  order = before_submit_order_save(order)
107
110
  raise('before_submit_order_save must return an Effective::Order') unless order.kind_of?(Effective::Order)
@@ -116,6 +119,26 @@ module ActsAsPurchasableWizard
116
119
  order
117
120
  end
118
121
 
122
+ # Override this in your wizard to enable the delayed payments
123
+ def delayed_payment_attributes
124
+ { delayed_payment: nil, delayed_payment_date: nil }
125
+ end
126
+
127
+ # This is used by effective_events and deluxe_delayed effective_orders provider
128
+ def assign_order_delayed_payment_attributes(order)
129
+ return unless order.respond_to?(:delayed_payment)
130
+
131
+ atts = delayed_payment_attributes()
132
+ return unless atts.present?
133
+
134
+ unless atts.kind_of?(Hash) && atts.key?(:delayed_payment) && atts.key?(:delayed_payment_date)
135
+ raise('expected delayed payment attributes')
136
+ end
137
+
138
+ order.assign_attributes(atts)
139
+ order
140
+ end
141
+
119
142
  # This is used by effective_memberships and effective_events
120
143
  # Which both add coupon_fees to their submit_fees
121
144
  def reduce_order_item_coupon_fee_price(order)
@@ -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.22.0'.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.22.0
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-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails