sequel-privacy 0.5 → 0.5.1

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: 8307cc7016667794361e143ba1a17735d2c189079af884a9928df3f67450fed1
4
- data.tar.gz: f6ae84ecd2b0627deeb998d69cc7f38ec73313b5851b4e84b4367335ab6e7b06
3
+ metadata.gz: af7fc02c1fb57d47ba358babdebb3289c2d8eb6ec43d2fce25a2c3477a3f2ccc
4
+ data.tar.gz: a18b09c73b5b03540d2a74f985d32c99b6b2a090a714346f2c87ef5a2997252c
5
5
  SHA512:
6
- metadata.gz: ff39c00cfd1df723a53bca2a75a3ab6fd3657e1475f9f53c48f369de686c3c81facea4af80325b6acfa23e409e6e5fe71b5794ed9c31fad7300f19727f25e7e7
7
- data.tar.gz: fa3124720cb8a285a1033fc3923d3df5f61d04685585394d94614d9bc7331ada3f8863335e91c0198229bfc7238e827b004de2cbed2c88a06fd762328753f8b2
6
+ metadata.gz: 9f46a3f0f253061be75dcd2fb80cf797c1be229d5fd83b1c9f1c86860621dae4536ea60b06df4e38d2d6b1e66f0e90533f0d3a75dddc48be388898ac1d8517d4
7
+ data.tar.gz: f4aee413ab143a08366b223e2c34d62165c69f1e63871eee400d6f82af3c096266e0646f3b4d3d4649a761c913e2c07cef8f852586f0c535d0af3daf1d02f9a6
@@ -405,8 +405,10 @@ module Sequel
405
405
  case type
406
406
  when :many_to_one, :one_to_one
407
407
  _override_singular_association(name)
408
+ _override_association_dataset(name)
408
409
  when :one_to_many, :many_to_many
409
410
  _override_plural_association(name)
411
+ _override_association_dataset(name)
410
412
  # Check if there are already privacy policies defined for this association
411
413
  setup_association_privacy(name) if privacy_association_policies[name]
412
414
  end
@@ -436,6 +438,29 @@ module Sequel
436
438
 
437
439
  private
438
440
 
441
+ sig { params(name: Symbol).void }
442
+ def _override_association_dataset(name)
443
+ dataset_method = :"#{name}_dataset"
444
+ return unless method_defined?(dataset_method)
445
+
446
+ original = instance_method(dataset_method)
447
+ assoc_reflection = association_reflection(name)
448
+ assoc_class = T.let(nil, T.nilable(T.class_of(Sequel::Model)))
449
+
450
+ define_method(dataset_method) do |*args|
451
+ ds = original.bind(self).(*args)
452
+ vc = instance_variable_get(:@viewer_context)
453
+ return ds unless vc
454
+
455
+ assoc_class ||= assoc_reflection.associated_class
456
+ if assoc_class.respond_to?(:privacy_vc_key) && ds.respond_to?(:for_vc)
457
+ T.unsafe(ds).for_vc(vc)
458
+ else
459
+ ds
460
+ end
461
+ end
462
+ end
463
+
439
464
  sig { params(name: Symbol).void }
440
465
  def _override_singular_association(name)
441
466
  original = instance_method(name)
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Sequel
5
5
  module Privacy
6
- VERSION = '0.5'
6
+ VERSION = '0.5.1'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-privacy
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Bales