effective_resources 1.10.0 → 1.12.1

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: 0bc703e350cb8ca2e07dd5d9f0413f88bd15e98bab5d113e2696397e00af0732
4
- data.tar.gz: d40aa7078d8ce692b7c5c7991b5c5ed2c06de95b0bf3602c5253b2b19affe6e6
3
+ metadata.gz: 3db298e3e7c154dc1aa2dbec87f22bcd2fe0c20b9ab565bea13a8305f6ba04f3
4
+ data.tar.gz: 6b79e28b6b7f8f7335313d769725e16f9f6deb799bdfa29fb0b1de6c5b459b3c
5
5
  SHA512:
6
- metadata.gz: 1f5a322f0390678c9fc5834003621d73a42ab538cb3c904d942b68d44a57acb81cd5ad4601b722f8f8795e64930074ad4281a8f26baea4d798edc0b182eaa48b
7
- data.tar.gz: efcd8d06e4889a5adce7a747eb207a0abfb920ae4f46981fd4de82ddeace22eb9ff2364fe1482c99ccff71d94d0d3393e986fd10fd2c6aa74059459ac583f06a
6
+ metadata.gz: 82f53749182dc5a0f9b86c92171c0dc36eebf49fbeb874789a466143354fe28143c4d83e8caefae4b4e42f7157608ec58400f5ce4322b3609616ccf115d2235c
7
+ data.tar.gz: c388f8c66074503b1d04874419b71a5d5054ececd383d33a45087f0a17f65007fbd3f9aeb7c457c5d61ac3c36d1931a6b734756ea55ef807bd54c827e5143884
@@ -35,6 +35,20 @@ module Effective
35
35
 
36
36
  # setup_wizard from Wicked called now
37
37
 
38
+ # Allow only 1 in-progress wizard at a time
39
+ def redirect_if_existing
40
+ return if step == 'wicked_finish'
41
+ return if resource.blank?
42
+ return if resource.try(:done?)
43
+ return unless resource_scope.respond_to?(:in_progress)
44
+
45
+ existing = resource_scope.in_progress.where.not(id: resource).first
46
+ return unless existing.present?
47
+
48
+ flash[:success] = "You have been redirected to your in-progress wizard"
49
+ redirect_to resource_wizard_path(existing, existing.next_step)
50
+ end
51
+
38
52
  # before_action :enforce_can_visit_step, only: [:show, :update]
39
53
  # Make sure I have permission for this step
40
54
  def enforce_can_visit_step
@@ -76,6 +90,10 @@ module Effective
76
90
  resource.ready!
77
91
  end
78
92
 
93
+ def clear_flash_success
94
+ @_delete_flash_success = true
95
+ end
96
+
79
97
  end
80
98
  end
81
99
  end
@@ -0,0 +1,19 @@
1
+ module Effective
2
+ module WizardController
3
+ module PermittedParams
4
+ BLACKLIST = [
5
+ :created_at, :updated_at,
6
+ :token, :slug, :price,
7
+ :logged_change_ids, :orders, :purchased_order_id,
8
+ :status, :status_steps, :wizard_steps,
9
+ :submitted_at, :completed_at, :reviewed_at, :approved_at, :declined_at, :purchased_at,
10
+ :declined_reason
11
+ ]
12
+
13
+ def resource_permitted_params
14
+ permitted_name = params.key?(effective_resource.name) ? effective_resource.name : effective_resource.resource_name
15
+ params.require(permitted_name).except(BLACKLIST).permit!
16
+ end
17
+ end
18
+ end
19
+ end
@@ -7,9 +7,14 @@ module Effective
7
7
 
8
8
  include Effective::WizardController::Actions
9
9
  include Effective::WizardController::BeforeActions
10
+ include Effective::WizardController::PermittedParams
10
11
  include Effective::WizardController::Save
11
12
  include Effective::WizardController::WickedOverrides
12
13
 
14
+ module ClassMethods
15
+ def effective_wizard_controller?; true; end
16
+ end
17
+
13
18
  included do
14
19
  raise("please install gem 'wicked' to use Effective::WizardController") unless defined?(Wicked)
15
20
 
@@ -19,10 +24,14 @@ module Effective
19
24
  before_action :assign_resource
20
25
  before_action :authorize_resource
21
26
  before_action :assign_required_steps
27
+
22
28
  before_action :setup_wizard # Wicked
23
29
 
24
30
  before_action :enforce_can_visit_step
25
31
 
32
+ before_action :redirect_if_existing, only: [:show, :new]
33
+ before_action :clear_flash_success, only: [:update]
34
+
26
35
  before_action :assign_current_step
27
36
  before_action :assign_page_title
28
37
 
