effective_resources 1.8.7 → 1.8.12

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: 79cab109b01cb0133d18f3530e8ed872c183c8e637c8279da87bbd068ddbee21
4
- data.tar.gz: 20e8cb596ab2181fde595dc430c2e57fa1396b7d91490827d496e20438f59575
3
+ metadata.gz: b61bac97524b1592c39a8b701f2c7bb0af87f9c5e882e75cbd1c2144e2284c38
4
+ data.tar.gz: 5c3d1674d1cdec588970c5358f307399c24d177300f04f81ffd8fde5e8b1e916
5
5
  SHA512:
6
- metadata.gz: b4ed96cdaf9a6fb68f51b3328fde6b38151f595f09e94fbc8943f034d0de2a9ae48a959f07c050fc77a8bfcaa8d1b6be0f671e7d23e762de51771cc58a6c8779
7
- data.tar.gz: feaa6d1027ba1b6315a922b400feab502bc1f96e545092e4d9f9284f9cd935e80e918dd2b2e93fb5b0f2391b59978aaa908c1663ec112d10c9bd3cde819c830b
6
+ metadata.gz: 9ffaaa83f17ee7dc3865da68bb1e3dbc7c9416fe68fd77c106cc51f1e9d23691cd35e1017f23428534d2001b897220d19b8daa0f27a96a004b29b8ef04aa8c91
7
+ data.tar.gz: 315828b2d06aa231f15dbae213f5dfcbc9e5721c53786e17aa10ee87d6e574f83c026c383f6f1782c08415df087b8d7a2fc7ccea828e56444cc2b173bf795bab
@@ -45,8 +45,10 @@ module Effective
45
45
  @_effective_resource ||= begin
46
46
  relation = instance_exec(&resource_scope_relation) if respond_to?(:resource_scope_relation)
47
47
 
48
- if respond_to?(:resource_scope_relation) && !relation.kind_of?(ActiveRecord::Relation)
49
- raise('resource_scope must return an ActiveRecord::Relation')
48
+ if respond_to?(:resource_scope_relation)
49
+ unless relation.kind_of?(ActiveRecord::Relation) || (relation.kind_of?(Class) && relation.ancestors.include?(ActiveModel::Model))
50
+ raise('resource_scope must return an ActiveRecord::Relation or class including ActiveModel::Model')
51
+ end
50
52
  end
51
53
 
52
54
  resource = Effective::Resource.new(controller_path, relation: relation)
@@ -94,6 +96,10 @@ module Effective
94
96
  effective_resource.klass
95
97
  end
96
98
 
99
+ def resource_human_name
100
+ effective_resource.human_name
101
+ end
102
+
97
103
  def resource_plural_name # 'things'
98
104
  effective_resource.plural_name
99
105
  end
@@ -2,7 +2,7 @@ module Effective
2
2
  module CrudController
3
3
  module Paths
4
4
 
5
- def resource_redirect_path(action = nil)
5
+ def resource_redirect_path(resource, action)
6
6
  submit = commit_action(action)
7
7
  redirect = submit[:redirect].respond_to?(:call) ? instance_exec(&submit[:redirect]) : submit[:redirect]
8
8
 
@@ -39,13 +39,29 @@ module Effective
39
39
  # Otherwise consider the action
40
40
  commit_default_redirect = case action
41
41
  when :create
