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

Check before loading relations #161

Open
Hesesses opened this issue May 22, 2020 · 0 comments
Open

Check before loading relations #161

Hesesses opened this issue May 22, 2020 · 0 comments

Comments

@Hesesses
Copy link

Hesesses commented May 22, 2020

Hello,

Lets say we have the following models:

  • Company
  • Client
  • Note

Company can have multiple Clients and admins can wrote notes on different clients.

Notes can only be seen by admins.

We have api endpoint GET /clients?with=details,notes which checks if the authenticated user is admin, if not then there is a logic to remove notes from the withparam -> ?with=details which is then used in laravel responder and everything works as should.

We also have endpoint GET /companies?with=clients which returns companies with clients.
But if someone sends a request: GET /companies?with=clients.notes the it will bypass the admin check and will get access to notes as companies endpoint doesnt have any checks for notes.

So the question is, how this problem should be solved using the package:

  1. create custom includeNotes(Client $client) on ClientTransformer function which checks if the authenticated user is admin and then return $client->notes;
    Can this cause some other problems? For example if the with params is with=clients.notes.something.else

  2. is it somehow possible to run the check on NoteTransformer if its allowed to be loaded?
    For example there might be multiple Transformers which want to include notes relation. Having the logic on NoteTransformer there is no need to add the logic on other files

  3. Any other ideas? :)

Edit:

  1. is it possible to limit the with param in the package to exclude sub relations:
    ?with=relation -> load relation
    ?with=relation.sub -> load relation (sub is not loaded)
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

1 participant