@@ -38,6 +47,12 @@ module Effective
38
47
  flash[:danger] = "Unknown step. You have been moved to the #{resource_wizard_steps.first} step."
39
48
  redirect_to wizard_path(resource_wizard_steps.first)
40
49
  end
50
+
51
+ # effective_resources on save callback
52
+ after_action do
53
+ flash.clear if @_delete_flash_success
54
+ end
55
+
41
56
  end
42
57
 
43
58
  def find_wizard_resource
@@ -244,4 +244,8 @@ module EffectiveResourcesHelper
244
244
  simple_format(sanitize(value.to_s, tags: @format_resource_tags, attributes: @format_resource_atts), {}, sanitize: false)
245
245
  end
246
246
 
247
+ def edit_effective_wizard?
248
+ controller.class.try(:effective_wizard_controller?) && defined?(resource) && resource.draft?
249
+ end
250
+
247
251
  end
@@ -59,6 +59,12 @@ module ActsAsWizard
59
59
  wizard_step_keys()
60
60
  end
61
61
 
62
+ # For use in the summary partials. Does not include summary.
63
+ def render_steps
64
+ blacklist = [:start, :billing, :checkout, :submitted, :summary]
65
+ (required_steps - blacklist).select { |step| has_completed_step?(step) }
66
+ end
67
+
62
68
  def wizard_step_title(step)
63
69
  self.class.const_get(:WIZARD_STEPS).fetch(step)
64
70
  end
@@ -134,6 +140,11 @@ module ActsAsWizard
134
140
 
135
141
  module ClassMethods
136
142
  def acts_as_wizard?; true; end
143
+
144
+ def all_wizard_steps
145
+ const_get(:WIZARD_STEPS).keys
146
+ end
147
+
137
148
  end
138
149
 
139
150
  end
@@ -28,8 +28,10 @@ module Effective
28
28
  def self.register_callback(connection:, name:, callback:)
29
29
  raise ArgumentError, "#{name} expected a block" unless callback
30
30
 
31
- raise("#{name} is useless outside transaction") unless connection.transaction_open?
32
- raise("#{name} is useless outside transaction") unless connection.current_transaction.joinable?
31
+ in_transaction = (connection.transaction_open? && connection.current_transaction.joinable?)
32
+
33
+ # Execute immediately when outside transaction
34
+ return callback.call unless in_transaction
33
35
 
34
36
  after_commit = Effective::AfterCommit.new("#{name}": callback)
35
37
  connection.add_transaction_record(after_commit)
@@ -38,7 +38,7 @@ EffectiveResources.setup do |config|
38
38
  # config.parent_mailer = '::ApplicationMailer'
39
39
 
40
40
  # Default deliver method
41
- # config.deliver_method = :deliver_now
41
+ # config.deliver_method = :deliver_later
42
42
 
43
43
  # Default layout
44
44
  # config.mailer_layout = 'effective_mailer_layout'
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.10.0'.freeze
2
+ VERSION = '1.12.1'.freeze
3
3
  end
@@ -36,7 +36,10 @@ module EffectiveResources
36
36
 
37
37
  # Email
38
38
  def self.deliver_method
39
- config[:deliver_method] || :deliver_now
39
+ return config[:deliver_method] if config[:deliver_method].present?
40
+
41
+ rails = Rails.application.config
42
+ (rails.respond_to?(:active_job) && rails.active_job.queue_adapter) ? :deliver_later : :deliver_now
40
43
  end
41
44
 
42
45
  def self.mailer_layout
@@ -106,10 +109,6 @@ module EffectiveResources
106
109
  end
107
110
  end
108
111
 
109
- def self.deliver_method
110
- config = Rails.application.config
111
- (config.respond_to?(:active_job) && config.active_job.queue_adapter) ? :deliver_later : :deliver_now
112
- end
113
112
 
114
113
  def self.advance_date(date, business_days: 1, holidays: [:ca, :observed])
115
114
  raise('business_days must be an integer <= 365') unless business_days.kind_of?(Integer) && business_days <= 365
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: 1.10.0
4
+ version: 1.12.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: 2022-01-24 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -145,6 +145,7 @@ files:
145
145
  - app/controllers/concerns/effective/wizard_controller.rb
146
146
  - app/controllers/concerns/effective/wizard_controller/actions.rb
147
147
  - app/controllers/concerns/effective/wizard_controller/before_actions.rb
148
+ - app/controllers/concerns/effective/wizard_controller/permitted_params.rb
148
149
  - app/controllers/concerns/effective/wizard_controller/save.rb
149
150
  - app/controllers/concerns/effective/wizard_controller/wicked_overrides.rb
150
151
  - app/helpers/effective_acts_as_email_form_helper.rb