avo 1.4.3 → 1.5.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.

Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +63 -54
  4. data/README.md +5 -4
  5. data/app/components/avo/views/resource_index_component.html.erb +3 -3
  6. data/app/controllers/avo/application_controller.rb +14 -7
  7. data/app/controllers/avo/relations_controller.rb +1 -1
  8. data/app/controllers/avo/search_controller.rb +50 -35
  9. data/app/helpers/avo/application_helper.rb +4 -6
  10. data/app/packs/entrypoints/application.css +2 -1
  11. data/app/packs/entrypoints/application.js +3 -0
  12. data/app/packs/js/controllers/search_controller.js +120 -0
  13. data/app/packs/js/helpers/debounce_promise.js +13 -0
  14. data/app/packs/stylesheets/search.css +79 -0
  15. data/app/views/avo/base/index.html.erb +2 -2
  16. data/app/views/avo/base/show.html.erb +2 -2
  17. data/app/views/avo/partials/_global_search.html.erb +17 -0
  18. data/app/views/avo/partials/_profile_dropdown.html.erb +12 -8
  19. data/app/views/avo/partials/_resource_search.html.erb +10 -0
  20. data/app/views/avo/partials/_turbo_frame_wrap.html.erb +3 -0
  21. data/app/views/layouts/avo/application.html.erb +2 -4
  22. data/avo.gemspec +1 -0
  23. data/config/routes.rb +2 -6
  24. data/lib/avo/app.rb +4 -2
  25. data/lib/avo/base_resource.rb +85 -7
  26. data/lib/avo/configuration.rb +2 -0
  27. data/lib/avo/fields/base_field.rb +6 -0
  28. data/lib/avo/fields/external_image_field.rb +4 -0
  29. data/lib/avo/fields/file_field.rb +4 -0
  30. data/lib/avo/licensing/license.rb +10 -0
  31. data/lib/avo/licensing/license_manager.rb +0 -2
  32. data/lib/avo/licensing/pro_license.rb +3 -1
  33. data/lib/avo/services/authorization_service.rb +1 -1
  34. data/lib/avo/version.rb +1 -1
  35. data/lib/generators/avo/templates/initializer/avo.tt +1 -0
  36. data/lib/generators/avo/templates/resource/resource.tt +3 -0
  37. data/lib/generators/avo/templates/tool/sidebar_item.tt +1 -1
  38. data/public/avo-packs/css/{application-68691c73.css → application-d69fe930.css} +183 -6
  39. data/public/avo-packs/css/application-d69fe930.css.br +0 -0
  40. data/public/avo-packs/css/application-d69fe930.css.gz +0 -0
  41. data/public/avo-packs/css/application-d69fe930.css.map +1 -0
  42. data/public/avo-packs/css/application-d69fe930.css.map.br +0 -0
  43. data/public/avo-packs/css/application-d69fe930.css.map.gz +0 -0
  44. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js +26 -0
  45. data/public/avo-packs/js/{application-6a0b9e58526ae6bef242.js.LICENSE.txt → application-7b3d507875f4bc1f6677.js.LICENSE.txt} +0 -0
  46. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.br +0 -0
  47. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.gz +0 -0
  48. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map +1 -0
  49. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map.br +0 -0
  50. data/public/avo-packs/js/application-7b3d507875f4bc1f6677.js.map.gz +0 -0
  51. data/public/avo-packs/manifest.json +15 -15
  52. metadata +35 -15
  53. data/public/avo-packs/css/application-68691c73.css.br +0 -0
  54. data/public/avo-packs/css/application-68691c73.css.gz +0 -0
  55. data/public/avo-packs/css/application-68691c73.css.map +0 -1
  56. data/public/avo-packs/css/application-68691c73.css.map.br +0 -0
  57. data/public/avo-packs/css/application-68691c73.css.map.gz +0 -0
  58. data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js +0 -26
  59. data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.br +0 -0
  60. data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.gz +0 -0
  61. data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.map +0 -1
  62. data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.map.br +0 -0
  63. data/public/avo-packs/js/application-6a0b9e58526ae6bef242.js.map.gz +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 380b07580be342a7704954836661ffcb47871124092b8c890b4e0f1eb21e49b5
