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

Add support for conditional relationships #450

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

timkomip
Copy link

@timkomip timkomip commented Apr 7, 2023

History

Setting the readable option on a relationship to a callables (procs, lambdas, etc) would only evaulate on load (once). Conditionally hiding relationships per request was not supported. Feature was disabled

Current State (before PR)

readable option on relationships (has_many, belongs_to) doesn't support callables (procs, lambdas, etc).

This PR

Adds support for setting readable with callables.

Changes

  • Sideload evaluates readable flag every time so that the read conditions can be check against current request (or context)
  • Move readable check to serializer. Sets :if option on JSONAPI::Serializable::Relationship object with lambda that calls sideload.readable?
  • Apply sideload/relationship without checking readable? on sideload since the check will be happening in the serializer.
  • Filters out the include from the include_hash if the current included relationships is not readable.

@@ -767,7 +767,7 @@ def admin?(object)
end
end

context "when a sideload macro not readable" do
xcontext "when a sideload macro not readable" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timkomip why are these skipped now?

@jkeen jkeen added the question label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants