cm-admin 1.3.1 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/cm_admin/resource_controller.rb +1 -1
- data/app/helpers/cm_admin/application_helper.rb +9 -7
- data/app/views/cm_admin/main/_actions_dropdown.html.slim +3 -3
- data/app/views/cm_admin/main/_associated_table.html.slim +4 -4
- data/app/views/cm_admin/main/_card.html.slim +2 -2
- data/app/views/cm_admin/main/_member_custom_action_modal.html.slim +1 -1
- data/app/views/cm_admin/main/_table.html.slim +2 -2
- data/app/views/cm_admin/main/_top_navbar.html.slim +5 -5
- data/app/views/layouts/_custom_action_modals.html.slim +1 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/action_dropdown_helper.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f06e165a6b468dde8b09746a40a195df154f4639626a12b4c2f856d4184abdf
|
4
|
+
data.tar.gz: 41e071501c0d1aed8bf7f1bd2ac301cc41bb6e06502abde2c39f5d3fd21e6dd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe73add42f92fc5f392cb17d16c37f5a9b6185d439ded6a51ffaff0ee5409d80074d2e5c76e0fbfdf9479a088fcfb9999079573e9ca8ff1c2a57d1216d0c5d38
|
7
|
+
data.tar.gz: a321b63a0f573d01f203045b6f89f1fc45407722c919cc164f4646ff284fdd33a3dcfc0b2e3f27c8cb00cb1e81e62c6cdfc1dfb61563e4db2234ca4632a22efe
|
data/Gemfile.lock
CHANGED
@@ -172,7 +172,7 @@ module CmAdmin
|
|
172
172
|
|
173
173
|
def resource_identifier
|
174
174
|
@ar_object, @associated_model, @associated_ar_object = custom_controller_action(action_name, params.permit!) if !@ar_object.present? && params[:id].present?
|
175
|
-
authorize
|
175
|
+
authorize @ar_object, policy_class: "CmAdmin::#{controller_name.classify}Policy".constantize if defined? "CmAdmin::#{controller_name.classify}Policy".constantize
|
176
176
|
aar_model = request.url.split('/')[-2].classify.constantize if params[:aar_id]
|
177
177
|
@associated_ar_object = aar_model.find(params[:aar_id]) if params[:aar_id]
|
178
178
|
nested_fields = get_nested_table_fields(@model.available_fields[:new])
|
@@ -6,9 +6,11 @@ module CmAdmin
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Allow if policy is not defined.
|
9
|
-
def has_valid_policy(
|
10
|
-
|
11
|
-
policy([:cm_admin,
|
9
|
+
def has_valid_policy(ar_object, action_name)
|
10
|
+
policy_object = ar_object.instance_of?(OpenStruct) ? @model.name.classify.constantize : ar_object
|
11
|
+
return true unless policy([:cm_admin, policy_object]).methods.include?(:"#{action_name}?")
|
12
|
+
|
13
|
+
policy([:cm_admin, policy_object]).send(:"#{action_name}?")
|
12
14
|
end
|
13
15
|
|
14
16
|
def action(action_name)
|
@@ -63,14 +65,14 @@ module CmAdmin
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
def is_show_action_available(model)
|
68
|
+
def is_show_action_available(model, ar_object)
|
67
69
|
model &&
|
68
70
|
model.available_actions.map(&:name).include?('show') &&
|
69
|
-
has_valid_policy(
|
71
|
+
has_valid_policy(ar_object, 'show')
|
70
72
|
end
|
71
73
|
|
72
|
-
def actions_filter(model, action_type)
|
73
|
-
model.available_actions.select { |action| action.action_type == action_type && has_valid_policy(
|
74
|
+
def actions_filter(model, ar_object, action_type)
|
75
|
+
model.available_actions.select { |action| action.action_type == action_type && has_valid_policy(ar_object, action.name) }
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
- edit_action = available_actions(cm_model, 'edit')
|
2
|
-
- destroy_action = available_actions(cm_model, 'destroy')
|
3
|
-
- custom_actions = available_actions(cm_model, 'custom_actions')
|
1
|
+
- edit_action = available_actions(cm_model, ar_object, 'edit')
|
2
|
+
- destroy_action = available_actions(cm_model, ar_object, 'destroy')
|
3
|
+
- custom_actions = available_actions(cm_model, ar_object, 'custom_actions')
|
4
4
|
- current_model = @associated_model || @model
|
5
5
|
- if custom_actions.any? || edit_action.present? || destroy_action.present?
|
6
6
|
td.row-action-cell
|
@@ -4,7 +4,7 @@
|
|
4
4
|
== render partial: 'cm_admin/main/filters', locals: { filters: @associated_model.filters }
|
5
5
|
p.table-top__total-count = "#{humanized_ar_collection_count(@associated_ar_object.pagy.count, @action.child_records.to_s)}"
|
6
6
|
.table-top__column-action
|
7
|
-
- if @associated_model && @associated_model.available_actions.map(&:name).include?('new') && has_valid_policy(@
|
7
|
+
- if @associated_model && @associated_model.available_actions.map(&:name).include?('new') && has_valid_policy(@associated_ar_object, 'new')
|
8
8
|
- association = @ar_object.class.reflect_on_all_associations.select{|x| x.name == @associated_model.name.tableize.to_sym }.first
|
9
9
|
- polymorphic_name = (association && association.inverse_of && association.inverse_of.options[:polymorphic]) ? association.inverse_of.name : ''
|
10
10
|
a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/new?associated_id=#{@ar_object.id}&associated_class=#{@ar_object.class.name.underscore}&polymorphic_name=#{polymorphic_name}&referrer=#{request.path}"
|
@@ -20,7 +20,7 @@
|
|
20
20
|
- elsif flash[:notice].present?
|
21
21
|
.alert.alert-success
|
22
22
|
= flash[:notice].html_safe
|
23
|
-
- bulk_actions = actions_filter(@associated_model, :bulk_action)
|
23
|
+
- bulk_actions = actions_filter(@associated_model, @associated_ar_object, :bulk_action)
|
24
24
|
- if bulk_actions.present?
|
25
25
|
.table-top.hidden data-section="bulk-action"
|
26
26
|
- bulk_actions.each do |action|
|
@@ -47,7 +47,7 @@
|
|
47
47
|
- if column.display_if.call(Current.user) && column.viewable
|
48
48
|
td class="text-ellipsis"
|
49
49
|
span class="#{column.field_type.to_s} #{column.cm_css_class} "
|
50
|
-
- if index == 0 && is_show_action_available(@associated_model)
|
50
|
+
- if index == 0 && is_show_action_available(@associated_model, ar_object)
|
51
51
|
a href="#{CmAdmin::Engine.mount_path}/#{@associated_model.name.tableize}/#{ar_object.id}" = show_field_value(ar_object, column)
|
52
52
|
- else
|
53
53
|
= show_field_value(ar_object, column)
|
@@ -60,4 +60,4 @@
|
|
60
60
|
.pagination-bar
|
61
61
|
p.count-text.m-0 Showing #{@associated_ar_object.pagy.from} to #{@associated_ar_object.pagy.to} out of #{@associated_ar_object.pagy.count}
|
62
62
|
== render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
|
63
|
-
= render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @associated_model, ar_collection: @associated_ar_object }
|
63
|
+
/ = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @associated_model, ar_collection: @associated_ar_object }
|
@@ -20,7 +20,7 @@
|
|
20
20
|
.alert.alert-success
|
21
21
|
= flash[:notice].html_safe
|
22
22
|
|
23
|
-
- bulk_actions = actions_filter(@model, :bulk_action)
|
23
|
+
- bulk_actions = actions_filter(@model, @ar_object, :bulk_action)
|
24
24
|
- if bulk_actions.present?
|
25
25
|
.table-top.hidden data-section="bulk-action"
|
26
26
|
- bulk_actions.each do |action|
|
@@ -38,7 +38,7 @@
|
|
38
38
|
.card-body
|
39
39
|
- @model.available_fields[:index].each_with_index do |column, index|
|
40
40
|
- if column.display_if.call(Current.user) && column.viewable
|
41
|
-
- if index == 0 && is_show_action_available(@model) && !([:link, :custom, :attachment, :drawer, :image].include?(column.field_type))
|
41
|
+
- if index == 0 && is_show_action_available(@model, ar_object) && !([:link, :custom, :attachment, :drawer, :image].include?(column.field_type))
|
42
42
|
h6.card-title
|
43
43
|
| Coffee table
|
44
44
|
.card-subtitle
|
@@ -1,4 +1,4 @@
|
|
1
|
-
- custom_actions = available_actions(cm_model, 'custom_actions')
|
1
|
+
- custom_actions = available_actions(cm_model, ar_object, 'custom_actions')
|
2
2
|
- custom_actions_modals = custom_actions.select{ |act| act if act.display_type.eql?(:modal) }
|
3
3
|
- ar_collection.data.each do |ar_object|
|
4
4
|
- if custom_actions_modals.any?
|
@@ -19,7 +19,7 @@
|
|
19
19
|
.alert.alert-success
|
20
20
|
= flash[:notice].html_safe
|
21
21
|
|
22
|
-
- bulk_actions = actions_filter(@model, :bulk_action)
|
22
|
+
- bulk_actions = actions_filter(@model, @ar_object, :bulk_action)
|
23
23
|
- if bulk_actions.present?
|
24
24
|
.table-top.hidden data-section="bulk-action"
|
25
25
|
- bulk_actions.each do |action|
|
@@ -44,7 +44,7 @@
|
|
44
44
|
- @model.available_fields[:index].each_with_index do |column, index|
|
45
45
|
- if column.display_if.call(Current.user) && column.viewable
|
46
46
|
td.text-ellipsis data-field-type="#{column.field_type || 'string'}"
|
47
|
-
- if index == 0 && is_show_action_available(@model) && !([:link, :custom, :attachment, :drawer, :image].include?(column.field_type))
|
47
|
+
- if index == 0 && is_show_action_available(@model, ar_object) && !([:link, :custom, :attachment, :drawer, :image].include?(column.field_type))
|
48
48
|
= link_to ar_object.send(column.field_name), cm_admin.send("#{ar_object.model_name.singular}_show_path", ar_object.id)
|
49
49
|
- else
|
50
50
|
= show_field_value(ar_object, column)
|
@@ -8,7 +8,7 @@
|
|
8
8
|
p.mb-0.text-body-secondary = @model.current_action.page_description
|
9
9
|
.entity-header__actions
|
10
10
|
- if @model.current_action.name == 'index'
|
11
|
-
- if has_valid_policy(@
|
11
|
+
- if has_valid_policy(@ar_object, :exportable)
|
12
12
|
.export-container
|
13
13
|
.dropdown
|
14
14
|
button.btn-secondary.dropdown-toggle data-bs-toggle='dropdown'
|
@@ -18,10 +18,10 @@
|
|
18
18
|
li
|
19
19
|
.popup-option.pointer data-bs-toggle='modal' data-bs-target='#exportmodal'
|
20
20
|
span Export
|
21
|
-
- if @model.importer && has_valid_policy(@
|
21
|
+
- if @model.importer && has_valid_policy(@ar_object, :importable)
|
22
22
|
= link_to 'Import', cm_admin.send(:"#{@model.name.underscore}_import_path"), class: 'btn-primary ms-2'
|
23
23
|
- new_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('new')}
|
24
|
-
- if new_action.any? &&
|
24
|
+
- if new_action.any? && has_valid_policy(@ar_object, 'new')
|
25
25
|
= link_to 'Add', cm_admin.send(:"#{@model.name.underscore}_new_path"), class: 'btn-primary ms-2'
|
26
26
|
- @model.available_actions.select{|act| act if act.route_type == 'collection'}.each do |custom_action|
|
27
27
|
= custom_action_items(custom_action, 'index')
|
@@ -30,8 +30,8 @@
|
|
30
30
|
= custom_action_items(custom_action, 'show')
|
31
31
|
|
32
32
|
- edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
|
33
|
-
- destroy_action = available_actions(@model, 'destroy')
|
34
|
-
- if edit_action.any? &&
|
33
|
+
- destroy_action = available_actions(@model, @ar_object, 'destroy')
|
34
|
+
- if edit_action.any? && has_valid_policy(@ar_object, 'edit')
|
35
35
|
= link_to cm_admin.send(:"#{@model.name.underscore}_edit_path", @ar_object), class: 'btn-primary ms-2' do
|
36
36
|
span
|
37
37
|
i.fa.fa-edit
|
@@ -1,6 +1,6 @@
|
|
1
1
|
- custom_action_with_modals = @model.available_actions.select{ |act| act if act.display_type == :modal && act.action_type == :custom }
|
2
2
|
- bulk_action_with_modals = @model.available_actions.select{ |act| act if act.display_type == :modal && act.action_type == :bulk_action }
|
3
|
-
- destroy_action = available_actions(@model, 'destroy')
|
3
|
+
- destroy_action = available_actions(@model, @ar_object, 'destroy')
|
4
4
|
- if @associated_model
|
5
5
|
- custom_action_with_modals += @associated_model.available_actions.select{ |act| act if act.display_type == :modal }
|
6
6
|
- if @current_action&.name == 'index'
|
data/lib/cm_admin/version.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module CmAdmin
|
2
2
|
module ViewHelpers
|
3
3
|
module ActionDropdownHelper
|
4
|
-
def available_actions(cm_model, action_type)
|
4
|
+
def available_actions(cm_model, ar_object, action_type)
|
5
5
|
if action_type.eql?('custom_actions')
|
6
6
|
cm_model.available_actions.select {
|
7
7
|
|act| act if act.route_type.eql?('member') &&
|
8
8
|
[:button, :modal].include?(act.display_type) &&
|
9
9
|
act.name.present? &&
|
10
|
-
has_valid_policy(
|
10
|
+
has_valid_policy(ar_object, act.name)
|
11
11
|
}
|
12
12
|
else
|
13
13
|
cm_model.available_actions.select {
|
14
14
|
|act| act if act.action_type.eql?(:default) &&
|
15
15
|
act.name.eql?(action_type)
|
16
|
-
} if has_valid_policy(
|
16
|
+
} if has_valid_policy(ar_object, action_type)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cm-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sajinmp
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-11-
|
13
|
+
date: 2023-11-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|