avo 3.0.0.pre14 → 3.0.0.pre15

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: d0b96922b610c34442f4ef39940c378a6b5acc2638954c7eae30217fcfef32c4
4
- data.tar.gz: '092dfa026329552be2be791d9493b4c0ca8db46caf72f7bb494e59aceab32275'
3
+ metadata.gz: 2b1b68ed3a24e1223b230516bb904a16816ad0f27a3bf2419120a603cd7e26d4
4
+ data.tar.gz: 07b958d68bff512090a9dbedf6762cfe6cc39ea04e6da075a470ac8deed681d8
5
5
  SHA512:
6
- metadata.gz: d1a47cfffce993596d1fd2edb977c4207ced53a597e174917848f69d3586a8d337dfcf7b131c4720cef4119ce5ff8d16577304533c4776e3e807b6307606396c
7
- data.tar.gz: 94699f2123e35d23c0572d73137c86e025fa493c6f0637d9b7ea04ecbb93daef27ecaac42e818f3cdf01aba2dc2420aed7b18de6bb72cd87d8995afb29026ad1
6
+ metadata.gz: 5891cb96687009033562eb024652abee10398d7a093ae8475ee5d06001dd4e578ab941980d8a657cae1a9824548a28e46f9cc0a53a74c2671c6ef7b6b98024d5
7
+ data.tar.gz: 58611c02f92e01e5fb35845c06c3fe4fb3164ed00971af40a6591c5f6cf009ad77df8037d629ca661575f8053dcd9f7a35153f0e3f482e6189609036f20593e1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (3.0.0.pre14)
4
+ avo (3.0.0.pre15)
5
5
  actionview (>= 6.1)
6
6
  active_link_to
7
7
  activerecord (>= 6.1)
@@ -17,7 +17,7 @@ class Avo::Index::ResourceTableComponent < ViewComponent::Base
17
17
 
18
18
  def encrypted_query
19
19
  # TODO: move this to the resource where we can apply the adapter pattern
20
- serialized_query = if query.instance_of?(Ransack::Search)
20
+ serialized_query = if Module.const_defined?("Ransack::Search") && query.instance_of?(Ransack::Search)
21
21
  query.context.object.to_sql
22
22
  else
23
23
  return :select_all_disabled if query.nil? || !query.respond_to?(:all) || !query.all.respond_to?(:to_sql)
@@ -113,7 +113,7 @@ class Avo::ResourceComponent < Avo::BaseComponent
113
113
 
114
114
  def has_reflection_and_is_read_only
115
115
  if @reflection.present? && @reflection.active_record.name && @reflection.name
116
- resource = Avo.resource_manager.get_resource_by_model_class(@reflection.active_record.name).new(params: helpers.params, view: view, user: helpers.current_user)
116
+ resource = Avo.resource_manager.get_resource_by_model_class(@reflection.active_record.name).new(params: helpers.params, view: view, user: helpers._current_user)
117
117
  fields = resource.get_field_definitions
118
118
  filtered_fields = fields.filter { |f| f.id == @reflection.name }
119
119
  else
@@ -34,7 +34,7 @@
34
34
  <div class="text-black space-y-4">
35
35
  <% Avo.profile_menu.items.each do |item| %>
36
36
  <% if item.is_a? Avo::Menu::Link %>
37
- <%= render Avo::ProfileItemComponent.new label: item.name, path: item.path, icon: item.icon %>
37
+ <%= render Avo::ProfileItemComponent.new label: item.name, path: item.path, icon: item.icon, method: item.method, params: item.params %>
38
38
  <% end %>
39
39
  <% end %>
40
40
  </div>
@@ -20,14 +20,10 @@ module Avo
20
20
  end
21
21
 
22
22
  def handle
23
- # puts ["action_params->", action_params].inspect
24
23
  resource_ids = action_params[:fields][:avo_resource_ids].split(",")
25
24
  @selected_query = action_params[:fields][:avo_selected_query]
26
25
 
27
- # puts ["action_params[:fields]->", action_params[:fields]].inspect
28
-
29
26
  fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query)
30
- # puts ["fields->", fields.to_h].inspect
31
27
 
