avo 2.28.0 → 2.28.2.pre.pr1642

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 793c8545f234434ece6d95719bbc92501755c47c27515996bae6bd47c8668da8
4
- data.tar.gz: 528f58dc08e61cdcb2d9d2bcc48b9341793c47d44fdc7b71c9999318aef845d0
3
+ metadata.gz: 2afd7fab61f56b5df63d0776f412e50efbf64bb0e45f9d011ec03f21978581c3
4
+ data.tar.gz: 69ea4d9a6097b88268f6058f0978a9ff938876d0c6837f41e5896411a2447db0
5
5
  SHA512:
6
- metadata.gz: 90c629713202b14315db0975c1ebe5cc34c2c5f8f9c9e2509f9d6f05da199ee8b645cc55cc4da6f8a78c4197c59b3c5207b4d00432516698fa068f9490bfb5d8
7
- data.tar.gz: ea1c21161d42a030d788a0cc3d92dccf5c551de9f466c2cc830a5035d9d1601fc2aee8ec83f7a1c1583060b01236b9adfad3433cd3512a7c04be7768cee3eeb5
6
+ metadata.gz: 3a324a98e38853c7b2cb4339f6c8d8c84efd7d4668248c1fd6e360f0fe7827a537108909c965241a080491fb6b18ac2d39c6b4e536de35708a495eb0484c0927
7
+ data.tar.gz: 0ddeccf56e54a0cd30214d69c1a02182d909b8731bf98ee95b4548ab1734ee1ff6c5b7d361b64e05a163a2cb0e957dfdcef88b3c156b7bc129ff06a452c4d90a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.28.0)
4
+ avo (2.28.2.pre.pr1642)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -19,40 +19,40 @@ PATH
19
19
  GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
- actioncable (6.1.7.2)
23
- actionpack (= 6.1.7.2)
24
- activesupport (= 6.1.7.2)
22
+ actioncable (6.1.7.3)
23
+ actionpack (= 6.1.7.3)
24
+ activesupport (= 6.1.7.3)
25
25
  nio4r (~> 2.0)
26
26
  websocket-driver (>= 0.6.1)
27
- actionmailbox (6.1.7.2)
28
- actionpack (= 6.1.7.2)
29
- activejob (= 6.1.7.2)
30
- activerecord (= 6.1.7.2)
31
- activestorage (= 6.1.7.2)
32
- activesupport (= 6.1.7.2)
27
+ actionmailbox (6.1.7.3)
28
+ actionpack (= 6.1.7.3)
29
+ activejob (= 6.1.7.3)
30
+ activerecord (= 6.1.7.3)
31
+ activestorage (= 6.1.7.3)
32
+ activesupport (= 6.1.7.3)
33
33
  mail (>= 2.7.1)
34
- actionmailer (6.1.7.2)
35
- actionpack (= 6.1.7.2)
36
- actionview (= 6.1.7.2)
37
- activejob (= 6.1.7.2)
38
- activesupport (= 6.1.7.2)
34
+ actionmailer (6.1.7.3)
35
+ actionpack (= 6.1.7.3)
36
+ actionview (= 6.1.7.3)
37
+ activejob (= 6.1.7.3)
38
+ activesupport (= 6.1.7.3)
39
39
  mail (~> 2.5, >= 2.5.4)
40
40
  rails-dom-testing (~> 2.0)
41
- actionpack (6.1.7.2)
42
- actionview (= 6.1.7.2)
43
- activesupport (= 6.1.7.2)
41
+ actionpack (6.1.7.3)
42
+ actionview (= 6.1.7.3)
43
+ activesupport (= 6.1.7.3)
44
44
  rack (~> 2.0, >= 2.0.9)
45
45
  rack-test (>= 0.6.3)
46
46
  rails-dom-testing (~> 2.0)
47
47
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
48
- actiontext (6.1.7.2)
49
- actionpack (= 6.1.7.2)
50
- activerecord (= 6.1.7.2)
51
- activestorage (= 6.1.7.2)
52
- activesupport (= 6.1.7.2)
48
+ actiontext (6.1.7.3)
49
+ actionpack (= 6.1.7.3)
50
+ activerecord (= 6.1.7.3)
51
+ activestorage (= 6.1.7.3)
52
+ activesupport (= 6.1.7.3)
53
53
  nokogiri (>= 1.8.5)
54
- actionview (6.1.7.2)
55
- activesupport (= 6.1.7.2)
54
+ actionview (6.1.7.3)
55
+ activesupport (= 6.1.7.3)
56
56
  builder (~> 3.1)
