jsonapi-authorization 1.0.0.alpha5 → 1.0.0.alpha6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1740e99c89b7ed5a7872ac09f90e25de714f2b3c
|
4
|
+
data.tar.gz: 4c7d58578b5814ba853ff871917df33904c61eb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b0202b9e8f5a0fa11f594ff35f62173ae7e4c326dff6011783c4300ac0165b0be779beb1d5e8268000fa597417ebf9bd2c48fc59975eef95ecbb769a53236d1
|
7
|
+
data.tar.gz: 6846fa8b449885c8addfbfa11e36ab5fd4e6f4f62249bbabe70772a5ecad4d65ad5c5005b739f90812cb1e2ecd0d7e8ac39bf6b1cb4d539199083d24186ab4b6
|
@@ -16,6 +16,11 @@ module JSONAPI
|
|
16
16
|
set_callback :create_to_many_relationships, :before, :authorize_create_to_many_relationships
|
17
17
|
set_callback :replace_to_many_relationships, :before, :authorize_replace_to_many_relationships
|
18
18
|
set_callback :remove_to_many_relationships, :before, :authorize_remove_to_many_relationships
|
19
|
+
set_callback(
|
20
|
+
:replace_polymorphic_to_one_relationship,
|
21
|
+
:before,
|
22
|
+
:authorize_replace_polymorphic_to_one_relationship
|
23
|
+
)
|
19
24
|
|
20
25
|
[
|
21
26
|
:find,
|
@@ -216,6 +221,39 @@ module JSONAPI
|
|
216
221
|
authorizer.remove_to_one_relationship(source_record, relationship_type)
|
217
222
|
end
|
218
223
|
|
224
|
+
def authorize_replace_polymorphic_to_one_relationship
|
225
|
+
return authorize_remove_to_one_relationship if params[:key_value].nil?
|
226
|
+
|
227
|
+
source_resource = @resource_klass.find_by_key(
|
228
|
+
params[:resource_id],
|
229
|
+
context: context
|
230
|
+
)
|
231
|
+
source_record = source_resource._model
|
232
|
+
|
233
|
+
# Fetch the name of the new class based on the incoming polymorphic
|
234
|
+
# "type" value. This will fail if there is no associated resource for the
|
235
|
+
# incoming "type" value so this shouldn't leak constants
|
236
|
+
related_record_class_name = source_resource
|
237
|
+
.send(:_model_class_name, params[:key_type])
|
238
|
+
|
239
|
+
# Fetch the underlying Resource class for the new record to-be-associated
|
240
|
+
related_resource_klass = @resource_klass.resource_for(related_record_class_name)
|
241
|
+
|
242
|
+
new_related_resource = related_resource_klass
|
243
|
+
.find_by_key(
|
244
|
+
params[:key_value],
|
245
|
+
context: context
|
246
|
+
)
|
247
|
+
new_related_record = new_related_resource._model unless new_related_resource.nil?
|
248
|
+
|
249
|
+
relationship_type = params[:relationship_type].to_sym
|
250
|
+
authorizer.replace_to_one_relationship(
|
251
|
+
source_record,
|
252
|
+
new_related_record,
|
253
|
+
relationship_type
|
254
|
+
)
|
255
|
+
end
|
256
|
+
|
219
257
|
private
|
220
258
|
|
221
259
|
def authorizer
|
@@ -309,7 +347,7 @@ module JSONAPI
|
|
309
347
|
next_resource_klass = relationship.resource_klass
|
310
348
|
Array.wrap(
|
311
349
|
source_record.public_send(
|
312
|
-
relationship.relation_name(context)
|
350
|
+
relationship.relation_name(context: context)
|
313
351
|
)
|
314
352
|
).each do |next_source_record|
|
315
353
|
deep.each do |next_include_item|
|
@@ -326,7 +364,7 @@ module JSONAPI
|
|
326
364
|
case relationship
|
327
365
|
when JSONAPI::Relationship::ToOne
|
328
366
|
related_record = source_record.public_send(
|
329
|
-
relationship.relation_name(context)
|
367
|
+
relationship.relation_name(context: context)
|
330
368
|
)
|
331
369
|
return if related_record.nil?
|
332
370
|
authorizer.include_has_one_resource(source_record, related_record)
|
@@ -31,7 +31,7 @@ module JSONAPI
|
|
31
31
|
|
32
32
|
def fetch_relationship(association_name)
|
33
33
|
relationships = self.class._relationships.select do |_k, v|
|
34
|
-
v.relation_name(
|
34
|
+
v.relation_name(context: context) == association_name
|
35
35
|
end
|
36
36
|
if relationships.empty?
|
37
37
|
nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapi-authorization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vesa Laakso
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jsonapi-resources
|