feat: filter users by github user id in the users list CLI command (#17029)

Add the `--github-user-id` option to `coder users list`, which makes the
command only return users with a matching GitHub user id. This will
enable https://github.com/coder/start-workspace-action to find a Coder
user that corresponds to a GitHub user requesting to start a workspace.
This commit is contained in:
Hugo Dutka
2025-03-21 13:30:47 +01:00
committed by GitHub
parent 69ba27e347
commit a71aa202dc
11 changed files with 124 additions and 30 deletions
+10
View File
@@ -6578,6 +6578,16 @@ func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
users = usersFilteredByLastSeen
}
if params.GithubComUserID != 0 {
usersFilteredByGithubComUserID := make([]database.User, 0, len(users))
for i, user := range users {
if user.GithubComUserID.Int64 == params.GithubComUserID {
usersFilteredByGithubComUserID = append(usersFilteredByGithubComUserID, users[i])
}
}
users = usersFilteredByGithubComUserID
}
beforePageCount := len(users)
if params.OffsetOpt > 0 {
+1
View File
@@ -393,6 +393,7 @@ func (q *sqlQuerier) GetAuthorizedUsers(ctx context.Context, arg GetUsersParams,
arg.LastSeenAfter,
arg.CreatedBefore,
arg.CreatedAfter,
arg.GithubComUserID,
arg.OffsetOpt,
arg.LimitOpt,
)
+19 -12
View File
@@ -11632,29 +11632,35 @@ WHERE
created_at >= $8
ELSE true
END
AND CASE
WHEN $9 :: bigint != 0 THEN
github_com_user_id = $9
ELSE true
END
-- End of filters
-- Authorize Filter clause will be injected below in GetAuthorizedUsers
-- @authorize_filter
ORDER BY
-- Deterministic and consistent ordering of all users. This is to ensure consistent pagination.
LOWER(username) ASC OFFSET $9
LOWER(username) ASC OFFSET $10
LIMIT
-- A null limit means "no limit", so 0 means return all
NULLIF($10 :: int, 0)
NULLIF($11 :: int, 0)
`
type GetUsersParams struct {
AfterID uuid.UUID `db:"after_id" json:"after_id"`
Search string `db:"search" json:"search"`
Status []UserStatus `db:"status" json:"status"`
RbacRole []string `db:"rbac_role" json:"rbac_role"`
LastSeenBefore time.Time `db:"last_seen_before" json:"last_seen_before"`
LastSeenAfter time.Time `db:"last_seen_after" json:"last_seen_after"`
CreatedBefore time.Time `db:"created_before" json:"created_before"`
CreatedAfter time.Time `db:"created_after" json:"created_after"`
OffsetOpt int32 `db:"offset_opt" json:"offset_opt"`
LimitOpt int32 `db:"limit_opt" json:"limit_opt"`
AfterID uuid.UUID `db:"after_id" json:"after_id"`
Search string `db:"search" json:"search"`
Status []UserStatus `db:"status" json:"status"`
RbacRole []string `db:"rbac_role" json:"rbac_role"`
LastSeenBefore time.Time `db:"last_seen_before" json:"last_seen_before"`
LastSeenAfter time.Time `db:"last_seen_after" json:"last_seen_after"`
CreatedBefore time.Time `db:"created_before" json:"created_before"`
CreatedAfter time.Time `db:"created_after" json:"created_after"`
GithubComUserID int64 `db:"github_com_user_id" json:"github_com_user_id"`
OffsetOpt int32 `db:"offset_opt" json:"offset_opt"`
LimitOpt int32 `db:"limit_opt" json:"limit_opt"`
}
type GetUsersRow struct {
@@ -11689,6 +11695,7 @@ func (q *sqlQuerier) GetUsers(ctx context.Context, arg GetUsersParams) ([]GetUse
arg.LastSeenAfter,
arg.CreatedBefore,
arg.CreatedAfter,
arg.GithubComUserID,
arg.OffsetOpt,
arg.LimitOpt,
)
+5
View File
@@ -223,6 +223,11 @@ WHERE
created_at >= @created_after
ELSE true
END
AND CASE
WHEN @github_com_user_id :: bigint != 0 THEN
github_com_user_id = @github_com_user_id
ELSE true
END
-- End of filters
-- Authorize Filter clause will be injected below in GetAuthorizedUsers