57
57
  erubi (~> 1.4)
58
58
  rails-dom-testing (~> 2.0)
@@ -62,22 +62,22 @@ GEM
62
62
  addressable
63
63
  active_median (0.3.3)
64
64
  activesupport (>= 5.2)
65
- activejob (6.1.7.2)
66
- activesupport (= 6.1.7.2)
65
+ activejob (6.1.7.3)
66
+ activesupport (= 6.1.7.3)
67
67
  globalid (>= 0.3.6)
68
- activemodel (6.1.7.2)
69
- activesupport (= 6.1.7.2)
70
- activerecord (6.1.7.2)
71
- activemodel (= 6.1.7.2)
72
- activesupport (= 6.1.7.2)
73
- activestorage (6.1.7.2)
74
- actionpack (= 6.1.7.2)
75
- activejob (= 6.1.7.2)
76
- activerecord (= 6.1.7.2)
77
- activesupport (= 6.1.7.2)
68
+ activemodel (6.1.7.3)
69
+ activesupport (= 6.1.7.3)
70
+ activerecord (6.1.7.3)
71
+ activemodel (= 6.1.7.3)
72
+ activesupport (= 6.1.7.3)
73
+ activestorage (6.1.7.3)
74
+ actionpack (= 6.1.7.3)
75
+ activejob (= 6.1.7.3)
76
+ activerecord (= 6.1.7.3)
77
+ activesupport (= 6.1.7.3)
78
78
  marcel (~> 1.0)
79
79
  mini_mime (>= 1.1.0)
80
- activesupport (6.1.7.2)
80
+ activesupport (6.1.7.3)
81
81
  concurrent-ruby (~> 1.0, >= 1.0.2)
82
82
  i18n (>= 1.6, < 2)
83
83
  minitest (>= 5.1)
@@ -142,7 +142,7 @@ GEM
142
142
  xpath (~> 3.2)
143
143
  chartkick (4.2.1)
144
144
  childprocess (4.1.0)
145
- concurrent-ruby (1.2.0)
145
+ concurrent-ruby (1.2.2)
146
146
  countries (4.2.3)
147
147
  i18n_data (~> 0.16.0)
148
148
  sixarm_ruby_unaccent (~> 1.1)
@@ -239,7 +239,7 @@ GEM
239
239
  loofah (2.19.1)
240
240
  crass (~> 1.0.2)
241
241
  nokogiri (>= 1.5.9)
242
- mail (2.8.0.1)
242
+ mail (2.8.1)
243
243
  mini_mime (>= 0.1.1)
244
244
  net-imap
245
245
  net-pop
@@ -263,15 +263,15 @@ GEM
263
263
  net-protocol
264
264
  net-pop (0.1.2)
265
265
  net-protocol
266
- net-protocol (0.1.3)
266
+ net-protocol (0.2.1)
267
267
  timeout
268
268
  net-smtp (0.3.3)
269
269
  net-protocol
270
270
  nio4r (2.5.8)
271
- nokogiri (1.13.10)
271
+ nokogiri (1.14.2)
272
272
  mini_portile2 (~> 2.8.0)
273
273
  racc (~> 1.4)
274
- nokogiri (1.13.10-x86_64-linux)
274
+ nokogiri (1.14.2-x86_64-linux)
275
275
  racc (~> 1.4)
276
276
  orm_adapter (0.5.0)
277
277
  pagy (6.0.2)
@@ -288,23 +288,23 @@ GEM
288
288
  pundit (2.2.0)
289
289
  activesupport (>= 3.0.0)
290
290
  racc (1.6.2)
291
- rack (2.2.6.3)
292
- rack-test (2.0.2)
291
+ rack (2.2.6.4)
292
+ rack-test (2.1.0)
293
293
  rack (>= 1.3)
294
- rails (6.1.7.2)
295
- actioncable (= 6.1.7.2)
296
- actionmailbox (= 6.1.7.2)
297
- actionmailer (= 6.1.7.2)
298
- actionpack (= 6.1.7.2)
299
- actiontext (= 6.1.7.2)
300
- actionview (= 6.1.7.2)
301
- activejob (= 6.1.7.2)
302
- activemodel (= 6.1.7.2)
303
- activerecord (= 6.1.7.2)
304
- activestorage (= 6.1.7.2)
305
- activesupport (= 6.1.7.2)
294
+ rails (6.1.7.3)
295
+ actioncable (= 6.1.7.3)
296
+ actionmailbox (= 6.1.7.3)
297
+ actionmailer (= 6.1.7.3)
298
+ actionpack (= 6.1.7.3)
299
+ actiontext (= 6.1.7.3)
300
+ actionview (= 6.1.7.3)
301
+ activejob (= 6.1.7.3)
302
+ activemodel (= 6.1.7.3)
303
+ activerecord (= 6.1.7.3)
304
+ activestorage (= 6.1.7.3)
305
+ activesupport (= 6.1.7.3)
306
306
  bundler (>= 1.15.0)
