-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add a paginated organization members endpoint #16835
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
Changes from 10 commits
cea4d3c
e97c9db
34003dc
9edb088
ef40967
6aaddaf
a724f48
4925592
902538c
06ff95c
560305d
76a4cbf
737ac9f
8910df3
0e579a2
73e356c
24332f4
7af0b60
cdc0322
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1002,6 +1002,9 @@ func New(options *Options) *API { | |||||||||
}) | ||||||||||
}) | ||||||||||
}) | ||||||||||
r.Route("/paginated-members", func(r chi.Router) { | ||||||||||
r.Get("/", api.paginatedMembers) | ||||||||||
}) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I wouldn't bother with the subrouter here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw this was a pattern we were doing in other places so copied that. Will change |
||||||||||
r.Route("/members", func(r chi.Router) { | ||||||||||
r.Get("/", api.listMembers) | ||||||||||
r.Route("/roles", func(r chi.Router) { | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3581,6 +3581,13 @@ func (q *querier) OrganizationMembers(ctx context.Context, arg database.Organiza | |||||||||||||||
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.OrganizationMembers)(ctx, arg) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func (q *querier) PaginatedOrganizationMembers(ctx context.Context, arg database.PaginatedOrganizationMembersParams) ([]database.PaginatedOrganizationMembersRow, error) { | ||||||||||||||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceOrganizationMember.InOrg(arg.OrganizationID)); err != nil { | ||||||||||||||||
return nil, err | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+3586
to
+3588
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just throw a comment
Suggested change
|
||||||||||||||||
return q.db.PaginatedOrganizationMembers(ctx, arg) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
func (q *querier) ReduceWorkspaceAgentShareLevelToAuthenticatedByTemplate(ctx context.Context, templateID uuid.UUID) error { | ||||||||||||||||
template, err := q.db.GetTemplateByID(ctx, templateID) | ||||||||||||||||
if err != nil { | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -985,6 +985,16 @@ func (s *MethodTestSuite) TestOrganization() { | |
mem, policy.ActionRead, | ||
) | ||
})) | ||
s.Run("PaginatedOrganizationMembers", s.Subtest(func(db database.Store, check *expects) { | ||
o := dbgen.Organization(s.T(), db, database.Organization{}) | ||
|
||
check.Args(database.PaginatedOrganizationMembersParams{ | ||
OrganizationID: o.ID, | ||
LimitOpt: 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this different check means we also don't need this field any more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accidentally pushed some test code in the test so not sure which one you were looking at but that's needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add back the org member in the setup? And check it in the That was breaking in the |
||
}).Asserts( | ||
rbac.ResourceOrganizationMember.InOrg(o.ID), policy.ActionRead, | ||
) | ||
})) | ||
s.Run("UpdateMemberRoles", s.Subtest(func(db database.Store, check *expects) { | ||
o := dbgen.Organization(s.T(), db, database.Organization{}) | ||
u := dbgen.User(s.T(), db, database.User{}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9584,6 +9584,45 @@ func (q *FakeQuerier) OrganizationMembers(_ context.Context, arg database.Organi | |
return tmp, nil | ||
} | ||
|
||
func (q *FakeQuerier) PaginatedOrganizationMembers(_ context.Context, arg database.PaginatedOrganizationMembersParams) ([]database.PaginatedOrganizationMembersRow, error) { | ||
err := validateDatabaseType(arg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
|
||
tmp := make([]database.PaginatedOrganizationMembersRow, 0) | ||
|
||
skippedMembers := 0 | ||
for _, organizationMember := range q.organizationMembers { | ||
if arg.OrganizationID != uuid.Nil && organizationMember.OrganizationID != arg.OrganizationID { | ||
continue | ||
} | ||
|
||
if skippedMembers < int(arg.OffsetOpt) { | ||
skippedMembers++ | ||
continue | ||
} | ||
|
||
if len(tmp) >= int(arg.LimitOpt) { | ||
break | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to check if the limitOpt is not 0. If it is zero, skip this check. To match the SQL |
||
|
||
user, _ := q.getUserByIDNoLock(organizationMember.UserID) | ||
tmp = append(tmp, database.PaginatedOrganizationMembersRow{ | ||
OrganizationMember: organizationMember, | ||
Username: user.Username, | ||
AvatarURL: user.AvatarURL, | ||
Name: user.Name, | ||
Email: user.Email, | ||
GlobalRoles: user.RBACRoles, | ||
}) | ||
} | ||
return tmp, nil | ||
} | ||
|
||
func (q *FakeQuerier) ReduceWorkspaceAgentShareLevelToAuthenticatedByTemplate(_ context.Context, templateID uuid.UUID) error { | ||
err := validateDatabaseType(templateID) | ||
if err != nil { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Really unfortunate we cannot just use the
/members
endpoint without it being a breaking change.Since organizations are new, I think it's worth considering.
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 was originally going to to augment the existing route to be paginated but @aslilac brought up the issue of backwards compatibility. I can circle back with her, and other stakeholders on this
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.
if we were having this discussion like two weeks ago I think I'd agree with you @Emyrk, but 2.20 is out now and marketing organizations as stable. :\