fix(command): allow email as username (#6565)

Fixes #6460

Made the username checks consistent with create human user.
This commit is contained in:
Tim Möhlmann
2023-09-15 18:29:29 +03:00
committed by GitHub
parent 1a49b7d298
commit 9266f8f00b
3 changed files with 160 additions and 46 deletions

View File

@@ -42,9 +42,17 @@ func (c *Commands) ChangeUsername(ctx context.Context, orgID, userID, userName s
if err != nil {
return nil, errors.ThrowPreconditionFailed(err, "COMMAND-38fnu", "Errors.Org.DomainPolicy.NotExisting")
}
if err := CheckDomainPolicyForUserName(userName, domainPolicy); err != nil {
return nil, err
if !domainPolicy.UserLoginMustBeDomain {
index := strings.LastIndex(userName, "@")
if index > 1 {
domainCheck := NewOrgDomainVerifiedWriteModel(userName[index+1:])
if err := c.eventstore.FilterToQueryReducer(ctx, domainCheck); err != nil {
return nil, err
}
if domainCheck.Verified && domainCheck.ResourceOwner != orgID {
return nil, errors.ThrowInvalidArgument(nil, "COMMAND-Di2ei", "Errors.User.DomainNotAllowedAsUsername")
}
}
}
userAgg := UserAggregateFromWriteModel(&existingUser.WriteModel)