-
Notifications
You must be signed in to change notification settings - Fork 361
feat: Add support for self keyword in schema for referencing a resource as a subject
#2785
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
base: main
Are you sure you want to change the base?
Conversation
68afbcc to
88b7ebc
Compare
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (39.56%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.
Additional details and impacted files@@ Coverage Diff @@
## main #2785 +/- ##
===========================================
- Coverage 78.50% 39.56% -38.94%
===========================================
Files 458 414 -44
Lines 44253 40864 -3389
===========================================
- Hits 34736 16163 -18573
- Misses 6698 22828 +16130
+ Partials 2819 1873 -946 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
88b7ebc to
9885a51
Compare
4fdb542 to
1230ce6
Compare
tstirrat15
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
| case core.ReachabilityEntrypoint_SELF_ENTRYPOINT: | ||
| containingRelation := entrypoint.ContainingRelationOrPermission() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't completely understand this part of the implementation. Where is the self logic here? Or is it actually implemented elsewhere?
| } | ||
| definition resource { | ||
| relation viewer: user#me_or_related | user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we refactor this to use an arrow, or is there something important about this being a userset?
| withTenantPrefix, | ||
| `definition expressioned { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't these need the use flags?
|
|
||
| // Look for `use somefeature` | ||
| if nextToken.Kind == TokenTypeIdentifier { | ||
| if nextToken.Kind == TokenTypeIdentifier || nextToken.Kind == TokenTypeKeyword { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this necessary? Is it because we've already reserved self?
We'll probably refactor this when we go and collapse composableschemadsl and schemadsl.
|
|
||
| return lexeme, false | ||
| }, | ||
| // TODO add typechecking flag? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context?
| if !p.isKeyword("self") { | ||
| return nil, false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's not necessary based on how this function is invoked. Is it worth keeping just so that the caller doesn't have to know that?
|
|
||
| node := p.startNode(dslshape.NodeTypeSelfExpression) | ||
| p.consumeKeyword("self") | ||
| defer p.mustFinishNode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, move up
pkg/query/build_tree.go
Outdated
| case *schema.SelfReference: | ||
| return NewEmptyFixedIterator(), nil // TODO is this ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update this - we're not actually checking the self relation because we're not asserting that a user is me_or_related to themselves.
4fcd516 to
1307604
Compare
| } | ||
| } | ||
| // Return the empty set if none of the resources matches | ||
| return func(yield func(Path, error) bool) {}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a helper for this (EmptyPathSeq()) but I went to find it and found more copies of this; so this is fine and I'll do a chore on it.
barakmich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my end -- I checked pkg/query and pkg/schema/v2 thoroughly, and gave the parser a glance from my recollection of it
|
For anyone following along: The integration tests are broken because the expected relations portion of the integration test harness makes an assumption that it can calculate all accessibility information based on the test relations defined in the validation file. That no longer holds for Barak and I talked about how we might fix it both in the short term and the long term; I'd like to revisit that conversation on Monday and figure out whether we want to just get this PR through or come up with a better way of structuring the integration tests. |
Reverts #1515
Fixes #338
Continues #1511
Description
The reason we reverted #1511 is that we'd break schemas where folks were using
selfas an actual relation name. We now have a mechanism to work around that, which isusedirectives. This updates the code from #1511 to introduce ause selfdirective which enables this feature at the schema level, disallows the use ofselfas a normal relation name, and then compiles accordingly.TODO
Changes
Will annotate. See commits after the first one for the changes required for the
usedirective.Testing
Review. See that tests pass.