avo 2.28.0 → 2.28.1.pre.pr1642

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 793c8545f234434ece6d95719bbc92501755c47c27515996bae6bd47c8668da8
4
- data.tar.gz: 528f58dc08e61cdcb2d9d2bcc48b9341793c47d44fdc7b71c9999318aef845d0
3
+ metadata.gz: d3bb2ce2c32ddbba4f8bbeb6106e8bba29345090ccb6fb373372bd8d23afa5cf
4
+ data.tar.gz: 6230460ca9c90b5195b384df63d96feac645e863c3821648425eb7ee2d108c11
5
5
  SHA512:
6
- metadata.gz: 90c629713202b14315db0975c1ebe5cc34c2c5f8f9c9e2509f9d6f05da199ee8b645cc55cc4da6f8a78c4197c59b3c5207b4d00432516698fa068f9490bfb5d8
7
- data.tar.gz: ea1c21161d42a030d788a0cc3d92dccf5c551de9f466c2cc830a5035d9d1601fc2aee8ec83f7a1c1583060b01236b9adfad3433cd3512a7c04be7768cee3eeb5
6
+ metadata.gz: 0d91aceda8772221c07996c3c1538b378451a8cf0726ad93ef593394335d833070135ef5412fdc40f09024805c2c05582a70d7cca481ee0e28d03aacd350ac5d
7
+ data.tar.gz: 5f7a86dc730ddb524274a91d0ec6781e02b9e2a93867c02e798f70c838081305140f5a70fdab806c023fed3ec91e018759a86f74eb639b47dd7f83f74c5c9fd4
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.1.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
@@ -28,7 +28,7 @@ module Avo
28
28
  rescue_from Avo::NotAuthorizedError, with: :render_unauthorized
29
29
  rescue_from ActiveRecord::RecordInvalid, with: :exception_logger
30
30
 
31
- helper_method :_current_user, :resources_path, :resource_path, :new_resource_path, :edit_resource_path, :resource_attach_path, :resource_detach_path, :related_resources_path, :turbo_frame_request?, :resource_view_path
31
+ helper_method :_current_user, :resources_path, :resource_path, :new_resource_path, :edit_resource_path, :resource_attach_path, :resource_detach_path, :related_resources_path, :turbo_frame_request?, :resource_view_path, :mount_path
32
32
  add_flash_types :info, :warning, :success, :error
33
33
 
34
34
  def init_app
@@ -101,6 +101,10 @@ module Avo
101
101
  instance_eval(&Avo.configuration.context)
102
102
  end
103
103
 
104
+ def mount_path
105
+ Avo::Engine.routes.find_script_name(params.permit!.to_h.symbolize_keys)
106
+ end
107
+
104
108
  # This is coming from Turbo::Frames::FrameRequest module.
105
109
  # Exposing it as public method
106
110
  def turbo_frame_request?
@@ -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)
@@ -1,7 +1,7 @@
1
1
  <%= javascript_tag nonce: true do %>
2
2
  window.Avo = window.Avo || { configuration: {} }
3
3
  Avo.configuration.timezone = '<%= Avo.configuration.timezone %>'
4
- Avo.configuration.root_path = '<%= root_path_without_url %>'
4
+ Avo.configuration.root_path = '<%= mount_path %>'
5
5
  Avo.configuration.search_debounce = '<%= Avo.configuration.search_debounce %>'
6
6
  Avo.configuration.cookies_key = '<%= Avo::COOKIES_KEY %>'
7
7
  <% end %>
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
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.1.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"}
@@ -29,6 +29,7 @@ Avo.configure do |config|
29
29
  # update: 'update?',
30
30
  # create: 'create?',
31
31
  # destroy: 'destroy?',
32
+ # search: 'search?',
32
33
  # }
33
34
  # config.raise_error_on_missing_policy = false
34
35
  # config.authorization_client = :pundit
@@ -61,7 +62,6 @@ Avo.configure do |config|
61
62
  # config.view_component_path = "app/components"
62
63
  # config.display_license_request_timeout_error = true
63
64
  # config.disabled_features = []
64
- # config.resource_controls = :right
65
65
  # config.tabs_style = :tabs # can be :tabs or :pills
66
66
  # config.buttons_on_form_footers = true
67
67
  # 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.1.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-22 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: