fix: update external username on idp if auto update is enabled (#7048)

* fix: update external username on idp if auto update is enabled

* update errors package
This commit is contained in:
Livio Spring
2023-12-08 19:22:07 +02:00
committed by GitHub
parent f680dd934d
commit aa3c352ae7
7 changed files with 296 additions and 4 deletions

View File

@@ -160,6 +160,27 @@ func (c *Commands) MigrateUserIDP(ctx context.Context, userID, orgID, idpConfigI
return err
}
func (c *Commands) UpdateUserIDPLinkUsername(ctx context.Context, userID, orgID, idpConfigID, externalID, newUsername string) (err error) {
if userID == "" {
return zerrors.ThrowInvalidArgument(nil, "COMMAND-SFegz", "Errors.IDMissing")
}
writeModel, err := c.userIDPLinkWriteModelByID(ctx, userID, idpConfigID, externalID, orgID)
if err != nil {
return err
}
if writeModel.State != domain.UserIDPLinkStateActive {
return zerrors.ThrowPreconditionFailed(nil, "COMMAND-DGhre", "Errors.User.ExternalIDP.NotFound")
}
if writeModel.DisplayName == newUsername {
return nil
}
userAgg := UserAggregateFromWriteModel(&writeModel.WriteModel) //nolint:contextcheck
_, err = c.eventstore.Push(ctx, user.NewUserIDPExternalUsernameEvent(ctx, userAgg, idpConfigID, externalID, newUsername))
return err
}
func (c *Commands) userIDPLinkWriteModelByID(ctx context.Context, userID, idpConfigID, externalUserID, resourceOwner string) (writeModel *UserIDPLinkWriteModel, err error) {
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()