Skip to content

Commit e7c6ae0

Browse files
authored
Fix relation_name lambda being broken (#81)
* Fix context not being passed properly in PunditScopedResource * Always pass a hash with :context key to relation_name accessor This seems to be the way jsonapi-resources does it. Although, at some points JR passes way more information down the chain. Unfortunately, that same information is not available in PunditScopedResource so I'll just go with what we can get in all the places. https://github.com/cerebris/jsonapi-resources/blob/5af1f17068b66b0a17b7b69e5db334c640f6f34b/lib/jsonapi/processor.rb#L170-L184
1 parent 24bfed7 commit e7c6ae0

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/jsonapi/authorization/authorizing_processor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def authorize_include_item(resource_klass, source_record, include_item)
347347
next_resource_klass = relationship.resource_klass
348348
Array.wrap(
349349
source_record.public_send(
350-
relationship.relation_name(context)
350+
relationship.relation_name(context: context)
351351
)
352352
).each do |next_source_record|
353353
deep.each do |next_include_item|
@@ -364,7 +364,7 @@ def authorize_include_item(resource_klass, source_record, include_item)
364364
case relationship
365365
when JSONAPI::Relationship::ToOne
366366
related_record = source_record.public_send(
367-
relationship.relation_name(context)
367+
relationship.relation_name(context: context)
368368
)
369369
return if related_record.nil?
370370
authorizer.include_has_one_resource(source_record, related_record)

lib/jsonapi/authorization/pundit_scoped_resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def records_for(association_name)
3131

3232
def fetch_relationship(association_name)
3333
relationships = self.class._relationships.select do |_k, v|
34-
v.relation_name({}) == association_name
34+
v.relation_name(context: context) == association_name
3535
end
3636
if relationships.empty?
3737
nil

0 commit comments

Comments
 (0)