mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add a paginated organization members endpoint (#16835)
Closes [coder/internal#460](https://github.com/coder/internal/issues/460)
This commit is contained in:
@@ -3581,6 +3581,14 @@ 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) {
|
||||
// Required to have permission to read all members in the organization
|
||||
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceOrganizationMember.InOrg(arg.OrganizationID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -985,6 +985,32 @@ 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{})
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
mem := dbgen.OrganizationMember(s.T(), db, database.OrganizationMember{
|
||||
OrganizationID: o.ID,
|
||||
UserID: u.ID,
|
||||
Roles: []string{rbac.RoleOrgAdmin()},
|
||||
})
|
||||
|
||||
check.Args(database.PaginatedOrganizationMembersParams{
|
||||
OrganizationID: o.ID,
|
||||
LimitOpt: 0,
|
||||
}).Asserts(
|
||||
rbac.ResourceOrganizationMember.InOrg(o.ID), policy.ActionRead,
|
||||
).Returns([]database.PaginatedOrganizationMembersRow{
|
||||
{
|
||||
OrganizationMember: mem,
|
||||
Username: u.Username,
|
||||
AvatarURL: u.AvatarURL,
|
||||
Name: u.Name,
|
||||
Email: u.Email,
|
||||
GlobalRoles: u.RBACRoles,
|
||||
Count: 1,
|
||||
},
|
||||
})
|
||||
}))
|
||||
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{})
|
||||
|
||||
@@ -503,7 +503,7 @@ func asserts(inputs ...any) []AssertRBAC {
|
||||
// Could be the string type.
|
||||
actionAsString, ok := inputs[i+1].(string)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("action '%q' not a supported action", actionAsString))
|
||||
panic(fmt.Sprintf("action '%T' not a supported action", inputs[i+1]))
|
||||
}
|
||||
action = policy.Action(actionAsString)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user