iknow_view_models 3.6.2 → 3.6.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 267212f1572c3f81b65462be6c30e02a12a6562a29d01bd5e0c342a12396acbc
4
- data.tar.gz: e8c4addd984351d6df889ba7d75abbe8d5bde7793a48791e24a1b42e7a3fdf42
3
+ metadata.gz: ea15135f8f921a083f88184fb1602c2cb1ab1654845bf7d29b5d6a35ce4a1e93
4
+ data.tar.gz: cbb335d8125222a4e5efdb6fc5ae6317a6c1e74d86270885b68d2e482742f392
5
5
  SHA512:
6
- metadata.gz: 6039dcc05bed20bce4681c322c3509be3f2a276c0a755fb3e27240eec74fd9eddef68f3c272df33554407853065a98e0f4d03a068c8c0e068cfc02be6f73ab67
7
- data.tar.gz: 95fb89d93724d5028905612d846534916c4bdacd1bb88009ae434090b183e17d7311bb2709bfa81b08ff3dff45940ced0ce080ff861529c59cbb96671a661b64
6
+ metadata.gz: cde2777790785631ba0407ddd576931b05257bb1f51544927c4f9750ec0472cd45f87a9cfc3536271ead56f7b7decbc548f3f401ca23ae48a28bb11c2a6b67dd
7
+ data.tar.gz: 0bc8000d9cdf342248e2c9cd24e40f8fd4386f34b01891b022785747f9eda8474a19201cc1c72af8d526632ca9493d97eef00e59da3c683ba7bd8d1083790cc2
data/.circleci/config.yml CHANGED
@@ -8,7 +8,7 @@ executors:
8
8
  default: "2.7"
9
9
  pg-version:
10
10
  type: string
11
- default: "11"
11
+ default: "12.10"
12
12
  gemfile:
13
13
  type: string
14
14
  default: "Gemfile"
@@ -16,14 +16,14 @@ executors:
16
16
  PGHOST: 127.0.0.1
17
17
  PGUSER: eikaiwa
18
18
  docker:
19
- - image: circleci/ruby:<< parameters.ruby-version >>
19
+ - image: cimg/ruby:<< parameters.ruby-version >>
20
20
  environment:
21
21
  BUNDLE_JOBS: 3
22
22
  BUNDLE_RETRY: 3
23
23
  BUNDLE_PATH: vendor/bundle
24
24
  RAILS_ENV: test
25
25
  BUNDLE_GEMFILE: << parameters.gemfile >>
26
- - image: circleci/postgres:<< parameters.pg-version >>-alpine
26
+ - image: cimg/postgres:<< parameters.pg-version >>
27
27
  environment:
28
28
  POSTGRES_USER: eikaiwa
29
29
  POSTGRES_DB: iknow_view_models
@@ -104,27 +104,27 @@ workflows:
104
104
  - test:
105
105
  name: 'ruby 2.7 rails 5.2 pg 12'
106
106
  ruby-version: "2.7"
107
- pg-version: "12"
107
+ pg-version: "12.10"
108
108
  gemfile: gemfiles/rails_5_2.gemfile
109
109
  - test:
110
110
  name: 'ruby 2.7 rails 6.0 pg 12'
111
111
  ruby-version: "2.7"
112
- pg-version: "12"
112
+ pg-version: "12.10"
113
113
  gemfile: gemfiles/rails_6_0.gemfile
114
114
  - test:
115
115
  name: 'ruby 2.7 rails 6.1 pg 12'
116
116
  ruby-version: "2.7"
117
- pg-version: "12"
117
+ pg-version: "12.10"
118
118
  gemfile: gemfiles/rails_6_1.gemfile
119
119
  - test:
120
120
  name: 'ruby 3.0 rails 6.1 pg 12'
121
121
  ruby-version: "3.0"
122
- pg-version: "12"
122
+ pg-version: "12.10"
123
123
  gemfile: gemfiles/rails_6_1.gemfile
124
124
  - test:
125
- name: 'ruby 3.0 rails 7.0 pg 12'
126
- ruby-version: "3.0"
127
- pg-version: "12"
125
+ name: 'ruby 3.1 rails 7.0 pg 13'
126
+ ruby-version: "3.1"
127
+ pg-version: "13.6"
128
128
  gemfile: gemfiles/rails_7_0.gemfile
129
129
  - publish:
130
130
  filters:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.6.2'
4
+ VERSION = '3.6.5'
5
5
  end
@@ -39,10 +39,20 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
39
39
  case
40
40
  when new_allow
41
41
  nil
42
- when mergeable_error?(self.allow_error) && mergeable_error?(other.allow_error)
43
- self.allow_error.merge(other.allow_error)
42
+ when self.allow_error.nil?
43
+ other.allow_error
44
+ when other.allow_error.nil?
45
+ self.allow_error
46
+ # Mergeable (standard) errors should be merged if possible; if not
47
+ # possible, we should take the first non-standard error.
48
+ when mergeable_error?(self.allow_error)
49
+ if mergeable_error?(other.allow_error)
50
+ self.allow_error.merge(other.allow_error)
51
+ else
52
+ other.allow_error
53
+ end
44
54
  else
45
- self.allow_error || other.allow_error
55
+ self.allow_error
46
56
  end
47
57
 
48
58
  ComposedResult.new(new_allow, other.veto, new_allow_error, other.veto_error)
@@ -52,7 +62,7 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
52
62
  private
53
63
 
54
64
  def mergeable_error?(err)
55
- err&.is_a?(NoRequiredConditionsError)
65
+ err.is_a?(NoRequiredConditionsError)
56
66
  end
57
67
  end
58
68
 
@@ -160,16 +170,15 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
160
170
  next unless visited.add?(ancestor)
161
171
  next if include_ancestor && !include_ancestor.call(ancestor)
162
172
 
163
- ancestor.each_check(check_name) { |x| yield x }
173
+ ancestor.each_check(check_name, include_ancestor) { |x| yield x }
164
174
  end
165
175
  end
166
176
 
167
177
  def inspect
168
- s = super + '('
169
- s += inspect_checks.join(', ')
170
- s += " includes checkers: #{@included_checkers.inspect}" if @included_checkers.present?
171
- s += ')'
172
- s
178
+ checks = inspect_checks
179
+ checks << "includes checkers: #{@included_checkers.inspect}" if @included_checkers.present?
180
+
181
+ super + '(' + checks.join(', ') + ')'
173
182
  end
174
183
 
175
184
  def inspect_checks
@@ -192,8 +192,6 @@ class ViewModel::AccessControl::Tree < ViewModel::AccessControl
192
192
  def inspect_checks
193
193
  checks = super
194
194
  if root?
195
- checks << 'no root checks'
196
- else
197
195
  checks << "root_children_visible_if: #{root_children_visible_ifs.map(&:reason)}" if root_children_visible_ifs.present?
198
196
  checks << "root_children_visible_unless: #{root_children_visible_unlesses.map(&:reason)}" if root_children_visible_unlesses.present?
199
197
  checks << "root_children_editable_if: #{root_children_editable_ifs.map(&:reason)}" if root_children_editable_ifs.present?
@@ -252,16 +250,16 @@ class ViewModel::AccessControl::Tree < ViewModel::AccessControl
252
250
 
253
251
  def save_root_visibility!(traversal_env)
254
252
  result = check_delegates(traversal_env,
255
- self.class.each_check(:root_children_visible_ifs, ->(a) { a.is_a?(Node) }),
256
- self.class.each_check(:root_children_visible_unlesses, ->(a) { a.is_a?(Node) }))
253
+ self.class.each_check(:root_children_visible_ifs, ->(a) { a < Node }),
254
+ self.class.each_check(:root_children_visible_unlesses, ->(a) { a < Node }))
257
255
 
258
256
  store_descendent_visibility(traversal_env.view, result)
259
257
  end
260
258
 
261
259
  def save_root_editability!(traversal_env)
262
260
  result = check_delegates(traversal_env,
263
- self.class.each_check(:root_children_editable_ifs, ->(a) { a.is_a?(Node) }),
264
- self.class.each_check(:root_children_editable_unlesses, ->(a) { a.is_a?(Node) }))
261
+ self.class.each_check(:root_children_editable_ifs, ->(a) { a < Node }),
262
+ self.class.each_check(:root_children_editable_unlesses, ->(a) { a < Node }))
265
263
 
266
264
  store_descendent_editability(traversal_env.view, result)
267
265
  end
@@ -14,7 +14,7 @@ class ViewModel::Migration::NoPathError < ViewModel::AbstractError
14
14
  end
15
15
 
16
16
  def detail
17
- "No migration path for #{vm_name} from #{from} to #{to}"
17
+ "No migration path for #{vm_name} between client version #{from} and server version #{to}"
18
18
  end
19
19
 
20
20
  def meta
data/lib/view_model.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  # A ViewModel encapsulates a particular aggregation of data calculated via the
4
4
  # underlying models and provides a means of serializing it into views.
5
5
  require 'jbuilder'
6
+ require 'base64'
6
7
  require 'deep_preloader'
7
8
 
8
9
  class ViewModel
@@ -319,6 +319,26 @@ class ViewModel::AccessControlTest < ActiveSupport::TestCase
319
319
  assert_serializes(Tree1View, make_tree('rule:visible_children', 'visible child', 'rule:visible_children', 'visible child'))
320
320
  end
321
321
 
322
+ def test_root_inheritance
323
+ parent_access_control = Class.new(ViewModel::AccessControl::Tree)
324
+ parent_access_control.view 'Tree1' do
325
+ visible_if!('true') { true }
326
+
327
+ root_children_visible_if!('root children visible') do
328
+ view.val == 'rule:visible_children'
329
+ end
330
+ end
331
+
332
+ TestAccessControl.include_from(parent_access_control)
333
+
334
+ refute_serializes(Tree1View, make_tree('arbitrary parent', 'invisible child'))
335
+ assert_serializes(Tree1View, make_tree('rule:visible_children', 'visible child'))
336
+
337
+ # nested root
338
+ refute_serializes(Tree1View, make_tree('rule:visible_children', 'visible child', 'arbitrary parent', 'invisible child'))
339
+ assert_serializes(Tree1View, make_tree('rule:visible_children', 'visible child', 'rule:visible_children', 'visible child'))
340
+ end
341
+
322
342
  def test_visibility_veto_from_root
323
343
  TestAccessControl.view 'Tree1' do
324
344
  root_children_visible_unless!('root children invisible') do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 3.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-16 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -509,7 +509,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
509
509
  - !ruby/object:Gem::Version
510
510
  version: '0'
511
511
  requirements: []
512
- rubygems_version: 3.1.6
512
+ rubygems_version: 3.3.11
513
513
  signing_key:
514
514
  specification_version: 4
515
515
  summary: ViewModels provide a means of encapsulating a collection of related data