effective_resources 0.9.1 → 0.9.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
  SHA1:
3
- metadata.gz: 35cbb54f201aa73759a5b30e40a64872edd06a90
4
- data.tar.gz: 155d1eb21e118942bf426030951ad9c0711ec264
3
+ metadata.gz: 4fbe1f0439ac8728d4c40ac89c5fc1d9360879b4
4
+ data.tar.gz: 6a61cede865aedbff717d46778ee050b824fc460
5
5
  SHA512:
6
- metadata.gz: f13b0ce467ebebdab7673f67c367118335d1894494b3c558cf9ae2486f7908c3d30c54dc380f2475cf3533212668fe27e16aee140c170ab57b8eaeec8e694d06
7
- data.tar.gz: ec7a4f34b62a61c0c3bfa800dd71e12315b03fd970378dbc2ed79d4af23ee0cb2e7bc803adaada3f5e4267af86f84feabb33c2a0b1a9ee13e0f3bc1996dafa24
6
+ metadata.gz: 860e346086622e579d8042a150f9eaed72047e4e11e3d75839b158665494db9d5f1a5a9924cdd35bd2b8eda4501ffb1eff023460955a0401b695d12b8aff31bc
7
+ data.tar.gz: 6fcb1b207a5b8c7c1804d7b3fa54e65940e31c8ddee4e21d4a65e2bc7fb97128a54a7098ec8555e01efb59525b314d01fa72ebb45b1d7d7bd5b364e00af305f1
@@ -22,8 +22,8 @@ module Effective
22
22
  # Automatically respond to any action defined via the routes file
23
23
  def define_actions_from_routes
24
24
  resource = Effective::Resource.new(controller_path)
25
- resource.member_actions.each { |action| member_action(action) }
26
- resource.collection_actions.each { |action| collection_action(action) }
25
+ (resource.member_actions - resource.crud_actions).each { |action| member_action(action) }
26
+ (resource.collection_actions - resource.crud_actions).each { |action| collection_action(action) }
27
27
  end
28
28
 
29
29
  # https://github.com/rails/rails/blob/v5.1.4/actionpack/lib/abstract_controller/callbacks.rb
@@ -65,12 +65,11 @@ module EffectiveResourcesHelper
65
65
  'effective/resource/actions'.freeze
66
66
  end + '.html'.freeze
67
67
 
68
- actions = (instance ? resource.resource_member_actions : resource.resource_collection_actions)
68
+ actions = (instance ? resource.member_get_actions : resource.collection_get_actions)
69
69
  actions = (actions & resource.crud_actions) if atts.delete(:crud)
70
- raise "unknown action for #{resource.name}: #{(atts.keys - actions).join(' ')}." if (atts.keys - actions).present?
71
70
 
71
+ raise "unknown action for #{resource.name}: #{(atts.keys - actions).join(' ')}." if (atts.keys - actions).present?
72
72
  actions = (actions - atts.reject { |_, v| v }.keys + atts.select { |_, v| v }.keys).uniq
73
- actions.select! { |action| EffectiveResources.authorized?(controller, action, (Array(instance).first || resource.klass)) }
74
73
 
75
74
  locals = { resource: instance, effective_resource: resource, namespace: namespace, actions: actions }.compact.merge(locals)
76
75
 
@@ -69,43 +69,36 @@ module Effective
69
69
  routes.keys
70
70
  end
71
71
 
72
- # Used by render_resource_actions helper
73
- # All the actions we can actually make a link to but not submits
74
- def resource_member_actions
75
- (routes.keys & [:show, :edit, :destroy]) + member_get_actions
76
- end
77
-
78
- # Used by render_resource_actions helper for the index screens or new record
79
- def resource_collection_actions
80
- (routes.keys & [:new]) + collection_get_actions
72
+ def crud_actions
73
+ actions & %i(index new create show edit update destroy)
81
74
  end
82
75
 
83
76
  # GET actions
84
77
  def collection_actions
85
- routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) }.compact - crud_actions
78
+ routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) }.compact
86
79
  end
87
80
 
88
81
  def collection_get_actions
89
- routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) && is_get_route?(route) }.compact - crud_actions
82
+ routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) && is_get_route?(route) }.compact
90
83
  end
91
84
 
92
85
  def collection_post_actions
93
- routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) && is_post_route?(route) }.compact - crud_actions
86
+ routes.values.map { |route| route.defaults[:action].to_sym if is_collection_route?(route) && is_post_route?(route) }.compact
94
87
  end
95
88
 
96
89
  # All actions
97
90
  def member_actions
98
- routes.values.map { |route| route.defaults[:action].to_sym if is_member_route?(route) }.compact - crud_actions
91
+ routes.values.map { |route| route.defaults[:action].to_sym if is_member_route?(route) }.compact
99
92
  end
100
93
 
101
94
  # GET actions
102
95
  def member_get_actions
103
- routes.values.map { |route| route.defaults[:action].to_sym if is_member_route?(route) && is_get_route?(route) }.compact - crud_actions
96
+ routes.values.map { |route| route.defaults[:action].to_sym if is_member_route?(route) && is_get_route?(route) }.compact
104
97
  end
105
98
 
106
99
  # POST/PUT/PATCH actions
107
100
  def member_post_actions
108
- routes.values.map { |route| route.defaults[:action].to_sym if is_member_route?(route) && is_post_route?(route) }.compact - crud_actions
101
+ routes.values.map { |route| route.defaults[:action].to_sym if is_member_route?(route) && is_post_route?(route) }.compact
109
102
  end
110
103
 
111
104
  # Same as controller_path in the view
@@ -115,10 +108,6 @@ module Effective
115
108
 
116
109
  private
117
110
 
118
- def crud_actions
119
- %i(index new create show edit update destroy)
120
- end
121
-
122
111
  def is_member_route?(route)
123
112
  (route.path.required_names || []).include?('id')
124
113
  end
@@ -12,7 +12,7 @@ module Effective
12
12
  submits['Save'] = { action: :save, default: true, class: 'btn btn-primary' }
13
13
  end
14
14
 
15
- member_post_actions.each do |action| # default true means it will be overwritten by dsl methods
15
+ (member_post_actions - crud_actions).each do |action| # default true means it will be overwritten by dsl methods
16
16
  submits[action.to_s.titleize] = { action: action, default: true, class: 'btn btn-primary' }
17
17
  end
18
18
 
@@ -1,22 +1,34 @@
1
1
  - if actions.index(:new)
2
- - name = effective_resource.human_name.titleize
3
- = link_to "New #{name}", effective_resource.action_path(:new), title: "New #{name}", class: 'btn btn-primary'
2
+ - if EffectiveResources.authorized?(controller, :new, effective_resource.klass)
3
+ - name = effective_resource.human_name.titleize
4
+ = link_to "New #{name}", effective_resource.action_path(:new), title: "New #{name}", class: 'btn btn-primary'
4
5
 
5
6
  - if actions.index(:edit)
6
- = link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}", class: 'btn btn-secondary'
7
+ - if EffectiveResources.authorized?(controller, :edit, resource)
8
+ = link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}", class: 'btn btn-secondary'
7
9
 
8
10
  - if actions.index(:show)
9
- = link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s, class: 'btn btn-secondary'
11
+ - if EffectiveResources.authorized?(controller, :show, resource)
12
+ = link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s, class: 'btn btn-secondary'
10
13
 
11
- - (actions - [:new, :edit, :show, :destroy]).each do |action|
14
+ - (actions - effective_resource.crud_actions).each do |action|
12
15
  - if effective_resource.member_post_actions.include?(action)
13
- = link_to action.to_s.titleize, effective_resource.action_path(action, resource), class: 'btn btn-secondary',
14
- title: "#{action} #{resource}", data: { method: :post, confirm: "#{action.to_s.titleize} #{resource}?"}
16
+ - if EffectiveResources.authorized?(controller, action, resource)
17
+ = link_to action.to_s.titleize, effective_resource.action_path(action, resource), class: 'btn btn-secondary',
18
+ title: "#{action} #{resource}", data: { method: :post, confirm: "#{action.to_s.titleize} #{resource}?"}
19
+
20
+ - elsif effective_resource.member_get_actions.include?(action)
21
+ - if EffectiveResources.authorized?(controller, action, resource)
22
+ = link_to action.to_s.titleize, effective_resource.action_path(action, resource), class: 'btn btn-secondary',
23
+ title: "#{action.to_s.titleize} #{resource}"
15
24
  - else
16
- = link_to action.to_s.titleize, effective_resource.action_path(action), class: 'btn btn-secondary', title: action.to_s.titleize
25
+ - if EffectiveResources.authorized?(controller, action, effective_resource.klass)
26
+ = link_to action.to_s.titleize, effective_resource.action_path(action), class: 'btn btn-secondary',
27
+ title: action.to_s.titleize
17
28
 
18
29
  = yield if block_given?
19
30
 
20
31
  - if actions.index(:destroy)
21
- = link_to 'Delete', effective_resource.action_path(:destroy, resource), class: 'btn btn-danger',
22
- title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
32
+ - if EffectiveResources.authorized?(controller, :destroy, resource)
33
+ = link_to 'Delete', effective_resource.action_path(:destroy, resource), class: 'btn btn-danger',
34
+ title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
@@ -1,16 +1,28 @@
1
1
  = dropdown(variation: :dropleft) do
2
2
  - if actions.index(:edit)
3
- = dropdown_link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}"
3
+ - if EffectiveResources.authorized?(controller, :edit, resource)
4
+ = dropdown_link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}"
4
5
 
5
6
  - if actions.index(:show)
6
- = dropdown_link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s
7
+ - if EffectiveResources.authorized?(controller, :show, resource)
8
+ = dropdown_link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s
7
9
 
8
- - (actions - [:edit, :show, :destroy]).each do |action|
9
- = dropdown_link_to action.to_s.titleize, effective_resource.action_path(action, resource),
10
- title: "#{action} #{resource}", data: { method: :post, confirm: "#{action.to_s.titleize} #{resource}?"}
10
+ - (actions - effective_resource.crud_actions).each do |action|
11
+ - if effective_resource.member_post_actions.include?(action)
12
+ - if EffectiveResources.authorized?(controller, action, resource)
13
+ = dropdown_link_to action.to_s.titleize, effective_resource.action_path(action, resource),
14
+ title: "#{action} #{resource}", data: { method: :post, confirm: "#{action.to_s.titleize} #{resource}?"}
15
+
16
+ - elsif effective_resource.member_get_actions.include?(action)
17
+ - if EffectiveResources.authorized?(controller, action, resource)
18
+ = dropdown_link_to action.to_s.titleize, effective_resource.action_path(action, resource), title: "#{action.to_s.titleize} #{resource}"
19
+ - else
20
+ - if EffectiveResources.authorized?(controller, action, effective_resource.klass)
21
+ = dropdown_link_to action.to_s.titleize, effective_resource.action_path(action), title: action.to_s.titleize
11
22
 
12
23
  = yield if block_given?
13
24
 
14
25
  - if actions.index(:destroy)
15
- = dropdown_link_to 'Delete', effective_resource.action_path(:destroy, resource),
16
- title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
26
+ - if EffectiveResources.authorized?(controller, :destroy, resource)
27
+ = dropdown_link_to 'Delete', effective_resource.action_path(:destroy, resource),
28
+ title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
@@ -1,8 +1,11 @@
1
1
  - if actions.index(:edit)
2
- = edit_icon_to effective_resource.action_path(:edit, resource)
2
+ - if EffectiveResources.authorized?(controller, :edit, resource)
3
+ = edit_icon_to effective_resource.action_path(:edit, resource)
3
4
 
4
5
  - if actions.index(:show)
5
- = show_icon_to effective_resource.action_path(:show, resource)
6
+ - if EffectiveResources.authorized?(controller, :show, resource)
7
+ = show_icon_to effective_resource.action_path(:show, resource)
6
8
 
7
9
  - if actions.index(:destroy)
8
- = destroy_icon_to effective_resource.action_path(:destroy, resource), data: { method: :delete, confirm: "Really delete #{resource}?" }
10
+ - if EffectiveResources.authorized?(controller, :destroy, resource)
11
+ = destroy_icon_to effective_resource.action_path(:destroy, resource), data: { method: :delete, confirm: "Really delete #{resource}?" }
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.9.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect