avo 2.36.0 → 2.36.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3daed936826074ad203833bc647b28ab8404e03f8f600e6e251ab1f5048b2d3f
4
- data.tar.gz: bcd0096cf724a4cbb88a8015b589103ec7f43d24e47b3275799c1662560e0226
3
+ metadata.gz: 6cfa65ccbc3c3192f2daa5822ca180639c84bac36bbc8f4a05e608fb73525c20
4
+ data.tar.gz: 5a4846161d7aee464404f83e57da20c9efcc5624a54433fba1cf2031240d0355
5
5
  SHA512:
6
- metadata.gz: ae0863ff1c66d4e3ffcd85fd94080147b00407e22e609e291cee924602fd2ccc871175320f9e61968433ec84aff38275c90fcf6e130c3ce7029e204649e10038
7
- data.tar.gz: f83cfd82506cbe80a4310114d1376c42cd86107f5448c7db43357f3539100975bd0be6681caf768f8a6becf1c28b63aba55f7aeb8ede806a9c60138e01679da1
6
+ metadata.gz: 82f1ef921487a6cfb94214ea861344dd85445dba19c5fa6cb63073da50fb547ef6aaae7db40ecb533972f6cd4bfa220ff54f2188e5b4ce39c7238a4e0ecaaf20
7
+ data.tar.gz: 031be9135507031c5d203dde3aa1429e27f7faf0e5b80f8fc201c3e4853ec758b705121c27756189a38b70cc0bed107023083de58c3a2fda2194e0f7d2ece363
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.36.0)
4
+ avo (2.36.1)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
@@ -63,32 +63,29 @@ class Avo::TabSwitcherComponent < Avo::BaseComponent
63
63
  # Because the developer hasn't specified that it should be visible on edit views (with the show_on: :edit option),
64
64
  # the field should not be visible in the item switcher either.
65
65
  def visible_items
66
- tabs.select do |item|
67
- visible = true
68
-
69
- if item.items.blank?
70
- visible = false
71
- end
66
+ tabs.select do |tab|
67
+ next false if tab.items.blank?
68
+ next false if tab.is_field? && !tab.authorized?
69
+ next false if tab.has_a_single_item? && !single_item_visible?(tab.items.first)
70
+ next false if !tab.visible?
71
+ next false if !tab.visible_on?(view)
72
+
73
+ true
74
+ end
75
+ end
72
76
 
73
- first_item = item.items.first
74
- if item.items.count == 1 && first_item.is_field? && first_item.has_own_panel? && !first_item.visible_on?(view)
75
- # Return nil if tab contians a has_many type of fields and it's hidden in current view
76
- visible = false
77
- end
77
+ private
78
78
 
79
- if item.respond_to?(:visible_on?)
80
- visible = item.visible_on? view
81
- end
79
+ def single_item_visible?(item)
80
+ # Item is visible if is not a field or don't have its own panel
81
+ return true if !item.is_field?
82
+ return true if !item.has_own_panel?
82
83
 
83
- if item.respond_to?(:visible?)
84
- visible = item.visible?
85
- end
84
+ return false if !item.visible_on?(view)
86
85
 
87
- if item.respond_to?(:authorized?)
88
- visible = item.authorized?
89
- end
86
+ # If item is hydrated with the correct resource and is not authorized, it's not visible
87
+ return false if item.resource.present? && !item.authorized?
90
88
 
91
- visible
92
- end
89
+ true
93
90
  end
94
91
  end
@@ -215,16 +215,24 @@ module Avo
215
215
 
216
216
  def save_model
217
217
  perform_action_and_record_errors do
218
- @model.save!
218
+ save_model_action
219
219
  end
220
220
  end
221
221
 
222
+ def save_model_action
223
+ @model.save!
224
+ end
225
+
222
226
  def destroy_model
223
227
  perform_action_and_record_errors do
224
- @model.destroy!
228
+ destroy_model_action
225
229
  end
226
230
  end
227
231
 
232
+ def destroy_model_action
233
+ @model.destroy!
234
+ end
235
+
228
236
  def perform_action_and_record_errors(&block)
229
237
  begin
230
238
  succeeded = block.call
@@ -253,7 +261,7 @@ module Avo
253
261
  end
254
262
 
255
263
  def permitted_params
256
- @resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param).concat extra_params
264
+ @resource.get_field_definitions.select(&:updatable).map(&:to_permitted_param).concat(extra_params).uniq
257
265
  end
258
266
 
259
267
  def extra_params
@@ -112,8 +112,13 @@ module Avo
112
112
  # This scope is applied if the search is being performed on a has_many association
113
113
  def apply_has_many_scope
114
114
  association_name = BaseResource.valid_association_name(parent, params[:via_association_id])
115
+
116
+ # Get association records
115
117
  scope = parent.send(association_name)
116
118
 
119
+ # Apply policy scope if authorization is present
120
+ scope = resource.authorization&.apply_policy scope
121
+
117
122
  Avo::Hosts::SearchScopeHost.new(block: @resource.search_query, params: params, scope: scope).handle
118
123
  end
119
124
 
@@ -98,6 +98,10 @@ module Avo
98
98
  if item.is_field?
99
99
  fields << item
100
100
  end
101
+
102
+ if item.is_row?
103
+ fields << extract_fields_from_items(tab)
104
+ end
101
105
  end
102
106
 
103
107
  fields.flatten
@@ -117,7 +121,7 @@ module Avo
117
121
  thing.items.each do |item|
118
122
  if item.is_field?
119
123
  fields << item
120
- elsif item.is_panel?
124
+ elsif item.is_panel? || item.is_row?
121
125
  fields << extract_fields_from_items(item)
122
126
  end
123
127
  end
@@ -18,7 +18,7 @@ module Avo
18
18
  def visible_on?(view)
19
19
  raise "No view specified on visibility check." if view.blank?
20
20
 
21
- send :"show_on_#{view.to_s}"
21
+ send :"show_on_#{view}"
22
22
  end
23
23
 
24
24
  def show_on(*where)
data/lib/avo/tab.rb CHANGED
@@ -65,4 +65,8 @@ class Avo::Tab
65
65
  super(view)
66
66
  end
67
67
  end
68
+
69
+ def has_a_single_item?
70
+ items.count == 1
71
+ end
68
72
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.36.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.36.1" 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: 2.36.0
4
+ version: 2.36.1
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-04 00:00:00.000000000 Z
12
+ date: 2023-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord