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 +4 -4
- data/lib/sequel/plugins/privacy.rb +25 -0
- data/lib/sequel/privacy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af7fc02c1fb57d47ba358babdebb3289c2d8eb6ec43d2fce25a2c3477a3f2ccc
|
|
4
|
+
data.tar.gz: a18b09c73b5b03540d2a74f985d32c99b6b2a090a714346f2c87ef5a2997252c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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)
|