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

Initial support for Intersection arrow #1937

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

josephschorr
Copy link
Member

@josephschorr josephschorr commented Jun 13, 2024

Adds support for intersection arrow and new syntax for existing arrows.

Existing arrow, two syntaxes:

permission view = folder->view
permission view = folder.any(view)

New syntax for intersection arrow:

permission view = folder.all(view)

The folder.all(view) syntax will ensure that a subject is found for view in all folders for the parent resource

Fixes #597

@github-actions github-actions bot added area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/dispatch Affects dispatching of requests labels Jun 13, 2024
@josephschorr josephschorr marked this pull request as ready for review June 13, 2024 19:04
@josephschorr josephschorr requested a review from a team as a code owner June 13, 2024 19:04
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

Overall this looks really good!

I'm mostly concerned about test coverage for more complex schemas, though I think there's some low-hanging performance fruit as well.

tuple.MustParse("document:doc2#parent@folder:folder2-2"),
tuple.MustParse("document:doc2#parent@folder:folder2-3"),
tuple.MustParse("folder:folder2-1#viewer@user:tom"),
tuple.MustParse("folder:folder2-2#viewer@user:tom"),
Copy link
Contributor

Choose a reason for hiding this comment

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

add a 0 case: a document that is in no folders.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

),
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any test cases for (not just for LR, the other methods too):

  • an all over a recursive relationship
  • an all that is part of an expression

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

return checkIntersectionTupleToUserset(ctx, cc, crc, child.FunctionedTupleToUserset)

default:
return checkResultError(spiceerrors.MustBugf("unknown functioned tuple to userset function `%s`", child.FunctionedTupleToUserset.Function), emptyMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit/suggestion:

Suggested change
return checkResultError(spiceerrors.MustBugf("unknown functioned tuple to userset function `%s`", child.FunctionedTupleToUserset.Function), emptyMetadata)
return checkResultError(spiceerrors.MustBugf("unknown tuple to userset function `%s`", child.FunctionedTupleToUserset.Function), emptyMetadata)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed

func (ce *ConcurrentExpander) expandTupleToUserset(_ context.Context, req ValidatedExpandRequest, ttu *core.TupleToUserset) ReduceableExpandFunc {
type expandFunc func(ctx context.Context, start *core.ObjectAndRelation, requests []ReduceableExpandFunc) ExpandResult

func expandTupleToUserset[T relation](
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any tests for expand?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

it.Close()

// Wait for all dispatched operations to complete.
if err := g.Wait(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need to wait here - since this is an AND operation, you can just add in the sets as you get them (it's associative and commutative). That should keep memory lower too.

ns.MustFunctionedTupleToUserset("owner", "any", "something"),
)),
ns.MustRelation("thirdwithall", ns.Union(
ns.MustFunctionedTupleToUserset("owner", "all", "something"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some cases in here with expressions containing the fn arrows to make sure they canonicalize the same?

i.e. owner.all(something) + foo == foo + owner.all(something)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added


case core.FunctionedTupleToUserset_FUNCTION_ALL:
// Mark as a conditional result.
operationResultState = core.ReachabilityEntrypoint_REACHABLE_CONDITIONAL_RESULT
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this conditional? I would think it would be marked the same as a regular arrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

The intersection results in a check being required. This ensures that all is checked post reachable resources.

}

// Create a membership set per-subject-type, representing the membership for each of the dispatched subjects.
resultsByDispatchedSubject := map[string]*MembershipSet{}
Copy link
Contributor

Choose a reason for hiding this comment

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

I made a similar comment on one of the other graph methods, but you don't have to collect up all of the results before you combine them; you can combine as you get responses back.

@josephschorr
Copy link
Member Author

Updated

@josephschorr josephschorr added this pull request to the merge queue Jun 28, 2024
Merged via the queue into authzed:main with commit 42b739f Jun 28, 2024
22 checks passed
@josephschorr josephschorr deleted the intersection-arrow branch June 28, 2024 20:22
@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/dispatch Affects dispatching of requests area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intersection Arrow Proposal
2 participants