Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include scoped relationships #1299

Closed
3 of 7 tasks
rpbaltazar opened this issue Dec 6, 2019 · 1 comment
Closed
3 of 7 tasks

Include scoped relationships #1299

rpbaltazar opened this issue Dec 6, 2019 · 1 comment

Comments

@rpbaltazar
Copy link

rpbaltazar commented Dec 6, 2019

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

Choose one section below and delete the other:

Bug reports:

Background info:

  • We are currently using the version 0.9.10 of JR in combination with jsonapi-authorization.
  • There is an open issue in jsonapi-authorization that clearly stops us from updating to the latest version.

Context setup:

  • We have an AR class entity that has_many tier_costs.
  • Some of these tier costs are scoped to a user context. E.g User 1 and User 2 both see the Entity 1. But User 1 can see Tier Cost 1 and 2 while User 2 can see only Tier Cost 1.
  • When the User 1 tries to do the following request: {{baseUrl}}/entities?include=tier_reward_costs all goes well and the included resources are all fine.
  • When the User 2 tries to do the same request the JR throws an error because it tries to fetch a resource that the User 2 does not have access to.

I've pinpointed the source of the problem to:

assoc_rels[rel_id] = target_resources[klass.name].fetch(rel_id)

My suggestion (and I'm submitting a PR in a minute) is that we should add results to the assoc_rels only if its not nil.

Here is the full log:

{
    "errors": [
        {
            "title": "Internal Server Error",
            "detail": "Internal Server Error",
            "code": "500",
            "status": "500",
            "meta": {
                "exception": "key not found: 1",
                "backtrace": [
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1354:in `fetch'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1354:in `block (3 levels) in preload_included_fragments'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1349:in `each'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1349:in `each_with_index'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1349:in `block (2 levels) in preload_included_fragments'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1347:in `each'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1347:in `block in preload_included_fragments'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1259:in `each'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1259:in `preload_included_fragments'",
                    "/home/rails/ros/lib/core/app/models/concerns/association_resource/resource_helper.rb:32:in `preload_included_fragments'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:1191:in `cached_resources_for'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/resource.rb:848:in `find_serialized_with_caching'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/processor.rb:83:in `find'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/processor.rb:58:in `block (2 levels) in process'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:135:in `run_callbacks'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/processor.rb:57:in `block in process'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:101:in `run_callbacks'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/processor.rb:56:in `process'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation.rb:16:in `process'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:58:in `block in process_operation'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:63:in `with_default_handling'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:57:in `process_operation'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:29:in `block (2 levels) in process'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:28:in `each'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:28:in `block in process'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:46:in `transaction'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/operation_dispatcher.rb:24:in `process'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/acts_as_resource_controller.rb:86:in `block in process_operations'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:101:in `run_callbacks'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/acts_as_resource_controller.rb:85:in `process_operations'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/acts_as_resource_controller.rb:77:in `process_request'",
                    "/usr/local/bundle/gems/jsonapi-resources-0.9.10/lib/jsonapi/acts_as_resource_controller.rb:16:in `index'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/abstract_controller/base.rb:196:in `process_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal/rendering.rb:30:in `process_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/abstract_controller/callbacks.rb:42:in `block in process_action'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:135:in `run_callbacks'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/abstract_controller/callbacks.rb:41:in `process_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal/rescue.rb:22:in `process_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/notifications.rb:180:in `block in instrument'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/notifications/instrumenter.rb:24:in `instrument'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/notifications.rb:180:in `instrument'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal/instrumentation.rb:32:in `process_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'",
                    "/usr/local/bundle/gems/activerecord-6.0.0.rc2/lib/active_record/railties/controller_runtime.rb:27:in `process_action'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/abstract_controller/base.rb:136:in `process'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal.rb:191:in `dispatch'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_controller/metal.rb:252:in `dispatch'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/routing/route_set.rb:51:in `dispatch'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/routing/route_set.rb:33:in `serve'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/journey/router.rb:49:in `block in serve'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/journey/router.rb:32:in `each'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/journey/router.rb:32:in `serve'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/routing/route_set.rb:837:in `call'",
                    "/usr/local/bundle/gems/apartment-2.2.1/lib/apartment/elevators/generic.rb:21:in `block in call'",
                    "/usr/local/bundle/gems/apartment-2.2.1/lib/apartment/adapters/abstract_adapter.rb:85:in `switch'",
                    "/usr/local/lib/ruby/2.6.0/forwardable.rb:230:in `switch'",
                    "/usr/local/bundle/gems/apartment-2.2.1/lib/apartment/elevators/generic.rb:21:in `call'",
                    "/usr/local/bundle/gems/warden-1.2.8/lib/warden/manager.rb:36:in `block in call'",
                    "/usr/local/bundle/gems/warden-1.2.8/lib/warden/manager.rb:34:in `catch'",
                    "/usr/local/bundle/gems/warden-1.2.8/lib/warden/manager.rb:34:in `call'",
                    "/usr/local/bundle/gems/apartment-2.2.1/lib/apartment/reloader.rb:18:in `call'",
                    "/usr/local/bundle/gems/rack-2.0.7/lib/rack/etag.rb:25:in `call'",
                    "/usr/local/bundle/gems/rack-2.0.7/lib/rack/conditional_get.rb:25:in `call'",
                    "/usr/local/bundle/gems/rack-2.0.7/lib/rack/head.rb:12:in `call'",
                    "/usr/local/bundle/gems/activerecord-6.0.0.rc2/lib/active_record/migration.rb:567:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:101:in `run_callbacks'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/callbacks.rb:26:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/executor.rb:14:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'",
                    "/usr/local/bundle/gems/railties-6.0.0.rc2/lib/rails/rack/logger.rb:38:in `call_app'",
                    "/usr/local/bundle/gems/railties-6.0.0.rc2/lib/rails/rack/logger.rb:26:in `block in call'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/tagged_logging.rb:80:in `block in tagged'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/tagged_logging.rb:28:in `tagged'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/tagged_logging.rb:80:in `tagged'",
                    "/usr/local/bundle/gems/railties-6.0.0.rc2/lib/rails/rack/logger.rb:26:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'",
                    "/home/rails/ros/lib/core/lib/ros/dtrace_middleware.rb:15:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/request_id.rb:27:in `call'",
                    "/usr/local/bundle/gems/rack-2.0.7/lib/rack/runtime.rb:22:in `call'",
                    "/usr/local/bundle/gems/activesupport-6.0.0.rc2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/executor.rb:14:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/static.rb:126:in `call'",
                    "/usr/local/bundle/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in `call'",
                    "/usr/local/bundle/gems/actionpack-6.0.0.rc2/lib/action_dispatch/middleware/host_authorization.rb:83:in `call'",
                    "/usr/local/bundle/gems/rack-cors-1.0.6/lib/rack/cors.rb:98:in `call'",
                    "/usr/local/bundle/gems/railties-6.0.0.rc2/lib/rails/engine.rb:526:in `call'",
                    "/usr/local/bundle/gems/rack-2.0.7/lib/rack/handler/webrick.rb:86:in `service'",
                    "/usr/local/lib/ruby/2.6.0/webrick/httpserver.rb:140:in `service'",
                    "/usr/local/lib/ruby/2.6.0/webrick/httpserver.rb:96:in `run'",
                    "/usr/local/lib/ruby/2.6.0/webrick/server.rb:307:in `block in start_thread'"
                ]
            }
        }
    ]
}```
lgebhardt added a commit that referenced this issue Dec 10, 2019
…ships

[Resolves #1299] Fix missing scoped association
@lgebhardt
Copy link
Member

Closed with #1300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants