effective_resources 1.9.19 → 1.12.0

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: db61d9867c96af5ca8c727700ab2c453bfc05a61394640a0c625ea656fd8b2a2
4
- data.tar.gz: da861639cb20385b43db877442e77a17766b24ef416b127d211089cbe47e6879
3
+ metadata.gz: 53d143a8c98a09dcf7d4d9806ef793e973d8222de8c26f5078c9921e2ce8fdb9
4
+ data.tar.gz: bb10ee364077d022fe04717f37e5eac64576077b6f9710313d1251ed252b39a3
5
5
  SHA512:
6
- metadata.gz: 9b8d7940d66b6982338170336ae87595e7943f43ea6df15b32b12acbbe6e02904e921cfbb1ac5bcca09587955a1cdf2c3d12667121ed105aba30e3f95245ca13
7
- data.tar.gz: 13446ebdf1422b9762442ea98a0f0902a4c8ed5fb82d784ee90a5e7b46f779782ef016bdbf5902cce13bc48f2358cc38651dc594ab9b044ff06226f426ddd0e0
6
+ metadata.gz: c89341875aec7a5520151b0ec922a54f8e309219a5f53b6ddd0a4092b1fb758dfd5f1ddee7222862e9e6406102f004ed30d4e03f72c4dc6d36821c9dc0c1cd58
7
+ data.tar.gz: 6782dbdbc803c7014e90a9b674cdd0c7be8920c1802203347e3046eaa5e07e05ac988e8a8c2dbbb78478c3caedfc5cb87ab9463cbf568d34ef654d714d8468c8
@@ -35,6 +35,19 @@ 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.done?
43
+
44
+ existing = resource_scope.in_progress.where.not(id: resource).first
45
+ return unless existing.present?
46
+
47
+ flash[:success] = "You have been redirected to your in-progress wizard"
48
+ redirect_to resource_wizard_path(existing, existing.next_step)
49
+ end
50
+
38
51
  # before_action :enforce_can_visit_step, only: [:show, :update]
39
52
  # Make sure I have permission for this step
40
53
  def enforce_can_visit_step
@@ -76,6 +89,10 @@ module Effective
76
89
  resource.ready!
77
90
  end
78
91
 
92
+ def clear_flash_success
93
+ @_delete_flash_success = true
94
+ end
95
+
79
96
  end
80
97
  end
81
98
  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
@@ -0,0 +1,7 @@
1
+ !!!
2
+ %html{style: 'background: #fff;'}
3
+ %head
4
+ %meta{:content => 'text/html; charset=UTF-8', 'http-equiv' => 'Content-Type'}
5
+
6
+ %body{style: 'background: #fff;'}
7
+ = yield
@@ -21,6 +21,8 @@ EffectiveResources.setup do |config|
21
21
  # end
22
22
  config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
23
23
 
24
+ # Default Submits
25
+ #
24
26
  # These default submit actions will be added to each controller
25
27
  # and rendered when calling effective_submit(f)
26
28
  # based on the controller, and its `submits` if any.
@@ -28,4 +30,22 @@ EffectiveResources.setup do |config|
28
30
  # Supported values: 'Save', 'Continue', and 'Add New'
29
31
  config.default_submits = ['Save', 'Continue', 'Add New']
30
32
 
33
+ # Email Settings
34
+ #
35
+ # The default mailer settings for all effective gems
36
+ #
37
+ # Configure the parent class responsible to send e-mails.
38
+ # config.parent_mailer = '::ApplicationMailer'
39
+
40
+ # Default deliver method
41
+ # config.deliver_method = :deliver_later
42
+
43
+ # Default layout
44
+ # config.mailer_layout = 'effective_mailer_layout'
45
+
46
+ # Default From
47
+ config.mailer_sender = "no-reply@example.com"
48
+
49
+ # Send Admin correspondence To
50
+ config.mailer_admin = "admin@example.com"
31
51
  end
@@ -38,6 +38,16 @@ module EffectiveGem
38
38
 
39
39
  true
40
40
  end
41
+
42
+ # This is included into every gem
43
+ # The gem may not have a mailer or use effective email templates
44
+ def send_email(email, *args)
45
+ raise('gem does not respond to mailer_class') unless respond_to?(:mailer_class)
46
+ raise('expected args to be an Array') unless args.kind_of?(Array)
47
+
48
+ mailer_class.send(email, *args).send(EffectiveResources.deliver_method)
49
+ end
50
+
41
51
  end
42
52
 
43
53
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.9.19'.freeze
2
+ VERSION = '1.12.0'.freeze
3
3
  end
@@ -5,7 +5,10 @@ require 'effective_resources/effective_gem'
5
5
  module EffectiveResources
6
6
 
7
7
  def self.config_keys
8
- [:authorization_method, :default_submits]
8
+ [
9
+ :authorization_method, :default_submits,
10
+ :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :parent_mailer
11
+ ]
9
12
  end
10
13
 
11
14
  include EffectiveGem
@@ -31,6 +34,31 @@ module EffectiveResources
31
34
  (['Save', 'Continue', 'Add New'] & Array(config.default_submits)).inject({}) { |h, v| h[v] = true; h }
32
35
  end
33
36
 
37
+ # Email
38
+ def self.deliver_method
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
43
+ end
44
+
45
+ def self.mailer_layout
46
+ config[:mailer_layout] || 'effective_mailer_layout'
47
+ end
48
+
49
+ def self.mailer_sender
50
+ config[:mailer_sender] || raise('effective resources mailer_sender missing. Add it to config/initializers/effective_resources.rb')
51
+ end
52
+
53
+ def self.mailer_admin
54
+ config[:mailer_admin] || raise('effective resources mailer_admin missing. Add it to config/initializers/effective_resources.rb')
55
+ end
56
+
57
+ def self.parent_mailer_class
58
+ return config[:parent_mailer].constantize if config[:parent_mailer].present?
59
+ '::ApplicationMailer'.safe_constantize || 'ActionMailer::Base'.constantize
60
+ end
61
+
34
62
  # Utilities
35
63
 
36
64
  # This looks up the best class give the name
@@ -81,10 +109,6 @@ module EffectiveResources
81
109
  end
82
110
  end
83
111
 
84
- def self.deliver_method
85
- config = Rails.application.config
86
- (config.respond_to?(:active_job) && config.active_job.queue_adapter) ? :deliver_later : :deliver_now
87
- end
88
112
 
89
113
  def self.advance_date(date, business_days: 1, holidays: [:ca, :observed])
90
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.9.19
4
+ version: 1.12.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: 2022-01-18 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
@@ -202,6 +203,7 @@ files:
202
203
  - app/views/effective/resource/_actions.html.haml
203
204
  - app/views/effective/resource/_actions_dropleft.html.haml
204
205
  - app/views/effective/resource/_actions_glyphicons.html.haml
206
+ - app/views/layouts/effective_mailer_layout.html.haml
205
207
  - config/effective_resources.rb
206
208
  - lib/effective_resources.rb
207
209
  - lib/effective_resources/effective_gem.rb