42
- [resource_show_path, resource_edit_path, resource_index_path]
42
+ [
43
+ (resource_show_path if EffectiveResources.authorized?(self, :show, resource)),
44
+ (resource_edit_path if EffectiveResources.authorized?(self, :edit, resource)),
45
+ (resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
46
+ ]
43
47
  when :update
44
- [resource_edit_path, resource_show_path, resource_index_path]
48
+ [
49
+ (resource_edit_path if EffectiveResources.authorized?(self, :edit, resource)),
50
+ (resource_show_path if EffectiveResources.authorized?(self, :show, resource)),
51
+ (resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
52
+ ]
45
53
  when :destroy
46
- [referer_redirect_path, resource_index_path]
54
+ [
55
+ referer_redirect_path,
56
+ (resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
57
+ ]
47
58
  else
48
- [referer_redirect_path, resource_edit_path, resource_show_path, resource_index_path]
59
+ [
60
+ referer_redirect_path,
61
+ (resource_edit_path if EffectiveResources.authorized?(self, :edit, resource)),
62
+ (resource_show_path if EffectiveResources.authorized?(self, :show, resource)),
63
+ (resource_index_path if EffectiveResources.authorized?(self, :index, resource.class))
64
+ ]
49
65
  end.compact.first
50
66
 
51
67
  return commit_default_redirect if commit_default_redirect.present?
@@ -10,12 +10,12 @@ module Effective
10
10
  respond_to do |format|
11
11
  format.html do
12
12
  flash[:success] ||= resource_flash(:success, resource, action)
13
- redirect_to(resource_redirect_path(action))
13
+ redirect_to(resource_redirect_path(resource, action))
14
14
  end
15
15
 
16
16
  format.js do
17
17
  flash[:success] ||= resource_flash(:success, resource, action)
18
- redirect_to(resource_redirect_path(action))
18
+ render(action, locals: { remote_form_redirect: resource_redirect_path(resource, action)}) # action.js.erb
19
19
  end
20
20
  end
21
21
  elsif template_present?(action)
@@ -27,7 +27,6 @@ module Effective
27
27
 
28
28
  format.js do
29
29
  flash.now[:success] ||= resource_flash(:success, resource, action)
30
- #reload_resource unless action == :destroy # Removed.
31
30
  render(action) # action.js.erb
32
31
  end
33
32
  end
@@ -35,7 +34,7 @@ module Effective
35
34
  respond_to do |format|
36
35
  format.html do
37
36
  flash[:success] ||= resource_flash(:success, resource, action)
38
- redirect_to(resource_redirect_path(action))
37
+ redirect_to(resource_redirect_path(resource, action))
39
38
  end
40
39
 
41
40
  format.js do
@@ -61,7 +60,7 @@ module Effective
61
60
  when :destroy
62
61
  format.html do
63
62
  redirect_flash
64
- redirect_to(resource_redirect_path(action))
63
+ redirect_to(resource_redirect_path(resource, action))
65
64
  end
66
65
  else
67
66
  if template_present?(action)
@@ -73,7 +72,7 @@ module Effective
73
72
  else
74
73
  format.html do
75
74
  redirect_flash
76
- redirect_to(resource_redirect_path(action))
75
+ redirect_to(resource_redirect_path(resource, action))
77
76
  end
78
77
  end
79
78
  end
@@ -96,9 +95,7 @@ module Effective
96
95
  end
97
96
 
98
97
  def template_present?(action)
99
- #lookup_context.template_exists?("#{action}.#{request.format.symbol.to_s.sub('json', 'js').presence || 'html'}", _prefixes)
100
-
101
- formats = [request.format.symbol.to_s.sub('json', 'js').presence || 'html']
98
+ formats = [(request.format.symbol.to_s.sub('json', 'js').presence || 'html').to_sym]
102
99
  lookup_context.template_exists?(action, _prefixes, formats: formats)
103
100
  end
104
101
 
@@ -8,8 +8,10 @@ module Effective
8
8
  def flash_success(resource, action = nil, name: nil)
9
9
  raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name))
10
10
 
11
- name ||= begin
12
- resource.destroyed? ? resource.class.model_name.to_s.downcase.split('::').last : resource.to_s.presence
11
+ name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
12
+ resource_human_name
13
+ else
14
+ resource.to_s.presence || resource_human_name
13
15
  end
14
16
 
15
17
  "Successfully #{action_verb(action)} #{name || 'resource'}".html_safe
@@ -24,8 +26,10 @@ module Effective
24
26
 
25
27
  messages = flash_errors(resource, e: e)
26
28
 
27
- name ||= begin
28
- resource.destroyed? ? resource.class.model_name.to_s.downcase.split('::').last : resource.to_s.presence
29
+ name ||= if resource.respond_to?(:destroyed?) && resource.destroyed?
30
+ resource_human_name
31
+ else
32
+ resource.to_s.presence || resource_human_name
29
33
  end
30
34
 
31
35
  ["Unable to #{action}", (" #{name}" if name), (": #{messages}" if messages)].compact.join.html_safe
@@ -7,7 +7,7 @@ module Effective
7
7
  action ||= resource.respond_to?("#{step}!") ? step : :save
8
8
 
9
9
  if save_resource(resource, action)
10
- flash[:success] = options.delete(:success) || resource_flash(:success, resource, action)
10
+ flash[:success] ||= options.delete(:success) || resource_flash(:success, resource, action)
11
11
 
12
12
  @skip_to ||= next_step
13
13
  @redirect_to ||= resource_wizard_path(resource, @skip_to) if was_new_record
@@ -65,7 +65,7 @@ module ActsAsWizard
65
65
  end
66
66
 
67
67
  def has_completed_step?(step)
68
- wizard_steps[step].present?
68
+ (errors.present? ? wizard_steps_was : wizard_steps)[step].present?
69
69
  end
70
70
 
71
71
  def next_step
@@ -4,8 +4,8 @@
4
4
  EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource) %>";
5
5
  EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
6
6
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
7
+ EffectiveForm.remote_form_redirect = "<%= local_assigns[:remote_form_redirect] %>";
7
8
 
8
9
  <% if @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
9
10
  EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
10
11
  <% end %>
11
-
@@ -4,6 +4,7 @@
4
4
  EffectiveForm.remote_form_payload = '';
5
5
  EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
6
6
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
7
+ EffectiveForm.remote_form_redirect = "<%= local_assigns[:remote_form_redirect] %>";
7
8
 
8
9
  <% if @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
9
10
  EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
@@ -5,6 +5,10 @@ EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource, actio
5
5
  EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
6
6
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
7
7
 
8
+ <% if !request.get? %>
9
+ EffectiveForm.remote_form_redirect = "<%= local_assigns[:remote_form_redirect] %>";
10
+ <% end %>
11
+
8
12
  <% if !request.get? && @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
9
13
  EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
10
14
  <% end %>
@@ -4,6 +4,7 @@
4
4
  EffectiveForm.remote_form_payload = "<%= j render_resource_form(@resource) %>";
5
5
  EffectiveForm.remote_form_commit = "<%= params[:commit] %>";
6
6
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
7
+ EffectiveForm.remote_form_redirect = "<%= raw local_assigns[:remote_form_redirect] %>";
7
8
 
8
9
  <% if @resource.respond_to?(:refresh_datatables) && @resource.refresh_datatables.present? %>
9
10
  EffectiveForm.remote_form_refresh_datatables = <%= raw Array(@resource.refresh_datatables).uniq.compact.map(&:to_s) %>;
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.7'.freeze
2
+ VERSION = '1.8.12'.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.8.7
4
+ version: 1.8.12
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: 2021-03-17 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails