mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
fix: user search with login_name (e.g. password reset) (#3149)
This commit is contained in:
parent
f96f62a1ab
commit
585ebf9a81
@ -131,9 +131,14 @@ var (
|
|||||||
name: projection.UserTypeCol,
|
name: projection.UserTypeCol,
|
||||||
table: userTable,
|
table: userTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
userLoginNamesTable = loginNameTable.setAlias("login_names")
|
userLoginNamesTable = loginNameTable.setAlias("login_names")
|
||||||
userLoginNamesUserIDCol = LoginNameUserIDCol.setTable(userLoginNamesTable)
|
userLoginNamesUserIDCol = LoginNameUserIDCol.setTable(userLoginNamesTable)
|
||||||
userLoginNamesCol = LoginNameNameCol.setTable(userLoginNamesTable)
|
userLoginNamesNameCol = LoginNameNameCol.setTable(userLoginNamesTable)
|
||||||
|
userLoginNamesListCol = Column{
|
||||||
|
name: "loginnames",
|
||||||
|
table: userLoginNamesTable,
|
||||||
|
}
|
||||||
userPreferredLoginNameTable = loginNameTable.setAlias("preferred_login_name")
|
userPreferredLoginNameTable = loginNameTable.setAlias("preferred_login_name")
|
||||||
userPreferredLoginNameUserIDCol = LoginNameUserIDCol.setTable(userPreferredLoginNameTable)
|
userPreferredLoginNameUserIDCol = LoginNameUserIDCol.setTable(userPreferredLoginNameTable)
|
||||||
userPreferredLoginNameCol = LoginNameNameCol.setTable(userPreferredLoginNameTable)
|
userPreferredLoginNameCol = LoginNameNameCol.setTable(userPreferredLoginNameTable)
|
||||||
@ -411,13 +416,13 @@ func NewUserPreferredLoginNameSearchQuery(value string, comparison TextCompariso
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewUserLoginNamesSearchQuery(value string) (SearchQuery, error) {
|
func NewUserLoginNamesSearchQuery(value string) (SearchQuery, error) {
|
||||||
return NewTextQuery(userLoginNamesCol, value, TextListContains)
|
return NewTextQuery(userLoginNamesListCol, value, TextListContains)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareUserQuery() (sq.SelectBuilder, func(*sql.Row) (*User, error)) {
|
func prepareUserQuery() (sq.SelectBuilder, func(*sql.Row) (*User, error)) {
|
||||||
loginNamesQuery, _, err := sq.Select(
|
loginNamesQuery, _, err := sq.Select(
|
||||||
userLoginNamesUserIDCol.identifier(),
|
userLoginNamesUserIDCol.identifier(),
|
||||||
"ARRAY_AGG("+userLoginNamesCol.identifier()+") as login_names").
|
"ARRAY_AGG("+userLoginNamesNameCol.identifier()+") as "+userLoginNamesListCol.name).
|
||||||
From(userLoginNamesTable.identifier()).
|
From(userLoginNamesTable.identifier()).
|
||||||
GroupBy(userLoginNamesUserIDCol.identifier()).
|
GroupBy(userLoginNamesUserIDCol.identifier()).
|
||||||
ToSql()
|
ToSql()
|
||||||
@ -444,7 +449,7 @@ func prepareUserQuery() (sq.SelectBuilder, func(*sql.Row) (*User, error)) {
|
|||||||
UserStateCol.identifier(),
|
UserStateCol.identifier(),
|
||||||
UserTypeCol.identifier(),
|
UserTypeCol.identifier(),
|
||||||
UserUsernameCol.identifier(),
|
UserUsernameCol.identifier(),
|
||||||
"login_names.login_names",
|
userLoginNamesListCol.identifier(),
|
||||||
userPreferredLoginNameCol.identifier(),
|
userPreferredLoginNameCol.identifier(),
|
||||||
HumanUserIDCol.identifier(),
|
HumanUserIDCol.identifier(),
|
||||||
HumanFirstNameCol.identifier(),
|
HumanFirstNameCol.identifier(),
|
||||||
@ -465,8 +470,8 @@ func prepareUserQuery() (sq.SelectBuilder, func(*sql.Row) (*User, error)) {
|
|||||||
From(userTable.identifier()).
|
From(userTable.identifier()).
|
||||||
LeftJoin(join(HumanUserIDCol, UserIDCol)).
|
LeftJoin(join(HumanUserIDCol, UserIDCol)).
|
||||||
LeftJoin(join(MachineUserIDCol, UserIDCol)).
|
LeftJoin(join(MachineUserIDCol, UserIDCol)).
|
||||||
LeftJoin("("+loginNamesQuery+") as login_names on "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()).
|
LeftJoin("("+loginNamesQuery+") as "+userLoginNamesTable.alias+" on "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()).
|
||||||
LeftJoin("("+preferredLoginNameQuery+") as preferred_login_name on "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...).
|
LeftJoin("("+preferredLoginNameQuery+") as "+userPreferredLoginNameTable.alias+" on "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...).
|
||||||
PlaceholderFormat(sq.Dollar),
|
PlaceholderFormat(sq.Dollar),
|
||||||
func(row *sql.Row) (*User, error) {
|
func(row *sql.Row) (*User, error) {
|
||||||
u := new(User)
|
u := new(User)
|
||||||
@ -753,7 +758,7 @@ func prepareUserUniqueQuery() (sq.SelectBuilder, func(*sql.Row) (bool, error)) {
|
|||||||
func prepareUsersQuery() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) {
|
func prepareUsersQuery() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) {
|
||||||
loginNamesQuery, _, err := sq.Select(
|
loginNamesQuery, _, err := sq.Select(
|
||||||
userLoginNamesUserIDCol.identifier(),
|
userLoginNamesUserIDCol.identifier(),
|
||||||
"ARRAY_AGG("+userLoginNamesCol.identifier()+") as login_names").
|
"ARRAY_AGG("+userLoginNamesNameCol.identifier()+") as "+userLoginNamesListCol.name).
|
||||||
From(userLoginNamesTable.identifier()).
|
From(userLoginNamesTable.identifier()).
|
||||||
GroupBy(userLoginNamesUserIDCol.identifier()).
|
GroupBy(userLoginNamesUserIDCol.identifier()).
|
||||||
ToSql()
|
ToSql()
|
||||||
@ -780,7 +785,7 @@ func prepareUsersQuery() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) {
|
|||||||
UserStateCol.identifier(),
|
UserStateCol.identifier(),
|
||||||
UserTypeCol.identifier(),
|
UserTypeCol.identifier(),
|
||||||
UserUsernameCol.identifier(),
|
UserUsernameCol.identifier(),
|
||||||
"login_names.login_names",
|
userLoginNamesListCol.identifier(),
|
||||||
userPreferredLoginNameCol.identifier(),
|
userPreferredLoginNameCol.identifier(),
|
||||||
HumanUserIDCol.identifier(),
|
HumanUserIDCol.identifier(),
|
||||||
HumanFirstNameCol.identifier(),
|
HumanFirstNameCol.identifier(),
|
||||||
@ -801,8 +806,8 @@ func prepareUsersQuery() (sq.SelectBuilder, func(*sql.Rows) (*Users, error)) {
|
|||||||
From(userTable.identifier()).
|
From(userTable.identifier()).
|
||||||
LeftJoin(join(HumanUserIDCol, UserIDCol)).
|
LeftJoin(join(HumanUserIDCol, UserIDCol)).
|
||||||
LeftJoin(join(MachineUserIDCol, UserIDCol)).
|
LeftJoin(join(MachineUserIDCol, UserIDCol)).
|
||||||
LeftJoin("("+loginNamesQuery+") as login_names on "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()).
|
LeftJoin("("+loginNamesQuery+") as "+userLoginNamesTable.alias+" on "+userLoginNamesUserIDCol.identifier()+" = "+UserIDCol.identifier()).
|
||||||
LeftJoin("("+preferredLoginNameQuery+") as preferred_login_name on "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...).
|
LeftJoin("("+preferredLoginNameQuery+") as "+userPreferredLoginNameTable.alias+" on "+userPreferredLoginNameUserIDCol.identifier()+" = "+UserIDCol.identifier(), preferredLoginNameArgs...).
|
||||||
PlaceholderFormat(sq.Dollar),
|
PlaceholderFormat(sq.Dollar),
|
||||||
func(rows *sql.Rows) (*Users, error) {
|
func(rows *sql.Rows) (*Users, error) {
|
||||||
users := make([]*User, 0)
|
users := make([]*User, 0)
|
||||||
|
@ -24,7 +24,7 @@ var (
|
|||||||
` zitadel.projections.users.state,` +
|
` zitadel.projections.users.state,` +
|
||||||
` zitadel.projections.users.type,` +
|
` zitadel.projections.users.type,` +
|
||||||
` zitadel.projections.users.username,` +
|
` zitadel.projections.users.username,` +
|
||||||
` login_names.login_names,` +
|
` login_names.loginnames,` +
|
||||||
` preferred_login_name.login_name,` +
|
` preferred_login_name.login_name,` +
|
||||||
` zitadel.projections.users_humans.user_id,` +
|
` zitadel.projections.users_humans.user_id,` +
|
||||||
` zitadel.projections.users_humans.first_name,` +
|
` zitadel.projections.users_humans.first_name,` +
|
||||||
@ -45,7 +45,7 @@ var (
|
|||||||
` LEFT JOIN zitadel.projections.users_humans ON zitadel.projections.users.id = zitadel.projections.users_humans.user_id` +
|
` LEFT JOIN zitadel.projections.users_humans ON zitadel.projections.users.id = zitadel.projections.users_humans.user_id` +
|
||||||
` LEFT JOIN zitadel.projections.users_machines ON zitadel.projections.users.id = zitadel.projections.users_machines.user_id` +
|
` LEFT JOIN zitadel.projections.users_machines ON zitadel.projections.users.id = zitadel.projections.users_machines.user_id` +
|
||||||
` LEFT JOIN` +
|
` LEFT JOIN` +
|
||||||
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) as login_names` +
|
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) as loginnames` +
|
||||||
` FROM zitadel.projections.login_names as login_names` +
|
` FROM zitadel.projections.login_names as login_names` +
|
||||||
` GROUP BY login_names.user_id) as login_names` +
|
` GROUP BY login_names.user_id) as login_names` +
|
||||||
` on login_names.user_id = zitadel.projections.users.id` +
|
` on login_names.user_id = zitadel.projections.users.id` +
|
||||||
@ -61,7 +61,7 @@ var (
|
|||||||
"state",
|
"state",
|
||||||
"type",
|
"type",
|
||||||
"username",
|
"username",
|
||||||
"login_names",
|
"loginnames",
|
||||||
"login_name",
|
"login_name",
|
||||||
//human
|
//human
|
||||||
"user_id",
|
"user_id",
|
||||||
@ -195,7 +195,7 @@ var (
|
|||||||
` zitadel.projections.users.state,` +
|
` zitadel.projections.users.state,` +
|
||||||
` zitadel.projections.users.type,` +
|
` zitadel.projections.users.type,` +
|
||||||
` zitadel.projections.users.username,` +
|
` zitadel.projections.users.username,` +
|
||||||
` login_names.login_names,` +
|
` login_names.loginnames,` +
|
||||||
` preferred_login_name.login_name,` +
|
` preferred_login_name.login_name,` +
|
||||||
` zitadel.projections.users_humans.user_id,` +
|
` zitadel.projections.users_humans.user_id,` +
|
||||||
` zitadel.projections.users_humans.first_name,` +
|
` zitadel.projections.users_humans.first_name,` +
|
||||||
@ -217,7 +217,7 @@ var (
|
|||||||
` LEFT JOIN zitadel.projections.users_humans ON zitadel.projections.users.id = zitadel.projections.users_humans.user_id` +
|
` LEFT JOIN zitadel.projections.users_humans ON zitadel.projections.users.id = zitadel.projections.users_humans.user_id` +
|
||||||
` LEFT JOIN zitadel.projections.users_machines ON zitadel.projections.users.id = zitadel.projections.users_machines.user_id` +
|
` LEFT JOIN zitadel.projections.users_machines ON zitadel.projections.users.id = zitadel.projections.users_machines.user_id` +
|
||||||
` LEFT JOIN` +
|
` LEFT JOIN` +
|
||||||
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) as login_names` +
|
` (SELECT login_names.user_id, ARRAY_AGG(login_names.login_name) as loginnames` +
|
||||||
` FROM zitadel.projections.login_names as login_names` +
|
` FROM zitadel.projections.login_names as login_names` +
|
||||||
` GROUP BY login_names.user_id) as login_names` +
|
` GROUP BY login_names.user_id) as login_names` +
|
||||||
` on login_names.user_id = zitadel.projections.users.id` +
|
` on login_names.user_id = zitadel.projections.users.id` +
|
||||||
@ -233,7 +233,7 @@ var (
|
|||||||
"state",
|
"state",
|
||||||
"type",
|
"type",
|
||||||
"username",
|
"username",
|
||||||
"login_names",
|
"loginnames",
|
||||||
"login_name",
|
"login_name",
|
||||||
//human
|
//human
|
||||||
"user_id",
|
"user_id",
|
||||||
|
Loading…
Reference in New Issue
Block a user