4
- data.tar.gz: fe64597fe439ae1da3758b787256ccc6087415bac4fe52eaca577cab30c190a8
3
+ metadata.gz: e864d98992a2be5740688af621e35b69e27249430f2d9f6361c936b8716175b1
4
+ data.tar.gz: 5a2b54c2b74fa4e302744d490bbf16196fbff7b3d10add7566db3dc9e693dac8
5
5
  SHA512:
6
- metadata.gz: ae8b98a0aaee29e0bc1fc332a2fae3cdf93ce3637ccff1d0c2625def3fac70ec2ee0f469b4096eaf99396f06b3133fe1e5ebf7163c2b8b80f26120e7f62e2478
7
- data.tar.gz: a98acda283b80b19e3b119b11f90fccba3f6659e0c0f79bda31462c574dbb73fe9e96cd3078555523593c92f4383b206de996890c1a044d52edace7e6e09c6ea
6
+ metadata.gz: c3eb6ad0ffcecff1bae739a9a6d4516d3118cf3f802db85e9002519396de3c3ffff256491c0b155199cc9515df023ee32bce1048467f484eac68aca6f15e13dd
7
+ data.tar.gz: b97d62031f3fa4506938f245217251c4bebe1cfeee94c2957899ea59c4fd847eb0484c2027c80dd92cd9ec7121cc7ee82da0482064c9275bdda09a8557133c7e
data/Gemfile CHANGED
@@ -100,6 +100,7 @@ group :test do
100
100
  gem "simplecov-cobertura"
101
101
  gem "webmock"
102
102
  gem "spring-commands-rspec"
103
+ gem "launchy", require: false
103
104
 
104
105
  gem "test-prof"
105
106
  end
@@ -125,3 +126,5 @@ gem 'meta-tags'
125
126
  gem 'breadcrumbs_on_rails'
126
127
 
127
128
  gem 'manifester'
129
+
130
+ gem 'ransack'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (1.4.3)
4
+ avo (1.5.1)
5
5
  active_link_to
6
6
  addressable
7
7
  breadcrumbs_on_rails
@@ -14,44 +14,45 @@ PATH
14
14
  pagy
15
15
  pundit
16
16
  rails (>= 6.0)
17
+ ransack
17
18
  view_component
18
19
  zeitwerk
19
20
 
20
21
  GEM
21
22
  remote: https://rubygems.org/
22
23
  specs:
23
- actioncable (6.0.3.6)
24
- actionpack (= 6.0.3.6)
24
+ actioncable (6.0.3.7)
25
+ actionpack (= 6.0.3.7)
25
26
  nio4r (~> 2.0)
26
27
  websocket-driver (>= 0.6.1)
27
- actionmailbox (6.0.3.6)
28
- actionpack (= 6.0.3.6)
29
- activejob (= 6.0.3.6)
30
- activerecord (= 6.0.3.6)
31
- activestorage (= 6.0.3.6)
32
- activesupport (= 6.0.3.6)
28
+ actionmailbox (6.0.3.7)
29
+ actionpack (= 6.0.3.7)
30
+ activejob (= 6.0.3.7)
31
+ activerecord (= 6.0.3.7)
32
+ activestorage (= 6.0.3.7)
33
+ activesupport (= 6.0.3.7)
33
34
  mail (>= 2.7.1)
34
- actionmailer (6.0.3.6)
35
- actionpack (= 6.0.3.6)
36
- actionview (= 6.0.3.6)
37
- activejob (= 6.0.3.6)
35
+ actionmailer (6.0.3.7)
36
+ actionpack (= 6.0.3.7)
37
+ actionview (= 6.0.3.7)
38
+ activejob (= 6.0.3.7)
38
39
  mail (~> 2.5, >= 2.5.4)
39
40
  rails-dom-testing (~> 2.0)
40
- actionpack (6.0.3.6)
41
- actionview (= 6.0.3.6)
42
- activesupport (= 6.0.3.6)
41
+ actionpack (6.0.3.7)
42
+ actionview (= 6.0.3.7)
43
+ activesupport (= 6.0.3.7)
43
44
  rack (~> 2.0, >= 2.0.8)