307
- railties (= 6.1.7.2)
307
+ railties (= 6.1.7.3)
308
308
  sprockets-rails (>= 2.0.0)
309
309
  rails-controller-testing (1.0.5)
310
310
  actionpack (>= 5.0.1.rc1)
@@ -318,9 +318,9 @@ GEM
318
318
  rails-i18n (7.0.5)
319
319
  i18n (>= 0.7, < 2)
320
320
  railties (>= 6.0.0, < 8)
321
- railties (6.1.7.2)
322
- actionpack (= 6.1.7.2)
323
- activesupport (= 6.1.7.2)
321
+ railties (6.1.7.3)
322
+ actionpack (= 6.1.7.3)
323
+ activesupport (= 6.1.7.3)
324
324
  method_source
325
325
  rake (>= 12.2)
326
326
  thor (~> 1.0)
@@ -412,7 +412,7 @@ GEM
412
412
  unicode-display_width (>= 1.1.1, < 3)
413
413
  test-prof (1.0.10)
414
414
  thor (1.2.1)
415
- timeout (0.3.0)
415
+ timeout (0.3.2)
416
416
  turbo-rails (1.4.0)
417
417
  actionpack (>= 6.0.0)
418
418
  activejob (>= 6.0.0)
@@ -444,7 +444,7 @@ GEM
444
444
  websocket-extensions (0.1.5)
445
445
  xpath (3.2.0)
446
446
  nokogiri (~> 1.8)
447
- zeitwerk (2.6.6)
447
+ zeitwerk (2.6.7)
448
448
 
449
449
  PLATFORMS
450
450
  ruby
@@ -31,7 +31,7 @@
31
31
  <% end %>
32
32
  <% c.body do %>
33
33
  <div class="flex flex-col xs:flex-row xs:justify-between space-y-2 xs:space-y-0 py-4 <%= 'hidden' if @resource.search_query.nil? && @filters.empty? && available_view_types.count <= 1 %>">
34
- <% unless hide_search_input %>
34
+ <% if show_search_input %>
35
35
  <div class="flex items-center px-4 w-64">
36
36
  <%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key, via_reflection: via_reflection} %>
37
37
  </div>
@@ -124,10 +124,19 @@ class Avo::Views::ResourceIndexComponent < Avo::ResourceComponent
124
124
  @resource.resource_description
125
125
  end
126
126
 
127
- def hide_search_input
128
- return true unless @resource.search_query.present?
127
+ def show_search_input
128
+ return false unless authorized_to_search?
129
+ return false unless @resource.search_query.present?
130
+ return false if field&.hide_search_input
129
131
 
130
- field&.hide_search_input || false
132
+ true
133
+ end
134
+
135
+ def authorized_to_search?
136
+ # Hide the search if the authorization prevents it
137
+ return true unless @resource.authorization.has_action_method?("search")
138
+
139
+ @resource.authorization.authorize_action("search", raise_exception: false)
131
140
  end
132
141
 
133
142
  private
@@ -27,7 +27,8 @@ module Avo
27
27
  resources
28
28
  .map do |resource|
29
29
  # Apply authorization
30
- next unless @authorization.set_record(resource.model_class).authorize_action(:index, raise_exception: false)
30
+ next unless @authorization.set_record(resource.model_class).authorize_action(:search, raise_exception: false)
31
+
31
32
  # Filter out the models without a search_query
32
33
  next if resource.search_query.nil?
33
34
 
@@ -120,10 +121,16 @@ module Avo
120
121
  models.map do |model|
121
122
  resource = avo_resource.dup.hydrate(model: model).hydrate_fields(model: model)
122
123
 
124
+ record_path = if resource.search_result_path.present?
125
+ Avo::Hosts::ResourceRecordHost.new(block: resource.search_result_path, resource: resource, record: model).handle
126
+ else
127
+ resource.record_path
128
+ end
129
+
123
130
  result = {
124
131
  _id: model.id,
125
132
  _label: resource.label,
126
- _url: resource.record_path,
133
+ _url: record_path
127
134
  }
