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

feat(list-users): ListUsers with Excluded Users #1604

Merged
merged 25 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a1ca45f
feat(list-users): ListUsers with Excluded Users
jon-whit May 6, 2024
e9099e7
test: drop residual test that was used for debugging
jon-whit May 6, 2024
0a26449
chore: restructure control flow in expandExclusion block
jon-whit May 8, 2024
f3875d7
chore(lint): fix lint warnings
jon-whit May 8, 2024
4af1cd3
chore: invert control flow blocks in expandExclusion
jon-whit May 8, 2024
a00f6d2
chore: rework control flow for expandExclusion case with base wildcard
jon-whit May 8, 2024
0bc6348
chore: more control flow improvements to expandExclusion
jon-whit May 8, 2024
b872f91
chore: add some godoc and swap to a relationship status enum
jon-whit May 8, 2024
04ef107
Merge branch 'listUsers-excludedUsers' of https://github.com/openfga/…
willvedd May 8, 2024
5f20ffb
Simplifying logic
willvedd May 15, 2024
c6ee655
Adding excluded users handling for intersection
willvedd May 18, 2024
3ac4faa
Adding excluded users handling for union
willvedd May 18, 2024
60aed6d
Fixing integration tests
willvedd May 18, 2024
9ac6e3c
Removing commented-out code
willvedd May 19, 2024
e13e518
Adding and fixing test case
willvedd May 20, 2024
571f71f
Removing pointer receiver, adding tests for InvertRelationshipStatus
willvedd May 20, 2024
243ad9c
test: add another ListUsers test involving excluded users
jon-whit May 8, 2024
b22fad6
test: add a unit test for expandExclusion handler
jon-whit May 20, 2024
4ecf4bc
Merge branch 'listUsers-excludedUsers' of https://github.com/openfga/…
willvedd May 20, 2024
4e62efe
Fixing TestListUsers_ExpandExclusionHandler
willvedd May 20, 2024
9a11034
Removing invert method
willvedd May 20, 2024
f46eb5e
Addressing PR feedback
willvedd May 20, 2024
67424c0
Merge branch 'list-users' of https://github.com/openfga/openfga into …
willvedd May 20, 2024
ad8dadd
chore: drop redundant 'if else'
jon-whit May 20, 2024
2f34a45
chore: simplify code and add a relevant comment
jon-whit May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/tests/consolidated_1_1_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6517,7 +6517,9 @@ tests:
object: document:1
relation: can_view
expectation:
- user:* # TODO but user:bob doesn't have access
- user:*
expectedExcludedUsers:
- user:bob
- request:
filters:
- user
Expand Down
24 changes: 17 additions & 7 deletions internal/test/listusers/listusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

type Assertion struct {
Request *TestListUsersRequest
ContextualTuples []*openfgav1.TupleKey `json:"contextualTuples"`
Context *structpb.Struct
Expectation []string
ErrorCode int `json:"errorCode"` // If ErrorCode is non-zero then we expect that the ListUsers call failed.
Request *TestListUsersRequest
ContextualTuples []*openfgav1.TupleKey `json:"contextualTuples"`
Context *structpb.Struct
Expectation []string
ExpectedExcludedUsers []string `json:"expectedExcludedUsers"`
ErrorCode int `json:"errorCode"` // If ErrorCode is non-zero then we expect that the ListUsers call failed.
}

type TestListUsersRequest struct {
Expand All @@ -28,14 +29,23 @@ func (t *TestListUsersRequest) ToString() string {
return fmt.Sprintf("object=%s, relation=%s, filters=%v", t.Object, t.Relation, strings.Join(t.Filters, ", "))
}

func FromProtoResponse(r *openfgav1.ListUsersResponse) []string {
func FromUsersProto(r []*openfgav1.User) []string {
var users []string
for _, user := range r.GetUsers() {
for _, user := range r {
users = append(users, tuple.UserProtoToString(user))
}
return users
}

func FromObjectOrUsersetProto(u []*openfgav1.ObjectOrUserset) []string {
var users []string
for _, user := range u {
users = append(users, tuple.FromObjectOrUsersetProto(user))
}

return users
}

func (t *TestListUsersRequest) ToProtoRequest() *openfgav1.ListUsersRequest {
var protoFilters []*openfgav1.UserTypeFilter

Expand Down
12 changes: 10 additions & 2 deletions pkg/server/commands/listusers/list_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ func (r *internalListUsersRequest) GetContext() *structpb.Struct {
}

type listUsersResponse struct {
Users []*openfgav1.User
Metadata listUsersResponseMetadata
Users []*openfgav1.User
ExcludedUsers []*openfgav1.ObjectOrUserset
Metadata listUsersResponseMetadata
}

type listUsersResponseMetadata struct {
Expand All @@ -110,6 +111,13 @@ func (r *listUsersResponse) GetUsers() []*openfgav1.User {
return r.Users
}

func (r *listUsersResponse) GetExcludedUsers() []*openfgav1.ObjectOrUserset {
if r == nil {
return []*openfgav1.ObjectOrUserset{}
}
return r.ExcludedUsers
}

func (r *listUsersResponse) GetMetadata() listUsersResponseMetadata {
if r == nil {
return listUsersResponseMetadata{}
Expand Down