44
45
  rack-test (>= 0.6.3)
45
46
  rails-dom-testing (~> 2.0)
46
47
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
47
- actiontext (6.0.3.6)
48
- actionpack (= 6.0.3.6)
49
- activerecord (= 6.0.3.6)
50
- activestorage (= 6.0.3.6)
51
- activesupport (= 6.0.3.6)
48
+ actiontext (6.0.3.7)
49
+ actionpack (= 6.0.3.7)
50
+ activerecord (= 6.0.3.7)
51
+ activestorage (= 6.0.3.7)
52
+ activesupport (= 6.0.3.7)
52
53
  nokogiri (>= 1.8.5)
53
- actionview (6.0.3.6)
54
- activesupport (= 6.0.3.6)
54
+ actionview (6.0.3.7)
55
+ activesupport (= 6.0.3.7)
55
56
  builder (~> 3.1)
56
57
  erubi (~> 1.4)
57
58
  rails-dom-testing (~> 2.0)
@@ -59,20 +60,20 @@ GEM
59
60
  active_link_to (1.0.5)
60
61
  actionpack
61
62
  addressable
62
- activejob (6.0.3.6)
63
- activesupport (= 6.0.3.6)
63
+ activejob (6.0.3.7)
64
+ activesupport (= 6.0.3.7)
64
65
  globalid (>= 0.3.6)
65
- activemodel (6.0.3.6)
66
- activesupport (= 6.0.3.6)
67
- activerecord (6.0.3.6)
68
- activemodel (= 6.0.3.6)
69
- activesupport (= 6.0.3.6)
70
- activestorage (6.0.3.6)
71
- actionpack (= 6.0.3.6)
72
- activejob (= 6.0.3.6)
73
- activerecord (= 6.0.3.6)
66
+ activemodel (6.0.3.7)
67
+ activesupport (= 6.0.3.7)
68
+ activerecord (6.0.3.7)
69
+ activemodel (= 6.0.3.7)
70
+ activesupport (= 6.0.3.7)
71
+ activestorage (6.0.3.7)
72
+ actionpack (= 6.0.3.7)
73
+ activejob (= 6.0.3.7)
74
+ activerecord (= 6.0.3.7)
74
75
  marcel (~> 1.0.0)
75
- activesupport (6.0.3.6)
76
+ activesupport (6.0.3.7)
76
77
  concurrent-ruby (~> 1.0, >= 1.0.2)
77
78
  i18n (>= 0.7, < 2)
78
79
  minitest (~> 5.1)
@@ -156,6 +157,8 @@ GEM
156
157
  i18n
157
158
  jbuilder (2.10.1)
158
159
  activesupport (>= 5.0.0)
160
+ launchy (2.5.0)
161
+ addressable (~> 2.7)
159
162
  listen (3.5.1)
160
163
  rb-fsevent (~> 0.10, >= 0.10.3)
161
164
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -176,7 +179,7 @@ GEM
176
179
  mime-types-data (3.2021.0225)
177
180
  mini_magick (4.11.0)
178
181
  mini_mime (1.1.0)
179
- mini_portile2 (2.5.0)
182
+ mini_portile2 (2.5.1)
180
183
  minitest (5.14.4)
181
184
  msgpack (1.4.2)
182
185
  multi_xml (0.6.0)
@@ -203,20 +206,20 @@ GEM
203
206
  rack
204
207
  rack-test (1.1.0)
205
208
  rack (>= 1.0, < 3)
206
- rails (6.0.3.6)
207
- actioncable (= 6.0.3.6)
208
- actionmailbox (= 6.0.3.6)
209
- actionmailer (= 6.0.3.6)
210
- actionpack (= 6.0.3.6)
211
- actiontext (= 6.0.3.6)
212
- actionview (= 6.0.3.6)
213
- activejob (= 6.0.3.6)
214
- activemodel (= 6.0.3.6)
215
- activerecord (= 6.0.3.6)
216
- activestorage (= 6.0.3.6)
217
- activesupport (= 6.0.3.6)
209
+ rails (6.0.3.7)
210
+ actioncable (= 6.0.3.7)
211
+ actionmailbox (= 6.0.3.7)
212
+ actionmailer (= 6.0.3.7)
213
+ actionpack (= 6.0.3.7)
214
+ actiontext (= 6.0.3.7)
215
+ actionview (= 6.0.3.7)
216
+ activejob (= 6.0.3.7)
217
+ activemodel (= 6.0.3.7)
218
+ activerecord (= 6.0.3.7)
219
+ activestorage (= 6.0.3.7)
220
+ activesupport (= 6.0.3.7)
218
221
  bundler (>= 1.3.0)
219
- railties (= 6.0.3.6)
222
+ railties (= 6.0.3.7)
220
223
  sprockets-rails (>= 2.0.0)
221
224
  rails-controller-testing (1.0.5)
222
225
  actionpack (>= 5.0.1.rc1)
@@ -227,14 +230,18 @@ GEM
227
230
  nokogiri (>= 1.6)
228
231
  rails-html-sanitizer (1.3.0)
229
232
  loofah (~> 2.3)
230
- railties (6.0.3.6)
231
- actionpack (= 6.0.3.6)
232
- activesupport (= 6.0.3.6)
233
+ railties (6.0.3.7)
234
+ actionpack (= 6.0.3.7)
235
+ activesupport (= 6.0.3.7)
233
236
  method_source
234
237
  rake (>= 0.8.7)
235
238
  thor (>= 0.20.3, < 2.0)
236
239
  rainbow (3.0.0)
237
240
  rake (13.0.3)
241
+ ransack (2.4.2)
242
+ activerecord (>= 5.2.4)
243
+ activesupport (>= 5.2.4)
244
+ i18n
238
245
  rb-fsevent (0.10.4)
239
246
  rb-inotify (0.10.1)
240
247
  ffi (~> 1.0)
@@ -242,7 +249,7 @@ GEM
242
249
  responders (3.0.1)
243
250
  actionpack (>= 5.0)
244
251
  railties (>= 5.0)
245
- rexml (3.2.4)
252
+ rexml (3.2.5)
246
253
  rspec-core (3.9.2)
247
254
  rspec-support (~> 3.9.3)
248
255
  rspec-expectations (3.9.2)
@@ -382,6 +389,7 @@ DEPENDENCIES
382
389
  image_processing (~> 1.2)
383
390
  iso
384
391
  jbuilder (~> 2.7)
392
+ launchy
385
393
  listen (>= 3.5.1)
386
394
  manifester
387
395
  meta-tags
@@ -390,6 +398,7 @@ DEPENDENCIES
390
398
  pundit
391
399
  rails (~> 6.0.2, >= 6.0.2.2)
392
400
  rails-controller-testing
401
+ ransack
393
402
  rspec-rails (~> 4.0.0)
394
403
  ruby-debug-ide
395
404
  sass-rails (>= 6)
@@ -409,4 +418,4 @@ DEPENDENCIES
409
418
  zeitwerk (~> 2.3)
410
419
 
411
420
  BUNDLED WITH
412
- 2.2.11
421
+ 2.2.17
data/README.md CHANGED
@@ -24,18 +24,19 @@ Avo is a beautiful next-generation framework that empowers you, the developer, t
24
24
  - **Powered by Hotwire** - Rails ❤️ Hotwire
25
25
  - **Code driven configuration** - Configure your Rails dashboard entirely by writing Ruby code.
26
26
  - **Resource Management** - Create a CRUD interface for Active Record from one command. No more copy-pasting view and controller files around.
27
+ - **Resource Search** - Quickly run a search through one or more resources at once.
27
28
  - **Active Storage support** - Amazingly easy, **one-line**, single or multi-file integration with **ActiveStorage**.
28
29
  - **Grid view** - Beautiful card layout to showcase your content.
29
30
  - **Actions** - Run custom actions to one or more of your resources with as little as pressing a button 💪
30
31
  - **Filters** - Write your own custom filters to quickly segment your data.
31
32
  - **Keeps your app clean** - You don't need to change your app to use Avo. Drop it in your existing app or add it to a new one and you're done 🙌
32
- - **Custom fields***- No worries if we missed a field you need. Generate a custom field in a jiffy.
33
- - **Dashboard widgets and metrics*** - Customize your dashboard with the tools and analytics you need.
33
+ - **Custom fields**- No worries if we missed a field you need. Generate a custom field in a jiffy.
34
34
  - **Custom tools** - You need to add a page with something completely new, you've got it!
35
35
  - **Authorization** - Leverage Pundit policies to build a robust and scalable authorization system.
36
- - **Themable*** - Dress it up into your own colors.
37
- - **Localization*** - Have it available in any language you need.
36
+ - **Localization** - Have it available in any language you need.
38
37
  - **No asset pipeline pollution** - Bring your own asset pipeline.
38
+ - **Dashboard widgets and metrics*** - Customize your dashboard with the tools and analytics you need.
39
+ - **Themable*** - Dress it up into your own colors.
39
40
 
40
41
  *Features still under development
41
42
 
@@ -22,12 +22,12 @@
22
22
  <% end %>
23
23
 
24
24
  <% c.body do %>
25
- <div class="flex justify-between py-6 min-h-24"
25
+ <div class="flex justify-between pt-2 pb-2 min-h-16"
26
26
  data-selected-resources-name="<%= @resource.plural_name.downcase %>"
27
27
  data-selected-resources="[]"
28
28
  >
29
29
  <div class="flex items-center px-6 w-64">
30
- <%# search %>
30
+ <%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key} if @resource.search_query.present? %>
31
31
  </div>
32
32
  <div class="flex justify-end items-center px-6 space-x-3">
33
33
  <%= render partial: 'avo/partials/view_toggle_button', locals: { available_view_types: available_view_types, view_type: view_type, turbo_frame: @turbo_frame } if @models.present? %>
@@ -36,7 +36,7 @@
36
36
  </div>
37
37
 
38
38
  <% if view_type.to_sym == :table %>
39
- <div class="w-full overflow-auto flex flex-col">
39
+ <div class="w-full overflow-auto flex flex-col mt-4">
40
40
  <div class="relative flex-1 flex">
41
41
  <%= render(Avo::Index::ResourceTableComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_model: @parent_model)) %>
42
42
  </div>
@@ -17,7 +17,7 @@ module Avo
17
17
  add_flash_types :info, :warning, :success, :error
18
18
 
19
19
  def init_app
20
- Avo::App.init request: request, context: context
20
+ Avo::App.init request: request, context: context, current_user: _current_user
21
21
 
22
22
  @license = Avo::App.license
23
23
  end
@@ -38,18 +38,25 @@ module Avo
38
38
  def render(*args)
39
39
  raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:check_avo_license).source_location.first.match?(/.*\/app\/controllers\/avo\/application_controller\.rb/)
40
40
 
41
+ if params[:controller] == "avo/search" && params[:action] == "index"
42
+ raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:index).source_location.first.match?(/.*\/app\/controllers\/avo\/search_controller\.rb/)
43
+ end
44
+
41
45
  super(*args)
42
46
  end
43
47
 
44
48
  def check_avo_license
49
+ # Check to see if the path is on a custom tool
45
50
  unless on_root_path || on_resources_path || on_api_path
46
- if @license.invalid? || @license.lacks(:custom_tools)
47
- if Rails.env.development?
51
+ # Display alert on custom tool page if in development.
52
+ if @license.lacks(:custom_tools) || @license.invalid?
53
+ if Rails.env.development? || Rails.env.test?
48
54
  @custom_tools_alert_visible = true
49
- else
50
- raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools."
51
55
  end
52
56
  end
57
+
58
+ # Raise error in non-development environments.
59
+ raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools." if @license.lacks_with_trial(:custom_tools)
53
60
  end
54
61
  end
55
62
 
@@ -157,9 +164,9 @@ module Avo
157
164
 
158
165
  def authorize_action
159
166
  if @model.present?
160
- @authorization.set_record(@model).authorize_action :index
167
+ @authorization.set_record(@model).authorize_action action_name.to_sym
161
168
  else
162
- @authorization.set_record(@resource.model_class).authorize_action :index
169
+ @authorization.set_record(@resource.model_class).authorize_action action_name.to_sym
163
170
  end
164
171
  end
165
172
 
@@ -17,7 +17,7 @@ module Avo
17
17
  @resource = @related_resource
