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

Use LEFT JOIN instead of INNER JOIN when translate condition to SQL #25

Open
ccatterina opened this issue Jun 21, 2021 · 0 comments
Open

Comments

@ccatterina
Copy link
Contributor

Hi,
I run into a problem while trying to handle the following situation:
immagine

I want that all users can read their things:

can('read', 'Thing', { "owners.user_id": user.id })

But i want also to add a specific rule to permit to alice to read a Thing that she doesn't own (the thing with id 3), so I have an additional rule for alice that says:

{
  action: 'read',
  subject: 'Thing',
  conditions: { id: 3 }
}

This situation results in a SQL statement similar to:

SELECT ... FROM Thing INNER JOIN ThingsOwners ON Thing.id = ThingsOwners.thing_id WHERE ( Thing.id = 3 or ThingsOwners.user_id = ALICE_ID)

That works as expected until the thing 3 has at least an owner, otherwise the thing 3 is filtered out by the INNER JOIN.

Using LEFT JOIN should fix this issue and afaik it wouldn't introduce any other problem.

What do you think about it? If you are ok with it I can work on a PR to replace INNER JOIN with LEFT JOIN. Thanks!

ccatterina pushed a commit to ccatterina/ucast that referenced this issue Aug 26, 2022
ccatterina pushed a commit to ccatterina/ucast that referenced this issue Aug 26, 2022
ccatterina added a commit to ccatterina/ucast that referenced this issue Aug 26, 2022
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