128
135
 
129
136
  if App.license.has_with_trial(:enhanced_search_results)
@@ -102,16 +102,15 @@ module Avo
102
102
  end
103
103
 
104
104
  def root_path_without_url
105
- Avo::App.root_path
106
- .to_s
107
- .delete_prefix(request.base_url.to_s)
108
- .delete_suffix("/")
109
- .gsub("/?", "?")
110
- .query = ""
105
+ "#{Avo.configuration.prefix_path}#{mount_path}"
111
106
  rescue
112
107
  Avo.configuration.root_path
113
108
  end
114
109
 
110
+ def mount_path
111
+ Avo::Engine.routes.find_script_name(params.permit!.to_h.symbolize_keys)
112
+ end
113
+
115
114
  private
116
115
 
117
116
  # Taken from the original library
data/config/master.key ADDED
@@ -0,0 +1 @@
1
+ 2aeb23d82b909d9c6b5abb62f7058c2a
@@ -30,6 +30,7 @@ module Avo
30
30
  class_attribute :description, default: :id
31
31
  class_attribute :search_query, default: nil
32
32
  class_attribute :search_query_help, default: ""
33
+ class_attribute :search_result_path
33
34
  class_attribute :includes, default: []
34
35
  class_attribute :authorization_policy
35
36
  class_attribute :translation_key
@@ -42,6 +42,7 @@ module Avo
42
42
  attr_accessor :field_wrapper_layout
43
43
  attr_accessor :sign_out_path_name
44
44
  attr_accessor :resources
45
+ attr_accessor :prefix_path
45
46
  attr_writer :branding
46
47
 
47
48
  def initialize
@@ -94,6 +95,7 @@ module Avo
94
95
  @authorization_client = :pundit
95
96
  @field_wrapper_layout = :inline
96
97
  @resources = nil
98
+ @prefix_path = nil
97
99
  end
98
100
 
99
101
  def current_user_method(&block)
@@ -117,8 +119,8 @@ module Avo
117
119
  end
118
120
 
119
121
  def namespace
120
- if computed_root_path.present?
121
- computed_root_path.delete "/"
122
+ if Avo.configuration.root_path.present?
123
+ Avo.configuration.root_path.delete "/"
122
124
  else
123
125
  root_path.delete "/"
124
126
  end
@@ -130,10 +132,6 @@ module Avo
130
132
  @root_path
131
133
  end
132
134
 
133
- def computed_root_path
134
- Avo.configuration.root_path
135
- end
136
-
137
135
  def feature_enabled?(feature)
138
136
  !@disabled_features.map(&:to_sym).include?(feature.to_sym)
139
137
  end
data/lib/avo/engine.rb CHANGED
@@ -7,6 +7,8 @@ Gem.loaded_specs["avo"].dependencies.each do |d|
7
7
  require "action_view/railtie"
8
8
  when "activestorage"
9
9
  require "active_storage/engine"
10
+ when "actiontext"
11
+ require "action_text/engine"
10
12
  else
11
13
  require d.name
12
14
  end
@@ -20,13 +20,26 @@ module Avo
20
20
  def formatted_value
21
21
  return if value.blank?
22
22
 
23
- value.iso8601
23
+ try_iso8601
24
24
  end
25
25
 
26
26
  def edit_formatted_value
27
- return nil if value.nil?
27
+ formatted_value
28
+ end
29
+
30
+ private
28
31
 
29
- value.iso8601
32
+ def try_iso8601
33
+ if value.respond_to?(:iso8601)
34
+ value.iso8601
35
+ elsif value.is_a?(String)
36
+ parsed = DateTime.parse(value.dup)
37
+ if parsed.present?
38
+ parsed
39
+ end
40
+ else
41
+ value
42
+ end
30
43
  end
31
44
  end
32
45
  end
@@ -10,6 +10,8 @@ module Avo
10
10
  option :params, default: proc { Avo::App.params }
11
11
  option :view_context, default: proc { Avo::App.view_context }
12
12
  option :current_user, default: proc { Avo::App.current_user }
13
+ option :main_app, default: proc { view_context.main_app }
14
+ option :avo, default: proc { view_context.avo }
13
15
  # This is optional because we might instantiate the `Host` first and later hydrate it with a block.
14
16
  option :block, optional: true
15
17
 
@@ -130,8 +130,16 @@ module Avo
130
130
  end