32
28
  args = {
33
29
  fields: fields,
@@ -41,8 +37,6 @@ module Avo
41
37
  @resource.find_record resource_ids, params: params
42
38
  end
43
39
 
44
- puts ["args->", args].inspect
45
-
46
40
  performed_action = @action.handle_action(**args)
47
41
 
48
42
  respond performed_action.response
@@ -67,18 +67,7 @@ module Avo
67
67
  end
68
68
 
69
69
  safe_call :set_and_apply_scopes
70
-
71
- if Avo.avo_filters_installed? && params[Avo::DynamicFilters.configuration.param_key].present?
72
- # Apply dynamic filters
73
- query_builder = Avo::DynamicFilters::QueryBuilder.new(resource: @resource, params: params, query: @query)
74
- @query = @query.ransack(**query_builder.ransack_query)
75
- end
76
-
77
- pagy_query = if @query.instance_of?(Ransack::Search)
78
- @query.result(distinct: false)
79
- else
80
- @query
81
- end
70
+ safe_call :apply_dynamic_filters
82
71
 
83
72
  @pagy, @records = pagy(pagy_query, items: @index_params[:per_page], link_extra: "data-turbo-frame=\"#{params[:turbo_frame]}\"", size: [1, 2, 2, 1], params: extra_pagy_params)
84
73
 
@@ -547,5 +536,9 @@ module Avo
547
536
  def safe_call(method)
548
537
  send(method) if respond_to?(method, true)
549
538
  end
539
+
540
+ def pagy_query
541
+ @query
542
+ end
550
543
  end
551
544
  end
@@ -3,7 +3,7 @@ module Avo
3
3
  def init_app
4
4
  Avo::Current.license = Avo::Licensing::NilLicense.new
5
5
  Avo::Current.context = context
6
- Avo::Current.current_user = _current_user
6
+ Avo::Current.user = _current_user
7
7
  Avo::Current.view_context = view_context
8
8
  Avo.init
9
9
  Avo::Current.license = Licensing::LicenseManager.new(Licensing::HQ.new(request).response).license
@@ -24,7 +24,9 @@ module Avo
24
24
  delegate :view, to: :class
25
25
  # TODO: find a differnet way to delegate this to the uninitialized Current variable
26
26
  delegate :context, to: Avo::Current
27
- delegate :current_user, to: Avo::Current
27
+ def curent_user
28
+ Avo::Current.user
29
+ end
28
30
  delegate :params, to: Avo::Current
29
31
  delegate :view_context, to: Avo::Current
30
32
  delegate :avo, to: :view_context
@@ -101,15 +103,12 @@ module Avo
101
103
  records, fields, current_user, resource = args.values_at(:records, :fields, :current_user, :resource)
102
104
  # Fetching the field definitions and not the actual fields (get_fields) because they will break if the user uses a `visible` block and adds a condition using the `params` variable. The params are different in the show method and the handle method.
103
105
  action_fields = get_field_definitions.map { |field| [field.id, field] }.to_h
104
- puts ["action_fields->", action_fields].inspect
105
106
 
106
107
  # For some fields, like belongs_to, the id and database_id differ (user vs user_id).
107
108
  # That's why we need to fetch the database_id for when we process the action.
108
109
  action_fields_by_database_id = action_fields.map do |id, value|
109
110
  [value.database_id.to_sym, value]
110
111
  end.to_h
111
- puts ["action_fields_by_database_id->", action_fields_by_database_id].inspect
112
- abort 1.inspect
113
112
 
114
113
  if fields.present?
115
114
  processed_fields = fields.to_unsafe_h.map do |name, value|
@@ -12,7 +12,9 @@ module Avo
12
12
 
13
13
  # Avo::Current methods
14
14
  delegate :context, to: Avo::Current
15
- delegate :current_user, to: Avo::Current
15
+ def curent_user
16
+ Avo::Current.user
17
+ end
16
18
  delegate :params, to: Avo::Current
17
19
  delegate :request, to: Avo::Current
18
20
  delegate :view_context, to: Avo::Current
@@ -101,7 +103,7 @@ module Avo
101
103
  end
102
104
 
103
105
  def authorization
104
- Avo::Services::AuthorizationService.new Avo::Current.current_user, model_class, policy_class: authorization_policy
106
+ Avo::Services::AuthorizationService.new Avo::Current.user, model_class, policy_class: authorization_policy
105
107
  end
106
108
 
107
109
  def get_record_associations(record)
@@ -404,7 +406,7 @@ module Avo
404
406
  end
405
407
 
406
408
  def authorization(user: nil)
407
- current_user = user || Avo::Current.current_user
409
+ current_user = user || Avo::Current.user
408
410
  Avo::Services::AuthorizationService.new(current_user, record || model_class, policy_class: authorization_policy)
409
411
  end
410
412
 
data/lib/avo/current.rb CHANGED
@@ -19,7 +19,7 @@ class Avo::Current < ActiveSupport::CurrentAttributes
19
19
 
20
20
  attribute :app
21
21
  attribute :license
22
- attribute :context, :current_user, :view_context
22
+ attribute :context, :user, :view_context
23
23
  attribute :error_manager
24
24
  attribute :resource_manager
25
25
  attribute :tool_manager
@@ -30,4 +30,10 @@ class Avo::Current < ActiveSupport::CurrentAttributes
30
30
  def request
31
31
  view_context.request || ActionDispatch::Request.empty
32
32
  end
33
+
34
+ def current_user
35
+ Rails.logger.warn "DEPRECATION WARNING: Avo::Current.current_user become deprecated and will become obsolete on futhure versions. Please use Avo::Current.user instead."
36
+
37
+ user
38
+ end
33
39
  end
@@ -20,7 +20,7 @@ module Avo
20
20
 
21
21
  # Set defaults on not initialized accessors
22
22
  @context ||= Avo::Current.context
23
- @current_user ||= Avo::Current.current_user
23
+ @current_user ||= Avo::Current.user
24
24
  @params ||= Avo::Current.params
25
25
  @request ||= Avo::Current.request
26
26
  @view_context ||= Avo::Current.view_context
@@ -15,7 +15,9 @@ module Avo
15
15
  delegate :params, to: Avo::Current
16
16
  delegate :request, to: Avo::Current
17
17
  delegate :view_context, to: Avo::Current
18
- delegate :current_user, to: Avo::Current
18
+ def curent_user
19
+ Avo::Current.user
20
+ end
19
21
 
20
22
  class << self
21
23
  def decode_filters(filter_params)
@@ -22,7 +22,9 @@ class Avo::HTML::Builder
22
22
  delegate :app, to: Avo::Current
23
23
  delegate :root_path, to: :app
24
24
  delegate :params, to: Avo::Current
25
- delegate :current_user, to: Avo::Current
25
+ def curent_user
26
+ Avo::Current.user
27
+ end
26
28
 
27
29
  def initialize(record: nil, resource: nil)
28
30
  @wrapper_stack = {}
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.0.pre14" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.0.pre15" unless const_defined?(:VERSION)
3
3
  end
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: 3.0.0.pre14
4
+ version: 3.0.0.pre15
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-07-27 00:00:00.000000000 Z
12
+ date: 2023-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord