avo 2.11.1.pre.3 → 2.11.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.lock +1 -1
- data/app/assets/stylesheets/avo.css +4 -1
- data/app/components/avo/fields/date_field/show_component.html.erb +0 -4
- data/app/components/avo/fields/has_one_field/show_component.html.erb +1 -1
- data/app/components/avo/fields/has_one_field/show_component.rb +6 -7
- data/app/components/avo/fields/text_field/index_component.html.erb +0 -2
- data/app/components/avo/fields/text_field/show_component.html.erb +0 -2
- data/app/components/avo/index/field_wrapper_component.html.erb +0 -4
- data/app/components/avo/index/resource_controls_component.rb +5 -7
- data/app/components/avo/index/resource_table_component.html.erb +1 -1
- data/app/components/avo/index/resource_table_component.rb +1 -2
- data/app/components/avo/index/table_row_component.html.erb +1 -1
- data/app/components/avo/index/table_row_component.rb +1 -2
- data/app/components/avo/resource_component.rb +5 -11
- data/app/components/avo/sidebar_component.html.erb +2 -2
- data/app/components/avo/tab_switcher_component.rb +0 -4
- data/app/components/avo/views/resource_edit_component.rb +6 -4
- data/app/components/avo/views/resource_index_component.html.erb +1 -1
- data/app/components/avo/views/resource_index_component.rb +3 -5
- data/app/components/avo/views/resource_show_component.html.erb +1 -1
- data/app/components/avo/views/resource_show_component.rb +1 -3
- data/app/controllers/avo/application_controller.rb +9 -24
- data/app/controllers/avo/associations_controller.rb +12 -38
- data/app/controllers/avo/base_controller.rb +1 -2
- data/app/javascript/js/controllers/mobile_controller.js +9 -0
- data/app/javascript/js/controllers.js +2 -2
- data/app/views/avo/base/index.html.erb +0 -1
- data/app/views/avo/base/show.html.erb +1 -7
- data/app/views/avo/partials/_javascript.html.erb +0 -1
- data/app/views/avo/partials/_navbar.html.erb +2 -5
- data/app/views/layouts/avo/application.html.erb +3 -3
- data/lib/avo/concerns/has_fields.rb +0 -5
- data/lib/avo/concerns/has_html_attributes.rb +1 -1
- data/lib/avo/fields/has_base_field.rb +0 -11
- data/lib/avo/fields/text_field.rb +2 -4
- data/lib/avo/services/authorization_service.rb +37 -41
- data/lib/avo/version.rb +1 -1
- data/lib/avo.rb +0 -1
- data/public/avo-assets/avo.css +11 -43
- data/public/avo-assets/avo.js +67 -68
- data/public/avo-assets/avo.js.map +3 -3
- metadata +5 -6
- data/app/assets/stylesheets/css/sidebar.css +0 -28
- data/app/javascript/js/controllers/sidebar_controller.js +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11bec5c585fbc251c7b9179b2494d3d05d7e52c8d1d26aa1113552f90e448bea
|
4
|
+
data.tar.gz: 66c973b9884dd4bf734a45ae957e572ecdc3c1bcf55056d5538907f52c356c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42fd910ec4e63622c2693e52a5bab127c1e46d0ce4f59f1c3e4507bd186f63fe8563b8b5ce2d65a84823b8e96cbb6c804e3df0db9e50444e507f84655b1e8bcb
|
7
|
+
data.tar.gz: b66101cb139f742cff2856ab83081280096325aeb421ac4698d9542c8b5bd985313f91db43a7454ac1dbb05ec30de384bb447df49693c140a6ff3db705f05b11
|
data/Gemfile.lock
CHANGED
@@ -16,7 +16,6 @@
|
|
16
16
|
@import './css/breadcrumbs.css';
|
17
17
|
@import './css/search.css';
|
18
18
|
@import './css/active-storage.css';
|
19
|
-
@import './css/sidebar.css';
|
20
19
|
@import './css/spinner.css';
|
21
20
|
@import './css/tags.css';
|
22
21
|
|
@@ -70,6 +69,10 @@ body {
|
|
70
69
|
@apply opacity-0 translate-y-1;
|
71
70
|
}
|
72
71
|
|
72
|
+
.application-sidebar .active:hover,
|
73
|
+
.application-sidebar .active {
|
74
|
+
@apply bg-blue-100 text-blue-500;
|
75
|
+
}
|
73
76
|
|
74
77
|
.turbo-progress-bar {
|
75
78
|
@apply bg-blue-400;
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<% c.tools do %>
|
8
8
|
<% if !@field.readonly && can_attach? %>
|
9
9
|
<%= a_link attach_path, icon: 'heroicons/outline/link', color: :primary, 'data-turbo-frame': 'attach_modal' do %>
|
10
|
-
<%= t('avo.attach_item', item: @field.name
|
10
|
+
<%= t('avo.attach_item', item: @field.name) %>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
13
13
|
<% end %>
|
@@ -4,20 +4,19 @@ class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
|
|
4
4
|
include Avo::ApplicationHelper
|
5
5
|
|
6
6
|
def can_attach?
|
7
|
-
|
8
|
-
|
7
|
+
attach_policy = true
|
9
8
|
if @field.present?
|
10
9
|
reflection_resource = @field.target_resource
|
11
10
|
if reflection_resource.present? && @resource.present?
|
12
|
-
method_name = "attach_#{
|
11
|
+
method_name = ("attach_#{reflection_resource.model_key}?").to_sym
|
12
|
+
defined_policy_methods = @resource.authorization.defined_methods(@resource.model_class, raise_exception: false)
|
13
13
|
|
14
|
-
if
|
15
|
-
|
14
|
+
if defined_policy_methods.present? && defined_policy_methods.include?(method_name)
|
15
|
+
attach_policy = @resource.authorization.authorize_action(method_name, raise_exception: false)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
policy_result
|
19
|
+
attach_policy
|
21
20
|
end
|
22
21
|
|
23
22
|
def attach_path
|
@@ -1,8 +1,6 @@
|
|
1
1
|
<%= index_field_wrapper field: @field, resource: @resource do %>
|
2
2
|
<% if @field.as_html %>
|
3
3
|
<%== @field.value %>
|
4
|
-
<% elsif @field.protocol.present? %>
|
5
|
-
<%= link_to @field.value, "#{@field.protocol}:#{@field.value}" %>
|
6
4
|
<% else %>
|
7
5
|
<%= link_to_if @field.link_to_resource, @field.value, resource_path %>
|
8
6
|
<% end %>
|
@@ -1,8 +1,6 @@
|
|
1
1
|
<%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
|
2
2
|
<% if @field.as_html %>
|
3
3
|
<%== @field.value %>
|
4
|
-
<% elsif @field.protocol.present? %>
|
5
|
-
<%= link_to @field.value, "#{@field.protocol}:#{@field.value}" %>
|
6
4
|
<% else %>
|
7
5
|
<%= @field.value %>
|
8
6
|
<% end %>
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
4
|
-
def initialize(resource: nil, reflection: nil, parent_model: nil,
|
4
|
+
def initialize(resource: nil, reflection: nil, parent_model: nil, view_type: :table)
|
5
5
|
@resource = resource
|
6
6
|
@reflection = reflection
|
7
7
|
@parent_model = parent_model
|
8
|
-
@parent_resource = parent_resource
|
9
8
|
@view_type = view_type
|
10
9
|
end
|
11
10
|
|
@@ -13,7 +12,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
13
12
|
@reflection.present? &&
|
14
13
|
@resource.model.present? &&
|
15
14
|
is_has_many_association &&
|
16
|
-
authorize_association_for(
|
15
|
+
authorize_association_for("detach")
|
17
16
|
end
|
18
17
|
|
19
18
|
def can_edit?
|
@@ -23,9 +22,8 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def can_view?
|
26
|
-
return authorize_association_for(:
|
25
|
+
return authorize_association_for(:view) if @reflection.present?
|
27
26
|
|
28
|
-
# Even if there's a @reflection object present, for show we're going to fallback to the original policy.
|
29
27
|
@resource.authorization.authorize_action(:show, raise_exception: false)
|
30
28
|
end
|
31
29
|
|
@@ -44,7 +42,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
44
42
|
|
45
43
|
def edit_path
|
46
44
|
# Add the `view` param to let Avo know where to redirect back when the user clicks the `Cancel` button.
|
47
|
-
args = {via_view:
|
45
|
+
args = {via_view: 'index'}
|
48
46
|
|
49
47
|
if @parent_model.present?
|
50
48
|
args = {
|
@@ -75,6 +73,6 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
|
|
75
73
|
end
|
76
74
|
|
77
75
|
def referrer_path
|
78
|
-
Avo::App.root_path(paths: [
|
76
|
+
Avo::App.root_path(paths: ['resources', params[:resource_name], params[:id], params[:related_name]], query: request.query_parameters.to_h)
|
79
77
|
end
|
80
78
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<tbody class="divide-y">
|
5
5
|
<% @resources.each_with_index do |resource, index| %>
|
6
6
|
<% cache_if Avo.configuration.cache_resources_on_index_view, resource.cache_hash(@parent_model), expires_in: 1.day do %>
|
7
|
-
<%= render Avo::Index::TableRowComponent.new(resource: resource, reflection: @reflection, parent_model: @parent_model
|
7
|
+
<%= render Avo::Index::TableRowComponent.new(resource: resource, reflection: @reflection, parent_model: @parent_model) %>
|
8
8
|
<% end %>
|
9
9
|
<% end %>
|
10
10
|
</tbody>
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Avo::Index::ResourceTableComponent < ViewComponent::Base
|
4
|
-
def initialize(resources: nil, resource: nil, reflection: nil, parent_model: nil
|
4
|
+
def initialize(resources: nil, resource: nil, reflection: nil, parent_model: nil)
|
5
5
|
@resources = resources
|
6
6
|
@resource = resource
|
7
7
|
@reflection = reflection
|
8
8
|
@parent_model = parent_model
|
9
|
-
@parent_resource = parent_resource
|
10
9
|
end
|
11
10
|
end
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<% end %>
|
15
15
|
<td class="text-right whitespace-nowrap px-2">
|
16
16
|
<div class="flex items-center justify-end flex-grow-0 h-full w-full">
|
17
|
-
<%= render(Avo::Index::ResourceControlsComponent.new(resource: @resource, reflection: @reflection, parent_model: @parent_model,
|
17
|
+
<%= render(Avo::Index::ResourceControlsComponent.new(resource: @resource, reflection: @reflection, parent_model: @parent_model, view_type: :table)) %>
|
18
18
|
</div>
|
19
19
|
</td>
|
20
20
|
</tr>
|
@@ -3,10 +3,9 @@
|
|
3
3
|
class Avo::Index::TableRowComponent < ViewComponent::Base
|
4
4
|
include Avo::ResourcesHelper
|
5
5
|
|
6
|
-
def initialize(resource: nil, reflection: nil, parent_model: nil
|
6
|
+
def initialize(resource: nil, reflection: nil, parent_model: nil)
|
7
7
|
@resource = resource
|
8
8
|
@reflection = reflection
|
9
9
|
@parent_model = parent_model
|
10
|
-
@parent_resource = parent_resource
|
11
10
|
end
|
12
11
|
end
|
@@ -39,29 +39,23 @@ class Avo::ResourceComponent < Avo::BaseComponent
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def authorize_association_for(policy_method)
|
42
|
-
|
42
|
+
association_policy = true
|
43
43
|
|
44
44
|
if @reflection.present?
|
45
|
-
# Fetch the appropiate resource
|
46
45
|
reflection_resource = ::Avo::App.get_resource_by_model_name(@reflection.active_record.name)
|
47
|
-
# Fetch the model
|
48
|
-
# Hydrate the resource with the model if we have one
|
49
46
|
reflection_resource.hydrate(model: @parent_model) if @parent_model.present?
|
50
|
-
|
51
|
-
association_name = @reflection.name
|
47
|
+
association_name = params["related_name"]
|
52
48
|
|
53
49
|
if association_name.present?
|
54
50
|
method_name = "#{policy_method}_#{association_name}?".to_sym
|
55
|
-
# Prepare the authorization service
|
56
|
-
service = reflection_resource.authorization
|
57
51
|
|
58
|
-
if
|
59
|
-
|
52
|
+
if reflection_resource.authorization.has_method?(method_name, raise_exception: false)
|
53
|
+
association_policy = reflection_resource.authorization.authorize_action(method_name, raise_exception: false)
|
60
54
|
end
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
64
|
-
|
58
|
+
association_policy
|
65
59
|
end
|
66
60
|
|
67
61
|
def main_panel
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div
|
2
|
-
class="
|
3
|
-
data-
|
2
|
+
class="fixed z-[60] t-0 application-sidebar w-64 hidden lg:flex flex-1 border-r lg:border-none bg-none h-[calc(100vh-4rem)] bg-gray-25 lg:bg-transparent <%= 'print:hidden' if Avo.configuration.hide_layout_when_printing %>"
|
3
|
+
data-mobile-target="sidebar"
|
4
4
|
>
|
5
5
|
<div class="flex flex-col w-full h-full">
|
6
6
|
<div class="flex-1 flex flex-col justify-between overflow-auto h-full pt-3 scroll-shadows">
|
@@ -22,10 +22,12 @@ class Avo::Views::ResourceEditComponent < Avo::ResourceComponent
|
|
22
22
|
helpers.resource_path(model: params[:via_resource_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
|
23
23
|
elsif via_index?
|
24
24
|
helpers.resources_path(resource: @resource)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
else # via resource show page
|
26
|
+
if is_edit?
|
27
|
+
helpers.resource_path(model: @resource.model, resource: @resource)
|
28
|
+
else
|
29
|
+
helpers.resources_path(resource: @resource)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -51,7 +51,7 @@
|
|
51
51
|
<% if @resources.present? %>
|
52
52
|
<div class="w-full overflow-auto flex flex-col mt-0">
|
53
53
|
<div class="relative flex-1 flex">
|
54
|
-
<%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model
|
54
|
+
<%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model)) %>
|
55
55
|
</div>
|
56
56
|
</div>
|
57
57
|
<% else %>
|
@@ -15,7 +15,6 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
15
15
|
reflection: nil,
|
16
16
|
turbo_frame: "",
|
17
17
|
parent_model: nil,
|
18
|
-
parent_resource: nil,
|
19
18
|
applied_filters: []
|
20
19
|
)
|
21
20
|
@resource = resource
|
@@ -28,7 +27,6 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
28
27
|
@reflection = reflection
|
29
28
|
@turbo_frame = turbo_frame
|
30
29
|
@parent_model = parent_model
|
31
|
-
@parent_resource = parent_resource
|
32
30
|
@applied_filters = applied_filters
|
33
31
|
@view = :index
|
34
32
|
end
|
@@ -54,7 +52,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
54
52
|
# The Create button is dependent on the new? policy method.
|
55
53
|
# The create? should be called only when the user clicks the Save button so the developers gets access to the params from the form.
|
56
54
|
def can_see_the_create_button?
|
57
|
-
return authorize_association_for(
|
55
|
+
return authorize_association_for("create") if @reflection.present?
|
58
56
|
|
59
57
|
@resource.authorization.authorize_action(:new, raise_exception: false) && !has_reflection_and_is_read_only
|
60
58
|
end
|
@@ -62,7 +60,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
62
60
|
def can_see_the_actions_button?
|
63
61
|
return false if @actions.blank?
|
64
62
|
|
65
|
-
return authorize_association_for(
|
63
|
+
return authorize_association_for("act_on") if @reflection.present?
|
66
64
|
|
67
65
|
@resource.authorization.authorize_action(:act_on, raise_exception: false) && !has_reflection_and_is_read_only
|
68
66
|
end
|
@@ -71,7 +69,7 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
|
|
71
69
|
klass = @reflection
|
72
70
|
klass = @reflection.through_reflection if klass.is_a? ::ActiveRecord::Reflection::ThroughReflection
|
73
71
|
|
74
|
-
@reflection.present? && klass.is_a?(::ActiveRecord::Reflection::HasManyReflection) && !has_reflection_and_is_read_only && authorize_association_for(
|
72
|
+
@reflection.present? && klass.is_a?(::ActiveRecord::Reflection::HasManyReflection) && !has_reflection_and_is_read_only && authorize_association_for("attach")
|
75
73
|
end
|
76
74
|
|
77
75
|
def has_reflection_and_is_read_only
|
@@ -19,8 +19,8 @@
|
|
19
19
|
} do %>
|
20
20
|
<%= t('avo.detach_item', item: title).capitalize %>
|
21
21
|
<% end %>
|
22
|
+
<%= render Avo::ActionsComponent.new actions: @actions, resource: @resource, view: @view %>
|
22
23
|
<% end %>
|
23
|
-
<%= render Avo::ActionsComponent.new actions: @actions, resource: @resource, view: @view %>
|
24
24
|
<% if can_see_the_edit_button? %>
|
25
25
|
<%= a_link edit_path,
|
26
26
|
color: :primary,
|
@@ -4,13 +4,11 @@ class Avo::Views::ResourceShowComponent < Avo::ResourceComponent
|
|
4
4
|
include Avo::ResourcesHelper
|
5
5
|
include Avo::ApplicationHelper
|
6
6
|
|
7
|
-
def initialize(resource: nil, reflection: nil,
|
7
|
+
def initialize(resource: nil, reflection: nil, parent_model: nil, resource_panel: nil, actions: [])
|
8
8
|
@resource = resource
|
9
9
|
@reflection = reflection
|
10
10
|
@resource_panel = resource_panel
|
11
11
|
@actions = actions
|
12
|
-
@parent_model = parent_model
|
13
|
-
@parent_resource = parent_resource
|
14
12
|
@view = :show
|
15
13
|
end
|
16
14
|
|
@@ -21,7 +21,6 @@ module Avo
|
|
21
21
|
before_action :set_container_classes
|
22
22
|
before_action :add_initial_breadcrumbs
|
23
23
|
before_action :set_view
|
24
|
-
before_action :set_sidebar_open
|
25
24
|
|
26
25
|
rescue_from Pundit::NotAuthorizedError, with: :render_unauthorized
|
27
26
|
rescue_from ActiveRecord::RecordInvalid, with: :exception_logger
|
@@ -130,11 +129,7 @@ module Avo
|
|
130
129
|
end
|
131
130
|
|
132
131
|
def set_related_model
|
133
|
-
@related_model =
|
134
|
-
@model.send params[:related_name]
|
135
|
-
else
|
136
|
-
eager_load_files(@related_resource, @model.send(params[:related_name])).find params[:related_id]
|
137
|
-
end
|
132
|
+
@related_model = eager_load_files(@related_resource, @related_resource.class.find_scope).find params[:related_id]
|
138
133
|
end
|
139
134
|
|
140
135
|
def set_view
|
@@ -160,20 +155,15 @@ module Avo
|
|
160
155
|
end
|
161
156
|
|
162
157
|
def hydrate_related_resource
|
163
|
-
@related_resource.hydrate(view: action_name.to_sym, user: _current_user
|
164
|
-
end
|
165
|
-
|
166
|
-
def authorize_base_action
|
167
|
-
class_to_authorize = @model || @resource.model_class
|
168
|
-
|
169
|
-
authorize_action class_to_authorize
|
158
|
+
@related_resource.hydrate(view: action_name.to_sym, user: _current_user)
|
170
159
|
end
|
171
160
|
|
172
|
-
def authorize_action
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
161
|
+
def authorize_action
|
162
|
+
if @model.present?
|
163
|
+
@authorization.set_record(@model).authorize_action action_name.to_sym
|
164
|
+
else
|
165
|
+
@authorization.set_record(@resource.model_class).authorize_action action_name.to_sym
|
166
|
+
end
|
177
167
|
end
|
178
168
|
|
179
169
|
# Get the pluralized resource name for this request
|
@@ -320,15 +310,10 @@ module Avo
|
|
320
310
|
|
321
311
|
def default_url_options
|
322
312
|
if params[:force_locale].present?
|
323
|
-
{**super, force_locale: params[:force_locale]}
|
313
|
+
{ **super, force_locale: params[:force_locale] }
|
324
314
|
else
|
325
315
|
super
|
326
316
|
end
|
327
317
|
end
|
328
|
-
|
329
|
-
def set_sidebar_open
|
330
|
-
value = cookies["#{Avo::COOKIES_KEY}.sidebar.open"]
|
331
|
-
@sidebar_open = value.blank? || value == '1'
|
332
|
-
end
|
333
318
|
end
|
334
319
|
end
|
@@ -5,16 +5,12 @@ module Avo
|
|
5
5
|
before_action :set_model, only: [:show, :index, :new, :create, :destroy, :order]
|
6
6
|
before_action :set_related_resource_name
|
7
7
|
before_action :set_related_resource, only: [:show, :index, :new, :create, :destroy, :order]
|
8
|
-
before_action :
|
9
|
-
before_action :hydrate_related_resource, only: [:show, :index, :create, :destroy, :order]
|
8
|
+
before_action :hydrate_related_resource, only: [:show, :index, :new, :create, :destroy, :order]
|
10
9
|
before_action :set_related_model, only: [:show, :order]
|
11
|
-
before_action :set_reflection
|
12
10
|
before_action :set_attachment_class, only: [:show, :index, :new, :create, :destroy, :order]
|
13
11
|
before_action :set_attachment_resource, only: [:show, :index, :new, :create, :destroy, :order]
|
14
12
|
before_action :set_attachment_model, only: [:create, :destroy, :order]
|
15
|
-
before_action :
|
16
|
-
before_action :authorize_attach_action, only: :new
|
17
|
-
before_action :authorize_detach_action, only: :destroy
|
13
|
+
before_action :set_reflection, only: [:index, :show, :order]
|
18
14
|
|
19
15
|
def index
|
20
16
|
@parent_resource = @resource.dup
|
@@ -32,8 +28,6 @@ module Avo
|
|
32
28
|
end
|
33
29
|
|
34
30
|
def show
|
35
|
-
@parent_resource, @parent_model = @resource, @model
|
36
|
-
|
37
31
|
@resource, @model = @related_resource, @related_model
|
38
32
|
|
39
33
|
super
|
@@ -42,6 +36,12 @@ module Avo
|
|
42
36
|
def new
|
43
37
|
@resource.hydrate(model: @model)
|
44
38
|
|
39
|
+
begin
|
40
|
+
@field = @resource.get_field_definitions.find { |f| f.id == @related_resource_name.to_sym }
|
41
|
+
@field.hydrate(resource: @resource, model: @model, view: :new)
|
42
|
+
rescue
|
43
|
+
end
|
44
|
+
|
45
45
|
if @field.present? && !@field.searchable
|
46
46
|
query = @authorization.apply_policy @attachment_class
|
47
47
|
|
@@ -93,12 +93,8 @@ module Avo
|
|
93
93
|
|
94
94
|
private
|
95
95
|
|
96
|
-
def set_reflection
|
97
|
-
@reflection = @model._reflections[params[:related_name].to_s]
|
98
|
-
end
|
99
|
-
|
100
96
|
def set_attachment_class
|
101
|
-
@attachment_class = @
|
97
|
+
@attachment_class = @model._reflections[params[:related_name].to_s].klass
|
102
98
|
end
|
103
99
|
|
104
100
|
def set_attachment_resource
|
@@ -106,13 +102,11 @@ module Avo
|
|
106
102
|
end
|
107
103
|
|
108
104
|
def set_attachment_model
|
109
|
-
@attachment_model = @
|
105
|
+
@attachment_model = @model._reflections[params[:related_name].to_s].klass.find attachment_id
|
110
106
|
end
|
111
107
|
|
112
|
-
def
|
113
|
-
@
|
114
|
-
@field.hydrate(resource: @resource, model: @model, view: :new)
|
115
|
-
rescue
|
108
|
+
def set_reflection
|
109
|
+
@reflection = @model._reflections[params[:related_name].to_s]
|
116
110
|
end
|
117
111
|
|
118
112
|
def attachment_id
|
@@ -127,25 +121,5 @@ module Avo
|
|
127
121
|
|
128
122
|
klass
|
129
123
|
end
|
130
|
-
|
131
|
-
def authorize_if_defined(method)
|
132
|
-
@authorization.set_record(@model)
|
133
|
-
|
134
|
-
if @authorization.has_method?(method.to_sym)
|
135
|
-
@authorization.authorize_action method.to_sym
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def authorize_index_action
|
140
|
-
authorize_if_defined "view_#{@field.id}?"
|
141
|
-
end
|
142
|
-
|
143
|
-
def authorize_attach_action
|
144
|
-
authorize_if_defined "attach_#{@field.id}?"
|
145
|
-
end
|
146
|
-
|
147
|
-
def authorize_detach_action
|
148
|
-
authorize_if_defined "detach_#{@field.id}?"
|
149
|
-
end
|
150
124
|
end
|
151
125
|
end
|
@@ -10,8 +10,7 @@ module Avo
|
|
10
10
|
before_action :set_model_to_fill
|
11
11
|
before_action :set_edit_title_and_breadcrumbs, only: [:edit, :update]
|
12
12
|
before_action :fill_model, only: [:create, :update]
|
13
|
-
|
14
|
-
before_action :authorize_base_action, if: -> {controller_name != "associations"}
|
13
|
+
before_action :authorize_action
|
15
14
|
|
16
15
|
def index
|
17
16
|
@page_title = @resource.plural_name.humanize
|
@@ -16,6 +16,7 @@ import ItemSelectorController from './controllers/item_selector_controller'
|
|
16
16
|
import KeyValueController from './controllers/fields/key_value_controller'
|
17
17
|
import LoadingButtonController from './controllers/loading_button_controller'
|
18
18
|
import MenuController from './controllers/menu_controller'
|
19
|
+
import MobileController from './controllers/mobile_controller'
|
19
20
|
import ModalController from './controllers/modal_controller'
|
20
21
|
import MultipleSelectFilterController from './controllers/multiple_select_filter_controller'
|
21
22
|
import PerPageController from './controllers/per_page_controller'
|
@@ -25,7 +26,6 @@ import ResourceShowController from './controllers/resource_show_controller'
|
|
25
26
|
import SearchController from './controllers/search_controller'
|
26
27
|
import SelectController from './controllers/select_controller'
|
27
28
|
import SelectFilterController from './controllers/select_filter_controller'
|
28
|
-
import SidebarController from './controllers/sidebar_controller'
|
29
29
|
import SimpleMdeController from './controllers/fields/simple_mde_controller'
|
30
30
|
import TabsController from './controllers/tabs_controller'
|
31
31
|
import TagsFieldController from './controllers/fields/tags_field_controller'
|
@@ -46,6 +46,7 @@ application.register('item-select-all', ItemSelectAllController)
|
|
46
46
|
application.register('item-selector', ItemSelectorController)
|
47
47
|
application.register('loading-button', LoadingButtonController)
|
48
48
|
application.register('menu', MenuController)
|
49
|
+
application.register('mobile', MobileController)
|
49
50
|
application.register('modal', ModalController)
|
50
51
|
application.register('multiple-select-filter', MultipleSelectFilterController)
|
51
52
|
application.register('per-page', PerPageController)
|
@@ -55,7 +56,6 @@ application.register('resource-show', ResourceShowController)
|
|
55
56
|
application.register('search', SearchController)
|
56
57
|
application.register('select', SelectController)
|
57
58
|
application.register('select-filter', SelectFilterController)
|
58
|
-
application.register('sidebar', SidebarController)
|
59
59
|
application.register('tabs', TabsController)
|
60
60
|
application.register('tags-field', TagsFieldController)
|
61
61
|
application.register('text-filter', TextFilterController)
|
@@ -1,9 +1,3 @@
|
|
1
1
|
<%= render Avo::TurboFrameWrapperComponent.new(params[:turbo_frame]) do %>
|
2
|
-
<%= render Avo::Views::ResourceShowComponent.new(
|
3
|
-
resource: @resource,
|
4
|
-
reflection: @reflection,
|
5
|
-
actions: @actions,
|
6
|
-
parent_model: @parent_model,
|
7
|
-
parent_resource: @parent_resource,
|
8
|
-
) %>
|
2
|
+
<%= render Avo::Views::ResourceShowComponent.new(resource: @resource, reflection: @reflection, actions: @actions) %>
|
9
3
|
<% end %>
|
@@ -3,5 +3,4 @@
|
|
3
3
|
Avo.configuration.timezone = '<%= Avo.configuration.timezone %>'
|
4
4
|
Avo.configuration.root_path = '<%= root_path_without_url %>'
|
5
5
|
Avo.configuration.search_debounce = '<%= Avo.configuration.search_debounce %>'
|
6
|
-
Avo.configuration.cookies_key = '<%= Avo::COOKIES_KEY %>'
|
7
6
|
<% end %>
|
@@ -2,11 +2,8 @@
|
|
2
2
|
class="fixed bg-white p-2 w-full flex flex-shrink-0 items-center z-50 px-4 lg:px-4 border-b space-x-4 lg:space-x-0 h-16 <%= 'print:hidden' if Avo.configuration.hide_layout_when_printing %>"
|
3
3
|
v-if="layout !== 'blank'"
|
4
4
|
>
|
5
|
-
<div class="flex items-center space-x-2 w-auto lg:w-64 flex-shrink-0 h-full">
|
6
|
-
|
7
|
-
<%= a_button class: 'lg:hidden', icon: 'menu', size: :xs, compact: true, style: :text, data: { action: 'click->sidebar#toggleSidebarOnMobile' } %>
|
8
|
-
<%= a_button class: 'hidden lg:block', icon: 'menu', size: :xs, compact: true, style: :text, data: { action: 'click->sidebar#toggleSidebar' } %>
|
9
|
-
</div>
|
5
|
+
<div class="flex items-center space-x-2 lg:space-x-0 w-auto lg:w-64 flex-shrink-0 h-full">
|
6
|
+
<%= a_button class: 'lg:hidden', icon: 'menu', size: :xs, compact: true, style: :text, data: { action: 'click->mobile#toggleSidebar' } %>
|
10
7
|
<%= render partial: "avo/partials/logo" %>
|
11
8
|
</div>
|
12
9
|
<div class="flex-1 flex items-center justify-between lg:justify-start space-x-2 sm:space-x-8 lg:pl-4">
|