effective_resources 1.10.1 → 1.12.2

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: 536afe56ae331c14920c56f2eb625812127f0b0ad9f57696b8dce9cc198b6840
4
- data.tar.gz: 99afc3984fd065ae8014bb031ea16a9138fce77e3ec0861b140a7d18e6f5e5fd
3
+ metadata.gz: 708a6f264932790398c9a14aac69e4755d828a85510724358b3b007b18cf2acc
4
+ data.tar.gz: 6b1617fd635ca5c208b211e4c87b86a2445e0f644b493a66f95e46de615dd8b0
5
5
  SHA512:
6
- metadata.gz: dd3e83bde7a2a01e86e9588d1998249c5e1f8882bceb679e4c32d4bafbb409b419125cc7bcca2ab4fe358bce0e707f79f7f1a5f1ef4628228dc897a9c74ca510
7
- data.tar.gz: 659aab8c923fd9a5b33cb21335251c038f7af37e141c5312fea317bf0a2a9fbb2f673a12cec5b8170a3e57a50e27dcaec21a76af4b69bfdb0143ea7fdcced82b
6
+ metadata.gz: b84ed8b1ebdac3e4a342c1447be127ad5d3a68b3afcdfe01d7e8c2e5e6d54f829ba1a0908a8a783c20f43d817ca0c9abceb77c88448d731451953e7812f7031a
7
+ data.tar.gz: 8c7a42aa944f20c7a0eab0f2a9c46f37963b794e5afee932f590211a866e633a1e6349b54c3ba5ec1f61aff2b33ac7ab392dba81b69c246b3a30918b9b9d9b3a
@@ -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)
@@ -95,8 +95,6 @@ module Effective
95
95
  relation.where(is_null("#{sql_column}_id")).where(is_null("#{sql_column}_type"))
96
96
  elsif type.present? && id.present? # This was from a polymorphic select
97
97
  relation.where("#{sql_column}_id = ?", id).where("#{sql_column}_type = ?", type)
98
- elsif name == :user # Polymorphic user
99
- relation.where(search_by_associated_conditions(association, term, fuzzy: fuzzy))
100
98
  else # Maybe from a string field
101
99
  collection = relation.none
102
100
 
@@ -106,7 +104,7 @@ module Effective
106
104
  resource = Effective::Resource.new(klass_name)
107
105
  next unless resource.klass.present?
108
106
 
109
- collection = collection.or(relation.where("#{name}_id": resource.search_any(term), "#{name}_type": klass_name))
107
+ collection = collection.or(relation.where("#{name}_id": resource.search_any(term, fuzzy: fuzzy), "#{name}_type": klass_name))
110
108
  end
111
109
 
112
110
  collection
@@ -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.1'.freeze
2
+ VERSION = '1.12.2'.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: 1.10.1
4
+ version: 1.12.2
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-02-03 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