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

ListUsers intersection #1467

Merged
merged 11 commits into from
Mar 21, 2024
Merged

ListUsers intersection #1467

merged 11 commits into from
Mar 21, 2024

Conversation

willvedd
Copy link
Contributor

@willvedd willvedd commented Mar 19, 2024

Description

Adding support for intersection rewrites in ListUsers via the and operator.

To achieve this, we need to execute the expand against all children of the intersection rewrite. We then aggregate the frequency count of all of the returned users. If that count is equal to the number of children, that indicates that the user was present in all intersection rewrite expands, thus we push it onto the main results channel.

This work may need to be refactored slightly when exclusion is introduced.

References

Parent PR: #1428

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@willvedd willvedd marked this pull request as ready for review March 19, 2024 22:29
@willvedd willvedd requested a review from a team as a code owner March 19, 2024 22:29
@willvedd willvedd mentioned this pull request Mar 20, 2024
4 tasks
@miparnisari miparnisari merged commit 600fe9a into list-users Mar 21, 2024
5 checks passed
@miparnisari miparnisari deleted the listusers-intersection branch March 21, 2024 00:18
@@ -857,8 +857,7 @@ func TestListUsersIntersection(t *testing.T) {
})
tests := ListUsersTests{
Copy link
Member

@miparnisari miparnisari Mar 21, 2024

Choose a reason for hiding this comment

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

I realized after merging this that there is one unit test worth adding, and it's currently failing:

{
			name: "intersection_and_wildcard",
			req: &openfgav1.ListUsersRequest{
				Object:   &openfgav1.Object{Type: "document", Id: "1"},
				Relation: "can_view",
				UserFilters: []*openfgav1.ListUsersFilter{
					{
						Type: "user",
					},
				},
			},
			model: `model
            schema 1.1
          type user
          type document
            relations
              define allowed: [user]
              define viewer: [user:*] and allowed
              define can_view: viewer`,

			tuples: []*openfgav1.TupleKey{
				tuple.NewTupleKey("document:1", "allowed", "user:jon"),
				tuple.NewTupleKey("document:1", "viewer", "user:*"),
				tuple.NewTupleKey("document:2", "viewer", "user:*"),
			},
			expectedUsers: []string{"user:jon"},
		},

For reference, this appears in https://github.com/openfga/openfga/blob/main/assets/tests/consolidated_1_1_tests.yaml#L4595-L4659

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point! Addressed in #1485.

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.

None yet

2 participants