18
18
  @parent_model = @parent_resource.model_class.find(params[:id])
19
19
  @parent_resource.hydrate(model: @parent_model)
20
- @query = @parent_model.public_send(params[:related_name])
20
+ @query = @authorization.apply_policy @parent_model.public_send(params[:related_name])
21
21
 
22
22
  super
23
23
  end
@@ -2,56 +2,71 @@ require_dependency "avo/application_controller"
2
2
 
3
3
  module Avo
4
4
  class SearchController < ApplicationController
5
- # before_action :authorize_user
5
+ before_action :set_resource_name, only: [:show]
6
+ before_action :set_resource, only: [:show]
6
7
 
7
8
  def index
8
- @authorization.set_record(resource_model).authorize_action :index
9
- resources = []
10
-
11
- App.resources
12
- .select { |resource| resource.search.present? }
13
- .select { |resource| AuthorizationService.authorize_action _current_user, resource.model, "index" }
14
- .each do |resource_model|
15
- found_resources = add_link_to_search_results(search_resource(resource_model), resource_model)
16
- resources.push({
17
- label: resource_model.name,
18
- resources: found_resources
19
- })
20
- end
9
+ raise ActionController::BadRequest.new("This feature requires the pro license https://avohq.io/purchase/pro") if App.license.lacks_with_trial(:global_search)
21
10
 
22
- render json: {
23
- resources: resources
24
- }
11
+ render json: search_resources(Avo::App.resources)
25
12
  end
26
13
 
27
- def resource
28
- render json: {
29
- resources: add_link_to_search_results(search_resource(avo_resource), avo_resource)
30
- }
14
+ def show
15
+ render json: search_resources([resource])
31
16
  end
32
17
 
33
18
  private
34
19
 
35
- def add_link_to_search_results(resources, avo_resource)
36
- resources.map do |model|
37
- {
38
- id: model.id,
39
- search_label: model.send(avo_resource.class.title),
40
- link: "/resources/#{model.class.to_s.singularize.underscore}/#{model.id}"
41
- }
20
+ def search_resources(resources)
21
+ resources.map do |resource|
22
+ # Apply authorization
23
+ next unless @authorization.set_record(resource.model_class).authorize_action(:index, raise_exception: false)
24
+ # Filter out the models without a search_query
25
+ next if resource.search_query.nil?
26
+
27
+ search_resource resource
42
28
  end
29
+ .select do |payload|
30
+ payload.present?
31
+ end
32
+ .sort do |payload|
33
+ payload.last[:count]
34
+ end
35
+ .reverse
36
+ .to_h
43
37
  end
44
38
 
45
- def search_resource(avo_resource)
46
- avo_resource.query_search(query: params[:q], via_resource_name: params[:via_resource_name], via_resource_id: params[:via_resource_id], user: _current_user)
39
+ def search_resource(resource)
40
+ results = apply_search_metadata(resource.search_query.call(params: params).limit(8), resource)
41
+
42
+ result_object = {
43
+ header: resource.name.pluralize,
44
+ results: results,
45
+ count: results.length
46
+ }
47
+
48
+ [resource.name.pluralize.downcase, result_object]
47
49
  end
48
50
 
49
- # def authorize_user
50
- # return if params[:action] == 'index'
51
+ def apply_search_metadata(models, avo_resource)
52
+ models.map do |model|
53
+ resource = avo_resource.dup.hydrate(model: model).hydrate_fields(model: model)
51
54
 
52
- # action = params[:action] == 'resource' ? :index : params[:action]
55
+ result = {
56
+ _id: model.id,
57
+ _label: resource.label,
58
+ _url: resource.avo_path,
59
+ model: model
60
+ }
53
61
 
54
- # return render_unauthorized unless AuthorizationService::authorize_action _current_user, avo_resource.model, action
55
- # end
62
+ if App.license.has_with_trial(:enhanced_search_results)
63
+ result[:_description] = resource.description
64
+ result[:_avatar] = resource.avatar
65
+ result[:_avatar_type] = resource.avatar_type
66
+ end
67
+
68
+ result
69
+ end
70
+ end
56
71
  end
57
72
  end