131
131
 
132
132
  def has_method?(method, **args)
133
+ method = "#{method}?" unless method.to_s.end_with? "?"
133
134
  defined_methods(args[:record] || record, **args).include? method.to_sym
134
135
  end
136
+
137
+ # Check the received method to see if the user overrode it in their config and then checks if it's present on the policy.
138
+ def has_action_method?(method, **args)
139
+ method = Avo.configuration.authorization_methods.stringify_keys[method.to_s] || method
140
+
141
+ has_method? method, **args
142
+ end
135
143
  end
136
144
  end
137
145
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.28.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.28.2.pre.pr1642" unless const_defined?(:VERSION)
3
3
  end
@@ -87,12 +87,20 @@ module Generators
87
87
  end
88
88
  end
89
89
 
90
+ def rich_texts
91
+ @rich_texts ||= reflections.select do |_, reflection|
92
+ reflection.options[:class_name] == "ActionText::RichText"
93
+ end
94
+ end
95
+
90
96
  def tags
91
97
  @tags ||= reflections.select { |_, reflection| reflection.options[:as] == :taggable }
92
98
  end
93
99
 
94
100
  def associations
95
- @associations ||= reflections.reject { |key| attachments.key?(key) || tags.key?(key) }
101
+ @associations ||= reflections.reject do |key|
102
+ attachments.key?(key) || tags.key?(key) || rich_texts.key?(key)
103
+ end
96
104
  end
97
105
 
98
106
  def fields
@@ -115,6 +123,7 @@ module Generators
115
123
  fields_from_model_enums
116
124
  fields_from_model_attachements
117
125
  fields_from_model_associations
126
+ fields_from_model_rich_texts
118
127
  fields_from_model_tags
119
128
 
120
129
  generated_fields_template
@@ -149,6 +158,12 @@ module Generators
149
158
  generated_fields_template
150
159
  end
151
160
 
161
+ def fields_from_model_rich_texts
162
+ rich_texts.each do |name, _|
163
+ fields[(name.delete_prefix("rich_text_"))] = {field: "trix"}
164
+ end
165
+ end
166
+
152
167
  def fields_from_model_tags
153
168
  tags.each do |name, _|
154
169
  fields[(remove_last_word_from name).pluralize] = {field: "tags"}
@@ -2,6 +2,8 @@
2
2
  Avo.configure do |config|
3
3
  ## == Routing ==
4
4
  config.root_path = '/<%= options[:path] %>'
5
+ # used only when you have custom `map` configuration in your config.ru
6
+ # config.prefix_path = "/internal"
5
7
 
6
8
  # Where should the user be redirected when visting the `/<%= options[:path] %>` url
7
9
  # config.home_path = nil
@@ -29,6 +31,7 @@ Avo.configure do |config|
29
31
  # update: 'update?',
30
32
  # create: 'create?',
31
33
  # destroy: 'destroy?',
34
+ # search: 'search?',
32
35
  # }
33
36
  # config.raise_error_on_missing_policy = false
34
37
  # config.authorization_client = :pundit
@@ -61,7 +64,6 @@ Avo.configure do |config|
61
64
  # config.view_component_path = "app/components"
62
65
  # config.display_license_request_timeout_error = true
63
66
  # config.disabled_features = []
64
- # config.resource_controls = :right
65
67
  # config.tabs_style = :tabs # can be :tabs or :pills
66
68
  # config.buttons_on_form_footers = true
67
69
  # config.field_wrapper_layout = true
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: 2.28.0
4
+ version: 2.28.2.pre.pr1642
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: 2023-03-14 00:00:00.000000000 Z
12
+ date: 2023-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -1696,6 +1696,7 @@ files:
1696
1696
  - config/credentials.yml.enc
1697
1697
  - config/i18n-tasks.yml
1698
1698
  - config/initializers/pagy.rb
1699
+ - config/master.key
1699
1700
  - config/routes.rb
1700
1701
  - config/spring.rb
1701
1702
  - db/factories.rb
@@ -1956,9 +1957,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
1956
1957
  version: 2.6.0
1957
1958
  required_rubygems_version: !ruby/object:Gem::Requirement
1958
1959
  requirements:
1959
- - - ">="
1960
+ - - ">"
1960
1961
  - !ruby/object:Gem::Version
1961
- version: '0'
1962
+ version: 1.3.1
1962
1963
  requirements: []
1963
1964
  rubygems_version: 3.3.3
1964
1965
  signing_key: