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 +4 -4
- data/app/controllers/concerns/effective/crud_controller.rb +2 -2
- data/app/helpers/effective_resources_helper.rb +2 -3
- data/app/models/effective/resources/actions.rb +8 -19
- data/app/models/effective/resources/forms.rb +1 -1
- data/app/views/effective/resource/_actions.html.haml +22 -10
- data/app/views/effective/resource/_actions_dropleft.html.haml +19 -7
- data/app/views/effective/resource/_actions_glyphicons.html.haml +6 -3
- data/lib/effective_resources/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fbe1f0439ac8728d4c40ac89c5fc1d9360879b4
|
4
|
+
data.tar.gz: 6a61cede865aedbff717d46778ee050b824fc460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
73
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
-
-
|
3
|
-
|
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
|
-
|
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
|
-
|
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 -
|
14
|
+
- (actions - effective_resource.crud_actions).each do |action|
|
12
15
|
- if effective_resource.member_post_actions.include?(action)
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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 -
|
9
|
-
|
10
|
-
|
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
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
10
|
+
- if EffectiveResources.authorized?(controller, :destroy, resource)
|
11
|
+
= destroy_icon_to effective_resource.action_path(:destroy, resource), data: { method: :delete, confirm: "Really delete #{resource}?" }
|