avo 1.18.0.pre.3 → 1.18.2
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 +4 -2
- data/Gemfile.lock +193 -169
- data/app/components/avo/fields/common/multiple_file_viewer_component.html.erb +0 -2
- data/app/components/avo/fields/text_field/index_component.html.erb +5 -1
- data/app/components/avo/fields/text_field/show_component.html.erb +5 -1
- data/app/components/avo/index/resource_controls_component.rb +1 -1
- data/app/components/avo/views/resource_edit_component.html.erb +1 -1
- data/app/controllers/avo/application_controller.rb +5 -19
- data/app/controllers/avo/attachments_controller.rb +2 -1
- data/app/helpers/avo/application_helper.rb +18 -0
- data/app/views/avo/partials/_profile_dropdown.html.erb +7 -5
- data/db/factories.rb +9 -0
- data/lib/avo/app.rb +8 -4
- data/lib/avo/base_resource.rb +9 -2
- data/lib/avo/configuration.rb +2 -0
- data/lib/avo/fields/files_field.rb +0 -2
- data/lib/avo/fields/text_field.rb +2 -0
- data/lib/avo/version.rb +1 -1
- data/public/avo-packs/css/application-f9191617.css.map +1 -1
- data/public/avo-packs/css/application-f9191617.css.map.br +0 -0
- data/public/avo-packs/css/application-f9191617.css.map.gz +0 -0
- data/public/avo-packs/js/application-cc89f096028eb1d4d971.js.map +1 -1
- data/public/avo-packs/js/application-cc89f096028eb1d4d971.js.map.br +0 -0
- data/public/avo-packs/js/application-cc89f096028eb1d4d971.js.map.gz +0 -0
- metadata +5 -5
@@ -2,6 +2,8 @@ module Avo
|
|
2
2
|
class ApplicationController < ::ActionController::Base
|
3
3
|
include Pundit
|
4
4
|
include Pagy::Backend
|
5
|
+
include Avo::ApplicationHelper
|
6
|
+
|
5
7
|
protect_from_forgery with: :exception
|
6
8
|
before_action :init_app
|
7
9
|
before_action :check_avo_license
|
@@ -71,6 +73,8 @@ module Avo
|
|
71
73
|
def resources_path(model, keep_query_params: false, **args)
|
72
74
|
return if model.nil?
|
73
75
|
|
76
|
+
model_class = get_model_class model
|
77
|
+
|
74
78
|
existing_params = {}
|
75
79
|
|
76
80
|
begin
|
@@ -78,7 +82,7 @@ module Avo
|
|
78
82
|
existing_params = Addressable::URI.parse(request.fullpath).query_values.symbolize_keys
|
79
83
|
end
|
80
84
|
rescue; end
|
81
|
-
avo.send :"resources_#{
|
85
|
+
avo.send :"resources_#{model_class.base_class.model_name.route_key}_path", **existing_params, **args
|
82
86
|
end
|
83
87
|
|
84
88
|
def related_resources_path(parent_model, model, keep_query_params: false, **args)
|
@@ -283,23 +287,5 @@ module Avo
|
|
283
287
|
def on_api_path
|
284
288
|
request.original_url.match?(/.*#{Avo::App.root_path}\/avo_api\/.*/)
|
285
289
|
end
|
286
|
-
|
287
|
-
def get_model_class(model)
|
288
|
-
if model.instance_of?(Class)
|
289
|
-
model
|
290
|
-
else
|
291
|
-
model.class
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def singular_name(model_or_class)
|
296
|
-
model_class = get_model_class model_or_class
|
297
|
-
|
298
|
-
if ActiveModel::Naming.uncountable? model_class
|
299
|
-
model_class.model_name.route_key.singularize.gsub('_index', '')
|
300
|
-
else
|
301
|
-
model_class.model_name.route_key.singularize
|
302
|
-
end
|
303
|
-
end
|
304
290
|
end
|
305
291
|
end
|
@@ -21,7 +21,8 @@ module Avo
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def destroy
|
24
|
-
|
24
|
+
blob = ActiveStorage::Blob.find(params[:signed_attachment_id])
|
25
|
+
attachment = blob.attachments.find_by record_id: params[:id], record_type: @model.class.to_s
|
25
26
|
|
26
27
|
if attachment.present?
|
27
28
|
attachment.destroy
|
@@ -154,5 +154,23 @@ module Avo
|
|
154
154
|
|
155
155
|
classes
|
156
156
|
end
|
157
|
+
|
158
|
+
def get_model_class(model)
|
159
|
+
if model.instance_of?(Class)
|
160
|
+
model
|
161
|
+
else
|
162
|
+
model.class.base_class
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def singular_name(model_or_class)
|
167
|
+
model_class = get_model_class model_or_class
|
168
|
+
|
169
|
+
if ActiveModel::Naming.uncountable? model_class
|
170
|
+
model_class.base_class.model_name.route_key.singularize.gsub('_index', '')
|
171
|
+
else
|
172
|
+
model_class.base_class.model_name.route_key.singularize
|
173
|
+
end
|
174
|
+
end
|
157
175
|
end
|
158
176
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
<% destroy_user_session_path = "destroy_#{Avo.configuration.current_user_resource_name}_session_path".to_sym %>
|
2
|
+
|
3
|
+
<div <% if main_app.respond_to?(destroy_user_session_path) %> data-controller="toggle-panel" <% end %>>
|
2
4
|
<a href="javascript:void(0);" class="flex items-center cursor-pointer font-semibold text-gray-700" data-action="click->toggle-panel#togglePanel">
|
3
5
|
<% if _current_user.respond_to?(:avatar) && _current_user.avatar.present? %>
|
4
6
|
<%= image_tag _current_user.avatar, class: "h-12 rounded-full border-4 border-white mr-1" %>
|
@@ -10,14 +12,14 @@
|
|
10
12
|
<% else %>
|
11
13
|
Avo user
|
12
14
|
<% end %>
|
13
|
-
<% if main_app.respond_to?(
|
15
|
+
<% if main_app.respond_to?(destroy_user_session_path) %>
|
14
16
|
<%= svg 'chevron-down', class: "ml-1 h-4" %>
|
15
17
|
<% end %>
|
16
18
|
</a>
|
17
19
|
|
18
|
-
<% if main_app.respond_to?(
|
19
|
-
<div class="hidden absolute inset-auto
|
20
|
-
<%= button_to t('avo.sign_out'), main_app.destroy_user_session_path, method: :delete, form: { "data-turbo" => "false" }, class: "appearance-none bg-white text-left cursor-pointer text-green-600 font-semibold hover:text-white hover:bg-green-500 block px-4 py-1 w-full" %>
|
20
|
+
<% if main_app.respond_to?(destroy_user_session_path) %>
|
21
|
+
<div class="hidden absolute inset-auto right-0 mr-6 mt-0 py-4 bg-white rounded-xl min-w-[200px] shadow-context" data-toggle-panel-target="panel">
|
22
|
+
<%= button_to t('avo.sign_out'), main_app.send(:destroy_user_session_path), method: :delete, form: { "data-turbo" => "false" }, class: "appearance-none bg-white text-left cursor-pointer text-green-600 font-semibold hover:text-white hover:bg-green-500 block px-4 py-1 w-full" %>
|
21
23
|
</div>
|
22
24
|
<% end %>
|
23
25
|
</div>
|
data/db/factories.rb
CHANGED
@@ -44,4 +44,13 @@ FactoryBot.define do
|
|
44
44
|
factory :comment do
|
45
45
|
body { Faker::Lorem.paragraphs(number: rand(4...10)).join("\n") }
|
46
46
|
end
|
47
|
+
|
48
|
+
factory :person do
|
49
|
+
name { "#{Faker::Name.first_name} #{Faker::Name.last_name}" }
|
50
|
+
end
|
51
|
+
|
52
|
+
factory :spouse do
|
53
|
+
name { "#{Faker::Name.first_name} #{Faker::Name.last_name}" }
|
54
|
+
type { "Spouse" }
|
55
|
+
end
|
47
56
|
end
|
data/lib/avo/app.rb
CHANGED
@@ -32,7 +32,11 @@ module Avo
|
|
32
32
|
|
33
33
|
# Set the current host for ActiveStorage
|
34
34
|
begin
|
35
|
-
|
35
|
+
if Rails::VERSION::MAJOR === 6
|
36
|
+
ActiveStorage::Current.host = request.base_url
|
37
|
+
elsif Rails::VERSION::MAJOR === 7
|
38
|
+
ActiveStorage::Current.url_options = request.base_url
|
39
|
+
end
|
36
40
|
rescue => exception
|
37
41
|
Rails.logger.debug "[Avo] Failed to set ActiveStorage::Current.url_options, #{exception.inspect}"
|
38
42
|
end
|
@@ -121,8 +125,8 @@ module Avo
|
|
121
125
|
|
122
126
|
def get_available_resources(user = nil)
|
123
127
|
resources.select do |resource|
|
124
|
-
|
125
|
-
|
128
|
+
Services::AuthorizationService.authorize user, resource.model_class, Avo.configuration.authorization_methods.stringify_keys["index"], raise_exception: false
|
129
|
+
end
|
126
130
|
.sort_by { |r| r.name }
|
127
131
|
end
|
128
132
|
|
@@ -145,7 +149,7 @@ module Avo
|
|
145
149
|
# remove the leading underscore (_)
|
146
150
|
filename[0] = ""
|
147
151
|
# remove the extension
|
148
|
-
filename.gsub!(
|
152
|
+
filename.gsub!(".html.erb", "")
|
149
153
|
filename
|
150
154
|
end
|
151
155
|
end
|
data/lib/avo/base_resource.rb
CHANGED
@@ -74,7 +74,7 @@ module Avo
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def initialize
|
77
|
-
self.class.model_class = model_class
|
77
|
+
self.class.model_class = model_class.base_class
|
78
78
|
end
|
79
79
|
|
80
80
|
def hydrate(model: nil, view: nil, user: nil, params: nil)
|
@@ -198,10 +198,13 @@ module Avo
|
|
198
198
|
end
|
199
199
|
|
200
200
|
def model_class
|
201
|
+
# get the model class off of the static property
|
201
202
|
return self.class.model_class if self.class.model_class.present?
|
202
203
|
|
203
|
-
|
204
|
+
# get the model class off of the model
|
205
|
+
return @model.base_class if @model.present?
|
204
206
|
|
207
|
+
# generate a model class
|
205
208
|
class_name_without_resource.safe_constantize
|
206
209
|
end
|
207
210
|
|
@@ -410,5 +413,9 @@ module Avo
|
|
410
413
|
rescue
|
411
414
|
nil
|
412
415
|
end
|
416
|
+
|
417
|
+
def form_scope
|
418
|
+
model.class.base_class.to_s.downcase
|
419
|
+
end
|
413
420
|
end
|
414
421
|
end
|
data/lib/avo/configuration.rb
CHANGED
@@ -25,6 +25,7 @@ module Avo
|
|
25
25
|
attr_accessor :search_debounce
|
26
26
|
attr_accessor :view_component_path
|
27
27
|
attr_accessor :display_license_request_timeout_error
|
28
|
+
attr_accessor :current_user_resource_name
|
28
29
|
|
29
30
|
def initialize
|
30
31
|
@root_path = "/avo"
|
@@ -62,6 +63,7 @@ module Avo
|
|
62
63
|
@search_debounce = 300
|
63
64
|
@view_component_path = "app/components"
|
64
65
|
@display_license_request_timeout_error = true
|
66
|
+
@current_user_resource_name = "user"
|
65
67
|
end
|
66
68
|
|
67
69
|
def locale_tag
|
@@ -2,11 +2,13 @@ module Avo
|
|
2
2
|
module Fields
|
3
3
|
class TextField < BaseField
|
4
4
|
attr_reader :link_to_resource
|
5
|
+
attr_reader :as_html
|
5
6
|
|
6
7
|
def initialize(id, **args, &block)
|
7
8
|
super(id, **args, &block)
|
8
9
|
|
9
10
|
@link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
|
11
|
+
@as_html = args[:as_html].present? ? args[:as_html] : false
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
data/lib/avo/version.rb
CHANGED