sequel-privacy 0.5.6 → 0.6
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 +43 -12
- data/lib/sequel/privacy/enforcer.rb +1 -1
- data/lib/sequel/privacy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6aa19c5eda5b7d5be5a491fd8aa877037c1b79014245d2a400f647fb7aa2d174
|
|
4
|
+
data.tar.gz: f29f6df4a6418febe64508727df1cb8e2e611b31ea02ae3b8dda9516cdc5fd90
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a466793f9a3ddb2c3938f6434a56a7262569820ae3a9c8fb752c0f7d163f3b8bdfad3d09f9750fe4771d28fbb8171a780e9569963429dda2edc5e0f2b2ac68a
|
|
7
|
+
data.tar.gz: bf7059897a808ff8466b2054f632a682bbf5e8201995760999259baaac3753d7116f6fe1159ec868ca1dfc40d5166697982a47f4b8dc494615c0337fdad14f2f
|
|
@@ -43,10 +43,15 @@ module Sequel
|
|
|
43
43
|
model.instance_variable_set(:@privacy_association_policies, {})
|
|
44
44
|
model.instance_variable_set(:@privacy_finalized, false)
|
|
45
45
|
model.instance_variable_set(:@allow_unsafe_access, false)
|
|
46
|
+
model.instance_variable_set(:@privacy_wrapped_association_reflections, {})
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
sig { params(model: T.class_of(Sequel::Model), opts: T::Hash[Symbol, T.untyped]).void }
|
|
49
|
-
def self.configure(model, opts = {})
|
|
50
|
+
def self.configure(model, opts = {})
|
|
51
|
+
model.all_association_reflections.each do |reflection|
|
|
52
|
+
model.send(:_setup_privacy_association_readers, reflection[:type], reflection[:name], true)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
50
55
|
|
|
51
56
|
class AssociationPrivacyDSL
|
|
52
57
|
extend T::Sig
|
|
@@ -146,6 +151,7 @@ module Sequel
|
|
|
146
151
|
:@privacy_policies => :dup,
|
|
147
152
|
:@privacy_fields => :dup,
|
|
148
153
|
:@privacy_association_policies => :dup,
|
|
154
|
+
:@privacy_wrapped_association_reflections => :dup,
|
|
149
155
|
:@privacy_finalized => nil,
|
|
150
156
|
:@allow_unsafe_access => nil
|
|
151
157
|
)
|
|
@@ -350,15 +356,7 @@ module Sequel
|
|
|
350
356
|
opts = _inject_privacy_eager_block(opts)
|
|
351
357
|
result = super
|
|
352
358
|
|
|
353
|
-
|
|
354
|
-
when :many_to_one, :one_to_one
|
|
355
|
-
_override_singular_association(name)
|
|
356
|
-
_override_association_dataset(name)
|
|
357
|
-
when :one_to_many, :many_to_many
|
|
358
|
-
_override_plural_association(name)
|
|
359
|
-
_override_association_dataset(name)
|
|
360
|
-
setup_association_privacy(name) if privacy_association_policies[name]
|
|
361
|
-
end
|
|
359
|
+
_setup_privacy_association_readers(type, name, false)
|
|
362
360
|
|
|
363
361
|
result
|
|
364
362
|
end
|
|
@@ -368,7 +366,11 @@ module Sequel
|
|
|
368
366
|
# DatasetMethods#post_load). Preserves any user-supplied block.
|
|
369
367
|
sig { params(opts: T::Hash[Symbol, T.untyped]).returns(T::Hash[Symbol, T.untyped]) }
|
|
370
368
|
def _inject_privacy_eager_block(opts)
|
|
371
|
-
|
|
369
|
+
opts.merge(eager_block: _privacy_eager_block(opts[:eager_block]))
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
sig { params(original: T.untyped).returns(Proc) }
|
|
373
|
+
def _privacy_eager_block(original)
|
|
372
374
|
wrapped = proc do |ds|
|
|
373
375
|
ds = original.call(ds) if original
|
|
374
376
|
vc = Thread.current[DatasetMethods::EAGER_VC_KEY]
|
|
@@ -378,11 +380,40 @@ module Sequel
|
|
|
378
380
|
ds
|
|
379
381
|
end
|
|
380
382
|
end
|
|
381
|
-
|
|
383
|
+
wrapped
|
|
382
384
|
end
|
|
383
385
|
|
|
384
386
|
private
|
|
385
387
|
|
|
388
|
+
sig { params(type: Symbol, name: Symbol, inject_eager_block: T::Boolean).void }
|
|
389
|
+
def _setup_privacy_association_readers(type, name, inject_eager_block)
|
|
390
|
+
reflection = association_reflection(name)
|
|
391
|
+
return unless reflection
|
|
392
|
+
|
|
393
|
+
@privacy_wrapped_association_reflections ||= T.let(
|
|
394
|
+
{},
|
|
395
|
+
T.nilable(T::Hash[Symbol, T.untyped])
|
|
396
|
+
)
|
|
397
|
+
wrapped = @privacy_wrapped_association_reflections
|
|
398
|
+
return if wrapped[name].equal?(reflection)
|
|
399
|
+
|
|
400
|
+
if inject_eager_block
|
|
401
|
+
reflection[:eager_block] = _privacy_eager_block(reflection[:eager_block])
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
case type
|
|
405
|
+
when :many_to_one, :one_to_one
|
|
406
|
+
_override_singular_association(name)
|
|
407
|
+
_override_association_dataset(name)
|
|
408
|
+
when :one_to_many, :many_to_many
|
|
409
|
+
_override_plural_association(name)
|
|
410
|
+
_override_association_dataset(name)
|
|
411
|
+
setup_association_privacy(name) if privacy_association_policies[name]
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
wrapped[name] = reflection
|
|
415
|
+
end
|
|
416
|
+
|
|
386
417
|
sig { params(name: Symbol).void }
|
|
387
418
|
def _override_association_dataset(name)
|
|
388
419
|
dataset_method = :"#{name}_dataset"
|
|
@@ -61,7 +61,7 @@ module Sequel
|
|
|
61
61
|
|
|
62
62
|
# Fail-secure: every chain ends with AlwaysDeny.
|
|
63
63
|
unless policies.last == BuiltInPolicies::AlwaysDeny
|
|
64
|
-
logger&.
|
|
64
|
+
logger&.debug { 'Policy chain should end with AlwaysDeny. Appending it.' }
|
|
65
65
|
policies = policies.dup << BuiltInPolicies::AlwaysDeny
|
|
66
66
|
end
|
|
67
67
|
|
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.
|
|
4
|
+
version: '0.6'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Austin Bales
|
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
138
|
- !ruby/object:Gem::Version
|
|
139
139
|
version: '0'
|
|
140
140
|
requirements: []
|
|
141
|
-
rubygems_version:
|
|
141
|
+
rubygems_version: 4.0.15
|
|
142
142
|
specification_version: 4
|
|
143
143
|
summary: Privacy enforcement plugin for Sequel models
|
|
144
144
|
test_files: []
|