avo 1.19.1.pre.8 → 1.20.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -2
- data/app/components/avo/index/resource_controls_component.html.erb +4 -0
- data/app/components/avo/index/resource_controls_component.rb +10 -2
- data/app/components/avo/panel_component.html.erb +4 -1
- data/app/components/avo/panel_component.rb +8 -1
- data/app/components/avo/resource_component.rb +26 -4
- data/app/components/avo/views/resource_edit_component.html.erb +6 -2
- data/app/components/avo/views/resource_index_component.html.erb +6 -4
- data/app/components/avo/views/resource_index_component.rb +20 -2
- data/app/components/avo/views/resource_new_component.html.erb +9 -2
- data/app/components/avo/views/resource_show_component.html.erb +1 -1
- data/app/components/avo/views/resource_show_component.rb +12 -1
- data/app/controllers/avo/base_controller.rb +1 -1
- data/app/controllers/avo/relations_controller.rb +5 -0
- data/config/routes.rb +1 -1
- data/db/factories.rb +8 -0
- data/lib/avo/app.rb +0 -18
- data/lib/avo/base_resource.rb +18 -1
- data/lib/avo/dynamic_router.rb +18 -0
- data/lib/avo/fields/base_field.rb +6 -0
- data/lib/avo/fields/has_base_field.rb +2 -0
- data/lib/avo/services/authorization_service.rb +8 -1
- data/lib/avo/version.rb +1 -1
- data/public/avo-assets/logo.png +0 -0
- metadata +6 -7
- data/app/assets/builds/avo.css +0 -8590
- data/app/assets/builds/avo.js +0 -87755
- data/app/assets/builds/avo.js.map +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e21fad20822df8f410cc1a6eca03d840949a4acd6bee9e47ea320927fa9c253d
|
4
|
+
data.tar.gz: 61dc6595933b686526948f1ec9f7b37dfaad833f85928609d6bc296f9d6eb694
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz: '
|
6
|
+
metadata.gz: 04c07e302dc1cd1ab911edeed99543ab93dd7b8f29ddf460dd42a85e828412b07f3a5f9fd113eeb520185f712b5586f2be89b2cc58271fe3762b26acc7cb3c73
|
7
|
+
data.tar.gz: '09968da7c74ed31cd98d3fe99ef64578bc26466b30db7d10a087ecc63424e42af2809f20c68df228637c4c54acd80e4144d35e64cb21df5d96833e14894c34f2'
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
avo (1.
|
4
|
+
avo (1.20.1)
|
5
5
|
active_link_to
|
6
6
|
addressable
|
7
7
|
breadcrumbs_on_rails
|
@@ -83,6 +83,8 @@ GEM
|
|
83
83
|
zeitwerk (~> 2.3)
|
84
84
|
addressable (2.8.0)
|
85
85
|
public_suffix (>= 2.0.2, < 5.0)
|
86
|
+
ap (0.1.1)
|
87
|
+
httparty (>= 0.7.7)
|
86
88
|
appraisal (2.4.1)
|
87
89
|
bundler
|
88
90
|
rake
|
@@ -228,7 +230,7 @@ GEM
|
|
228
230
|
mini_portile2 (~> 2.7.0)
|
229
231
|
racc (~> 1.4)
|
230
232
|
orm_adapter (0.5.0)
|
231
|
-
pagy (5.10.
|
233
|
+
pagy (5.10.1)
|
232
234
|
activesupport
|
233
235
|
parallel (1.21.0)
|
234
236
|
parser (3.1.0.0)
|
@@ -395,6 +397,7 @@ PLATFORMS
|
|
395
397
|
DEPENDENCIES
|
396
398
|
active_link_to
|
397
399
|
addressable
|
400
|
+
ap
|
398
401
|
appraisal
|
399
402
|
avo!
|
400
403
|
aws-sdk-s3
|
@@ -4,6 +4,7 @@
|
|
4
4
|
show_path,
|
5
5
|
title: t('avo.view_item', item: singular_resource_name).capitalize,
|
6
6
|
data: {
|
7
|
+
target: 'control:view',
|
7
8
|
control: :show,
|
8
9
|
'tippy': 'tooltip',
|
9
10
|
}
|
@@ -15,6 +16,7 @@
|
|
15
16
|
edit_path,
|
16
17
|
title: t('avo.edit_item', item: singular_resource_name).capitalize,
|
17
18
|
data: {
|
19
|
+
target: 'control:edit',
|
18
20
|
control: :edit,
|
19
21
|
'resource-id': @resource.model.id,
|
20
22
|
'tippy': 'tooltip',
|
@@ -30,6 +32,7 @@
|
|
30
32
|
title: t('avo.detach_item', item: singular_resource_name).capitalize,
|
31
33
|
type: :submit,
|
32
34
|
data: {
|
35
|
+
target: 'control:detach',
|
33
36
|
confirm: t('avo.are_you_sure_detach_item', item: singular_resource_name),
|
34
37
|
control: :detach,
|
35
38
|
'resource-id': @resource.model.id,
|
@@ -49,6 +52,7 @@
|
|
49
52
|
title: t('avo.delete_item', item: singular_resource_name).capitalize,
|
50
53
|
type: :submit,
|
51
54
|
data: {
|
55
|
+
target: 'control:destroy',
|
52
56
|
confirm: t('avo.are_you_sure', item: singular_resource_name),
|
53
57
|
control: :destroy,
|
54
58
|
'resource-id': @resource.model.id,
|
@@ -10,15 +10,19 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
10
10
|
def can_detach?
|
11
11
|
@reflection.present? &&
|
12
12
|
@resource.model.present? &&
|
13
|
-
|
13
|
+
is_has_many_association &&
|
14
14
|
authorize_association_for("detach")
|
15
15
|
end
|
16
16
|
|
17
17
|
def can_edit?
|
18
|
+
return authorize_association_for(:edit) if @reflection.present?
|
19
|
+
|
18
20
|
@resource.authorization.authorize_action(:edit, raise_exception: false)
|
19
21
|
end
|
20
22
|
|
21
23
|
def can_view?
|
24
|
+
return authorize_association_for(:view) if @reflection.present?
|
25
|
+
|
22
26
|
@resource.authorization.authorize_action(:show, raise_exception: false)
|
23
27
|
end
|
24
28
|
|
@@ -50,7 +54,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
50
54
|
|
51
55
|
def singular_resource_name
|
52
56
|
if @reflection.present?
|
53
|
-
|
57
|
+
reflection_resource.name
|
54
58
|
else
|
55
59
|
@resource.singular_name.present? ? @resource.singular_name : @resource.model_class.model_name.name.downcase
|
56
60
|
end
|
@@ -61,4 +65,8 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
61
65
|
|
62
66
|
::Avo::App.get_resource_by_model_name @parent_model.class
|
63
67
|
end
|
68
|
+
|
69
|
+
def is_has_many_association
|
70
|
+
@reflection.is_a?(::ActiveRecord::Reflection::HasManyReflection) || @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
|
71
|
+
end
|
64
72
|
end
|
@@ -6,9 +6,12 @@
|
|
6
6
|
<%= helpers.render_breadcrumbs(separator: helpers.svg('chevron-right', class: 'inline-block h-3 stroke-current relative top-[-1px] ml-1' )) if Avo.configuration.display_breadcrumbs %>
|
7
7
|
</div>
|
8
8
|
<% end %>
|
9
|
-
<div class="text-2xl tracking-normal font-bold text-gray-800 truncate">
|
9
|
+
<div class="text-2xl tracking-normal font-bold text-gray-800 truncate" data-target="title">
|
10
10
|
<%= @title %>
|
11
11
|
</div>
|
12
|
+
<div class="text-sm tracking-normal text-gray-600" data-target="description">
|
13
|
+
<%== description %>
|
14
|
+
</div>
|
12
15
|
</div>
|
13
16
|
|
14
17
|
<div>
|
@@ -6,8 +6,9 @@ class Avo::PanelComponent < ViewComponent::Base
|
|
6
6
|
renders_one :bare_content
|
7
7
|
renders_one :footer
|
8
8
|
|
9
|
-
def initialize(title: nil, body_classes: nil, data: {}, display_breadcrumbs: false, index: nil)
|
9
|
+
def initialize(title: nil, description: nil, body_classes: nil, data: {}, display_breadcrumbs: false, index: nil)
|
10
10
|
@title = title
|
11
|
+
@description = description
|
11
12
|
@body_classes = body_classes
|
12
13
|
@data = data
|
13
14
|
@display_breadcrumbs = display_breadcrumbs
|
@@ -25,4 +26,10 @@ class Avo::PanelComponent < ViewComponent::Base
|
|
25
26
|
def display_breadcrumbs?
|
26
27
|
@display_breadcrumbs
|
27
28
|
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
return @description if @description.present?
|
32
|
+
|
33
|
+
' '
|
34
|
+
end
|
28
35
|
end
|
@@ -1,20 +1,27 @@
|
|
1
1
|
class Avo::ResourceComponent < ViewComponent::Base
|
2
2
|
def can_create?
|
3
|
+
return authorize_association_for(:create) if @reflection.present?
|
4
|
+
|
3
5
|
@resource.authorization.authorize_action(:create, raise_exception: false)
|
4
6
|
end
|
5
7
|
|
6
8
|
def can_delete?
|
9
|
+
return authorize_association_for(:destroy) if @reflection.present?
|
10
|
+
|
7
11
|
@resource.authorization.authorize_action(:destroy, raise_exception: false)
|
8
12
|
end
|
9
13
|
|
10
14
|
def authorize_association_for(policy_method)
|
11
15
|
association_policy = true
|
16
|
+
|
12
17
|
if @reflection.present?
|
13
18
|
reflection_resource = ::Avo::App.get_resource_by_model_name(@reflection.active_record.name)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
association_name = params['related_name']
|
20
|
+
|
21
|
+
if association_name.present?
|
22
|
+
method_name = "#{policy_method}_#{association_name}?".to_sym
|
23
|
+
|
24
|
+
if reflection_resource.authorization.has_method?(method_name, raise_exception: false)
|
18
25
|
association_policy = reflection_resource.authorization.authorize_action(method_name, raise_exception: false)
|
19
26
|
end
|
20
27
|
end
|
@@ -25,7 +32,22 @@ class Avo::ResourceComponent < ViewComponent::Base
|
|
25
32
|
|
26
33
|
private
|
27
34
|
|
35
|
+
# Figure out what is the corresponding field for this @reflection
|
36
|
+
def field
|
37
|
+
fields = ::Avo::App.get_resource_by_model_name(@reflection.active_record.name).get_field_definitions
|
38
|
+
fields.find { |f| f.id == @reflection.name }
|
39
|
+
rescue
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
28
43
|
def relation_resource
|
29
44
|
::Avo::App.get_resource_by_model_name params[:via_resource_class].safe_constantize
|
30
45
|
end
|
46
|
+
|
47
|
+
# Get the resource for the resource using the klass attribute so we get the namespace too
|
48
|
+
def reflection_resource
|
49
|
+
::Avo::App.get_resource_by_model_name(@reflection.klass.to_s)
|
50
|
+
rescue
|
51
|
+
nil
|
52
|
+
end
|
31
53
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
<div data-model-id="<%= @resource.model.id %>">
|
2
2
|
<% @resource.panels.each do |resource_panel| %>
|
3
|
-
<%= form_with model: @resource.model,
|
3
|
+
<%= form_with model: @resource.model,
|
4
|
+
scope: @resource.form_scope,
|
5
|
+
url: helpers.resource_path(model: @resource.model, resource: @resource),
|
6
|
+
method: :put,
|
7
|
+
multipart: true do |form| %>
|
4
8
|
<%= hidden_field_tag :referrer, back_path if params[:via_resource_class] %>
|
5
9
|
|
6
|
-
<%= render Avo::PanelComponent.new(title: resource_panel[:name], display_breadcrumbs: true) do |c| %>
|
10
|
+
<%= render Avo::PanelComponent.new(title: resource_panel[:name], description: @resource.resource_description, display_breadcrumbs: true) do |c| %>
|
7
11
|
<% c.tools do %>
|
8
12
|
<div class="flex justify-end space-x-2">
|
9
13
|
<%= a_link back_path do %>
|
@@ -1,16 +1,18 @@
|
|
1
1
|
<div>
|
2
|
-
<%= render Avo::PanelComponent.new(title: title, body_classes: 'py-4', data: { component: 'resources-index' }, display_breadcrumbs: @reflection.blank?) do |c| %>
|
2
|
+
<%= render Avo::PanelComponent.new(title: title, description: description, body_classes: 'py-4', data: { component: 'resources-index' }, display_breadcrumbs: @reflection.blank?) do |c| %>
|
3
3
|
<% c.tools do %>
|
4
|
-
|
4
|
+
<% if can_see_the_actions_button? %>
|
5
|
+
<%= render 'actions' %>
|
6
|
+
<% end %>
|
5
7
|
|
6
8
|
<% if can_see_the_create_button? %>
|
7
|
-
<%= a_link create_path do %>
|
9
|
+
<%= a_link create_path, 'data-target': 'create' do %>
|
8
10
|
<%= svg 'plus' %> <%= t('avo.create_new_item', item: singular_resource_name.downcase ) %>
|
9
11
|
<% end %>
|
10
12
|
<% end %>
|
11
13
|
|
12
14
|
<% if can_attach? %>
|
13
|
-
<%= a_link attach_path, color: 'indigo', 'data-turbo-frame': 'attach_modal' do %>
|
15
|
+
<%= a_link attach_path, color: 'indigo', 'data-turbo-frame': 'attach_modal', 'data-target': 'attach' do %>
|
14
16
|
<%= svg 'view-grid-add' %> <%= t('avo.attach_item', item: singular_resource_name).capitalize %>
|
15
17
|
<% end %>
|
16
18
|
<% end %>
|
@@ -30,7 +30,9 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
30
30
|
|
31
31
|
def title
|
32
32
|
if @reflection.present?
|
33
|
-
|
33
|
+
return field.plural_name if field.present?
|
34
|
+
|
35
|
+
reflection_resource.plural_name
|
34
36
|
else
|
35
37
|
@resource.plural_name
|
36
38
|
end
|
@@ -47,9 +49,19 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
47
49
|
# The Create button is dependent on the new? policy method.
|
48
50
|
# The create? should be called only when the user clicks the Save button so the developers gets access to the params from the form.
|
49
51
|
def can_see_the_create_button?
|
52
|
+
return authorize_association_for("create") if @reflection.present?
|
53
|
+
|
50
54
|
@resource.authorization.authorize_action(:new, raise_exception: false) && !has_reflection_and_is_read_only
|
51
55
|
end
|
52
56
|
|
57
|
+
def can_see_the_actions_button?
|
58
|
+
return false if @actions.blank?
|
59
|
+
|
60
|
+
return authorize_association_for("act_on") if @reflection.present?
|
61
|
+
|
62
|
+
@resource.authorization.authorize_action(:act_on, raise_exception: false) && !has_reflection_and_is_read_only
|
63
|
+
end
|
64
|
+
|
53
65
|
def can_attach?
|
54
66
|
klass = @reflection
|
55
67
|
klass = @reflection.through_reflection if klass.is_a? ::ActiveRecord::Reflection::ThroughReflection
|
@@ -107,12 +119,18 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
107
119
|
|
108
120
|
def singular_resource_name
|
109
121
|
if @reflection.present?
|
110
|
-
|
122
|
+
reflection_resource.name
|
111
123
|
else
|
112
124
|
@resource.singular_name || @resource.model_class.model_name.name.downcase
|
113
125
|
end
|
114
126
|
end
|
115
127
|
|
128
|
+
def description
|
129
|
+
return if @reflection.present?
|
130
|
+
|
131
|
+
@resource.resource_description
|
132
|
+
end
|
133
|
+
|
116
134
|
private
|
117
135
|
|
118
136
|
def reflection_model_class
|
@@ -1,7 +1,14 @@
|
|
1
1
|
<div>
|
2
2
|
<% @resource.panels.each do |resource_panel| %>
|
3
|
-
<%= form_with model: @resource.model,
|
4
|
-
|
3
|
+
<%= form_with model: @resource.model,
|
4
|
+
scope: @resource.form_scope,
|
5
|
+
url: helpers.resources_path(resource: @resource,
|
6
|
+
via_relation_class: params[:via_relation_class],
|
7
|
+
via_relation: params[:via_relation],
|
8
|
+
via_resource_id: params[:via_resource_id]),
|
9
|
+
local: true,
|
10
|
+
multipart: true do |form| %>
|
11
|
+
<%= render Avo::PanelComponent.new(title: resource_panel[:name], description: @resource.resource_description, display_breadcrumbs: true) do |c| %>
|
5
12
|
<% c.tools do %>
|
6
13
|
<div class="flex justify-end space-x-2">
|
7
14
|
<%= a_link back_path do %>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
data-selected-resources='["<%= @resource.model.id %>"]'
|
4
4
|
>
|
5
5
|
<% @resource.panels.each_with_index do |resource_panel, index| %>
|
6
|
-
<%= render Avo::PanelComponent.new(title:
|
6
|
+
<%= render Avo::PanelComponent.new(title: title, description: @resource.resource_description, display_breadcrumbs: @reflection.blank?, index: index) do |c| %>
|
7
7
|
<% c.tools do %>
|
8
8
|
<% if resource_panel[:name] == @resource.default_panel_name %>
|
9
9
|
<%= render 'actions' %>
|
@@ -6,13 +6,24 @@ class Avo::Views::ResourceShowComponent < Avo::ResourceComponent
|
|
6
6
|
|
7
7
|
attr_reader :fields_by_panel, :has_one_panels, :has_many_panels, :has_as_belongs_to_many_panels
|
8
8
|
|
9
|
-
def initialize(resource: nil, reflection: nil, parent_model: nil)
|
9
|
+
def initialize(resource: nil, reflection: nil, parent_model: nil, resource_panel: nil)
|
10
10
|
@resource = resource
|
11
11
|
@reflection = reflection
|
12
|
+
@resource_panel = resource_panel
|
12
13
|
|
13
14
|
split_panel_fields
|
14
15
|
end
|
15
16
|
|
17
|
+
def title
|
18
|
+
if @reflection.present?
|
19
|
+
return field.name if field.present?
|
20
|
+
|
21
|
+
reflection_resource.name
|
22
|
+
else
|
23
|
+
@resource.panels.first[:name]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
16
27
|
def back_path
|
17
28
|
if via_resource?
|
18
29
|
helpers.resource_path(model: params[:via_resource_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
|
@@ -18,6 +18,11 @@ module Avo
|
|
18
18
|
@parent_model = @parent_resource.class.find_scope.find(params[:id])
|
19
19
|
@parent_resource.hydrate(model: @parent_model)
|
20
20
|
@query = @authorization.apply_policy @parent_model.public_send(params[:related_name])
|
21
|
+
@association_field = @parent_resource.get_field params[:related_name]
|
22
|
+
|
23
|
+
if @association_field.present? && @association_field.scope.present?
|
24
|
+
@query = @query.instance_exec(&@association_field.scope)
|
25
|
+
end
|
21
26
|
|
22
27
|
super
|
23
28
|
end
|
data/config/routes.rb
CHANGED
@@ -23,7 +23,7 @@ Avo::Engine.routes.draw do
|
|
23
23
|
|
24
24
|
# Generate resource routes as below:
|
25
25
|
# resources :posts
|
26
|
-
|
26
|
+
Avo::DynamicRouter::routes(self)
|
27
27
|
|
28
28
|
# Relations
|
29
29
|
get "/:resource_name/:id/:related_name/new", to: "relations#new", as: "associations_new"
|
data/db/factories.rb
CHANGED
data/lib/avo/app.rb
CHANGED
@@ -155,24 +155,6 @@ module Avo
|
|
155
155
|
filename
|
156
156
|
end
|
157
157
|
end
|
158
|
-
|
159
|
-
def draw_routes
|
160
|
-
# We should eager load all the classes so we find all descendants
|
161
|
-
Rails.application.eager_load!
|
162
|
-
|
163
|
-
proc do
|
164
|
-
BaseResource.descendants
|
165
|
-
.select do |resource|
|
166
|
-
resource != :BaseResource
|
167
|
-
end
|
168
|
-
.select do |resource|
|
169
|
-
resource.is_a? Class
|
170
|
-
end
|
171
|
-
.map do |resource|
|
172
|
-
resources resource.new.model_key
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
158
|
end
|
177
159
|
end
|
178
160
|
end
|
data/lib/avo/base_resource.rb
CHANGED
@@ -19,6 +19,7 @@ module Avo
|
|
19
19
|
|
20
20
|
class_attribute :id, default: :id
|
21
21
|
class_attribute :title, default: :id
|
22
|
+
class_attribute :description, default: :id
|
22
23
|
class_attribute :search_query, default: nil
|
23
24
|
class_attribute :search_query_help, default: ''
|
24
25
|
class_attribute :includes, default: []
|
@@ -154,6 +155,12 @@ module Avo
|
|
154
155
|
fields
|
155
156
|
end
|
156
157
|
|
158
|
+
def get_field(id)
|
159
|
+
get_field_definitions.find do |f|
|
160
|
+
f.id == id.to_sym
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
157
164
|
def get_grid_fields
|
158
165
|
return if self.class.grid_loader.blank?
|
159
166
|
|
@@ -224,6 +231,16 @@ module Avo
|
|
224
231
|
name
|
225
232
|
end
|
226
233
|
|
234
|
+
def resource_description
|
235
|
+
return instance_exec(&self.class.description) if self.class.description.respond_to? :call
|
236
|
+
|
237
|
+
# Show the description only on the resource index view.
|
238
|
+
# If the user wants to conditionally it on all pages, they should use a block.
|
239
|
+
if view == :index
|
240
|
+
return self.class.description if self.class.description.is_a? String
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
227
244
|
def translation_key
|
228
245
|
return "avo.resource_translations.#{class_name_without_resource.underscore}" if self.class.translation_enabled
|
229
246
|
|
@@ -442,7 +459,7 @@ module Avo
|
|
442
459
|
end
|
443
460
|
|
444
461
|
def form_scope
|
445
|
-
|
462
|
+
model_class.base_class.to_s.underscore.downcase
|
446
463
|
end
|
447
464
|
end
|
448
465
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Avo
|
2
|
+
module DynamicRouter
|
3
|
+
def self.routes(router)
|
4
|
+
Rails.application.eager_load!
|
5
|
+
|
6
|
+
BaseResource.descendants
|
7
|
+
.select do |resource|
|
8
|
+
resource != :BaseResource
|
9
|
+
end
|
10
|
+
.select do |resource|
|
11
|
+
resource.is_a? Class
|
12
|
+
end
|
13
|
+
.map do |resource|
|
14
|
+
router.resources resource.new.model_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -102,6 +102,12 @@ module Avo
|
|
102
102
|
@id.to_s.humanize(keep_id_suffix: true)
|
103
103
|
end
|
104
104
|
|
105
|
+
def plural_name
|
106
|
+
return I18n.t(translation_key, count: 2).capitalize if translation_key
|
107
|
+
|
108
|
+
name.pluralize
|
109
|
+
end
|
110
|
+
|
105
111
|
def placeholder
|
106
112
|
return @placeholder if @placeholder.present?
|
107
113
|
|
@@ -2,11 +2,13 @@ module Avo
|
|
2
2
|
module Fields
|
3
3
|
class HasBaseField < BaseField
|
4
4
|
attr_accessor :display
|
5
|
+
attr_accessor :scope
|
5
6
|
|
6
7
|
def initialize(id, **args, &block)
|
7
8
|
super(id, **args, &block)
|
8
9
|
|
9
10
|
@display = args[:display].present? ? args[:display] : :show
|
11
|
+
@scope = args[:scope].present? ? args[:scope] : nil
|
10
12
|
end
|
11
13
|
|
12
14
|
def resource
|
@@ -37,6 +37,10 @@ module Avo
|
|
37
37
|
self.class.defined_methods(user, model, **args)
|
38
38
|
end
|
39
39
|
|
40
|
+
def has_method?(method, **args)
|
41
|
+
self.class.defined_methods(user, record, **args).include? method.to_sym
|
42
|
+
end
|
43
|
+
|
40
44
|
class << self
|
41
45
|
def authorize(user, record, action, **args)
|
42
46
|
return true if skip_authorization
|
@@ -64,6 +68,9 @@ module Avo
|
|
64
68
|
def authorize_action(user, record, action, **args)
|
65
69
|
action = Avo.configuration.authorization_methods.stringify_keys[action.to_s] || action
|
66
70
|
|
71
|
+
# Add the question mark if it's missing
|
72
|
+
action = "#{action}?" unless action.end_with? '?'
|
73
|
+
|
67
74
|
return true if action.nil?
|
68
75
|
|
69
76
|
authorize user, record, action, **args
|
@@ -101,7 +108,7 @@ module Avo
|
|
101
108
|
Pundit.policy!(user, record).methods
|
102
109
|
rescue => error
|
103
110
|
if args[:raise_exception] == false
|
104
|
-
|
111
|
+
[]
|
105
112
|
else
|
106
113
|
raise error
|
107
114
|
end
|
data/lib/avo/version.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Marin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-02-
|
12
|
+
date: 2022-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -206,9 +206,6 @@ files:
|
|
206
206
|
- Gemfile.lock
|
207
207
|
- README.md
|
208
208
|
- Rakefile
|
209
|
-
- app/assets/builds/avo.css
|
210
|
-
- app/assets/builds/avo.js
|
211
|
-
- app/assets/builds/avo.js.map
|
212
209
|
- app/assets/config/avo_manifest.js
|
213
210
|
- app/assets/images/avo/logo.png
|
214
211
|
- app/assets/stylesheets/avo.css
|
@@ -583,6 +580,7 @@ files:
|
|
583
580
|
- lib/avo/base_action.rb
|
584
581
|
- lib/avo/base_resource.rb
|
585
582
|
- lib/avo/configuration.rb
|
583
|
+
- lib/avo/dynamic_router.rb
|
586
584
|
- lib/avo/engine.rb
|
587
585
|
- lib/avo/fields/badge_field.rb
|
588
586
|
- lib/avo/fields/base_field.rb
|
@@ -688,6 +686,7 @@ files:
|
|
688
686
|
- public/avo-assets/fonts/nunito-v16-latin-regular.ttf
|
689
687
|
- public/avo-assets/fonts/nunito-v16-latin-regular.woff
|
690
688
|
- public/avo-assets/fonts/nunito-v16-latin-regular.woff2
|
689
|
+
- public/avo-assets/logo.png
|
691
690
|
homepage: https://avohq.io
|
692
691
|
licenses:
|
693
692
|
- Commercial
|
@@ -708,9 +707,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
708
707
|
version: '0'
|
709
708
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
710
709
|
requirements:
|
711
|
-
- - "
|
710
|
+
- - ">="
|
712
711
|
- !ruby/object:Gem::Version
|
713
|
-
version:
|
712
|
+
version: '0'
|
714
713
|
requirements: []
|
715
714
|
rubygems_version: 3.3.3
|
716
715
|
signing_key:
|