mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-07 22:17:42 +00:00
fix: login names (and query) (#253)
This commit is contained in:
parent
d89087cbe0
commit
66cca48b62
@ -102,7 +102,7 @@ func (u *User) fillLoginNames(user *view_model.UserView) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user.SetLoginNames(policy, org.Domains)
|
user.SetLoginNames(policy, org.Domains)
|
||||||
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain)
|
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain, policy.UserLoginMustBeDomain)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ func (u *User) fillPreferredLoginNamesOnOrgUsers(event *models.Event) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain)
|
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain, policy.UserLoginMustBeDomain)
|
||||||
err := u.view.PutUser(user, 0)
|
err := u.view.PutUser(user, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -149,7 +149,7 @@ func (u *User) fillPreferredLoginNamesOnOrgUsers(event *models.Event) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain)
|
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain, policy.UserLoginMustBeDomain)
|
||||||
err := u.view.PutUser(user, 0)
|
err := u.view.PutUser(user, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -168,7 +168,7 @@ func (u *User) fillLoginNames(user *view_model.UserView) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user.SetLoginNames(policy, org.Domains)
|
user.SetLoginNames(policy, org.Domains)
|
||||||
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain)
|
user.PreferredLoginName = user.GenerateLoginName(org.GetPrimaryDomain().Domain, policy.UserLoginMustBeDomain)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,21 +145,23 @@ func UsersToModel(users []*UserView) []*model.UserView {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserView) GenerateLoginName(domain string) string {
|
func (u *UserView) GenerateLoginName(domain string, appendDomain bool) string {
|
||||||
|
if !appendDomain {
|
||||||
|
return u.UserName
|
||||||
|
}
|
||||||
return u.UserName + "@" + domain
|
return u.UserName + "@" + domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserView) SetLoginNames(policy *org_model.OrgIamPolicy, domains []*org_model.OrgDomain) {
|
func (u *UserView) SetLoginNames(policy *org_model.OrgIamPolicy, domains []*org_model.OrgDomain) {
|
||||||
loginNames := make([]string, 0)
|
loginNames := make([]string, 0)
|
||||||
if !policy.UserLoginMustBeDomain {
|
|
||||||
u.LoginNames = []string{u.UserName}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, d := range domains {
|
for _, d := range domains {
|
||||||
if d.Verified {
|
if d.Verified {
|
||||||
loginNames = append(loginNames, u.GenerateLoginName(d.Domain))
|
loginNames = append(loginNames, u.GenerateLoginName(d.Domain, true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !policy.UserLoginMustBeDomain {
|
||||||
|
loginNames = append(loginNames, u.UserName)
|
||||||
|
}
|
||||||
u.LoginNames = loginNames
|
u.LoginNames = loginNames
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package view
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
|
||||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||||
global_model "github.com/caos/zitadel/internal/model"
|
global_model "github.com/caos/zitadel/internal/model"
|
||||||
usr_model "github.com/caos/zitadel/internal/user/model"
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
||||||
"github.com/caos/zitadel/internal/user/repository/view/model"
|
"github.com/caos/zitadel/internal/user/repository/view/model"
|
||||||
"github.com/caos/zitadel/internal/view"
|
"github.com/caos/zitadel/internal/view"
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
"github.com/lib/pq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserByID(db *gorm.DB, table, userID string) (*model.UserView, error) {
|
func UserByID(db *gorm.DB, table, userID string) (*model.UserView, error) {
|
||||||
@ -35,7 +35,7 @@ func UserByLoginName(db *gorm.DB, table, loginName string) (*model.UserView, err
|
|||||||
loginNameQuery := &model.UserSearchQuery{
|
loginNameQuery := &model.UserSearchQuery{
|
||||||
Key: usr_model.USERSEARCHKEY_LOGIN_NAMES,
|
Key: usr_model.USERSEARCHKEY_LOGIN_NAMES,
|
||||||
Method: global_model.SEARCHMETHOD_LIST_CONTAINS,
|
Method: global_model.SEARCHMETHOD_LIST_CONTAINS,
|
||||||
Value: pq.Array([]string{loginName}),
|
Value: loginName,
|
||||||
}
|
}
|
||||||
query := view.PrepareGetByQuery(table, loginNameQuery)
|
query := view.PrepareGetByQuery(table, loginNameQuery)
|
||||||
err := query(db, user)
|
err := query(db, user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user