feat: support filtering users table by login type (#17238)

#15896 Mentions ability to add support for filtering by login type

The issue mentions that backend API support exists but the backend did
not seem to have the support for this filter. So I have added the
ability to filter it.

I also added a corresponding update to readme file to make sure the docs
will correctly showcase this feature
This commit is contained in:
Utsavkumar Lal
2025-04-09 13:59:41 +10:00
committed by GitHub
parent f2d24bc3f4
commit 0e658219b2
10 changed files with 226 additions and 24 deletions
+12
View File
@@ -6824,6 +6824,18 @@ func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
users = usersFilteredByRole
}
if len(params.LoginType) > 0 {
usersFilteredByLoginType := make([]database.User, 0, len(users))
for i, user := range users {
if slice.ContainsCompare(params.LoginType, user.LoginType, func(a, b database.LoginType) bool {
return strings.EqualFold(string(a), string(b))
}) {
usersFilteredByLoginType = append(usersFilteredByLoginType, users[i])
}
}
users = usersFilteredByLoginType
}
if !params.CreatedBefore.IsZero() {
usersFilteredByCreatedAt := make([]database.User, 0, len(users))
for i, user := range users {
+1
View File
@@ -395,6 +395,7 @@ func (q *sqlQuerier) GetAuthorizedUsers(ctx context.Context, arg GetUsersParams,
arg.CreatedAfter,
arg.IncludeSystem,
arg.GithubComUserID,
pq.Array(arg.LoginType),
arg.OffsetOpt,
arg.LimitOpt,
)
+10 -2
View File
@@ -12410,16 +12410,22 @@ WHERE
github_com_user_id = $10
ELSE true
END
-- Filter by login_type
AND CASE
WHEN cardinality($11 :: login_type[]) > 0 THEN
login_type = ANY($11 :: login_type[])
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 $11
LOWER(username) ASC OFFSET $12
LIMIT
-- A null limit means "no limit", so 0 means return all
NULLIF($12 :: int, 0)
NULLIF($13 :: int, 0)
`
type GetUsersParams struct {
@@ -12433,6 +12439,7 @@ type GetUsersParams struct {
CreatedAfter time.Time `db:"created_after" json:"created_after"`
IncludeSystem bool `db:"include_system" json:"include_system"`
GithubComUserID int64 `db:"github_com_user_id" json:"github_com_user_id"`
LoginType []LoginType `db:"login_type" json:"login_type"`
OffsetOpt int32 `db:"offset_opt" json:"offset_opt"`
LimitOpt int32 `db:"limit_opt" json:"limit_opt"`
}
@@ -12472,6 +12479,7 @@ func (q *sqlQuerier) GetUsers(ctx context.Context, arg GetUsersParams) ([]GetUse
arg.CreatedAfter,
arg.IncludeSystem,
arg.GithubComUserID,
pq.Array(arg.LoginType),
arg.OffsetOpt,
arg.LimitOpt,
)
+6
View File
@@ -260,6 +260,12 @@ WHERE
github_com_user_id = @github_com_user_id
ELSE true
END
-- Filter by login_type
AND CASE
WHEN cardinality(@login_type :: login_type[]) > 0 THEN
login_type = ANY(@login_type :: login_type[])
ELSE true
END
-- End of filters
-- Authorize Filter clause will be injected below in GetAuthorizedUsers