Skip to content

Add an option to allow include on a relationship #73

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

Closed
wants to merge 2 commits into from
Closed

Add an option to allow include on a relationship #73

wants to merge 2 commits into from

Conversation

blmundie
Copy link

Add an option to each relationship to allow including in json. The default is to allow include.

@fotinakis
Copy link
Owner

I think that if we end up implementing a lightweight "permission system" for what can be included or not, it probably needs to be dynamic and not static like this. Ie. someone might want to "allow_include" true for admin users for certain relationships, and allow_include false for the same relationships for other users. Unfortunately this implementation is a bit too static for that world.

Also, there is probably a case where you would want to allow includes when starting at certain root elements but not others, ie. allow include of post.user on posts but not category.posts.user on categories, or something like that. In my mind these kinds of includes might expose a security vulnerabilities which I haven't fully thought through, so until we can really enumerate more cases I'd like to leave permission handling up to individual implementations rather than baking in something incomplete.

Would be interested to hear your and other comments on this and what the right strategy could be.

@fotinakis fotinakis closed this May 11, 2016
@blmundie
Copy link
Author

I can change the code to allow a method name or proc to be passed to it as well as true or false. The proc or method could be passed passthrough_options or passthrough_options[:context] to get the current_user info.

For situations like post.user vs category.posts.user it might make more sense to handle the permissions in the relationship vs the include. You could use something like Pundit scopes to limit the category's posts to only the ones the user is permitted to view.

The scenario I need fix is including a parent then it's children. Something like post.category.posts or user.organization.users. I would much rather handle this in the serializer than having to parse the include string separately and checking permissions before serialize.

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

Successfully merging this pull request may close these issues.

2 participants