Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: explicity set updated_at field when updating identity #4131

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions identity/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,22 @@ func TestManager(t *testing.T) {
// That is why we only check the identity in the store.
checkExtensionFields(fromStore, "[email protected]")(t)
})

t.Run("case=should always update updated_at field", func(t *testing.T) {
original := identity.NewIdentity(config.DefaultIdentityTraitsSchemaID)
original.Traits = newTraits("[email protected]", "")
require.NoError(t, reg.IdentityManager().Create(ctx, original))

time.Sleep(time.Millisecond)

require.NoError(t, reg.IdentityManager().UpdateTraits(
ctx, original.ID, newTraits("[email protected]", ""),
identity.ManagerAllowWriteProtectedTraits))

updated, err := reg.IdentityPool().GetIdentity(ctx, original.ID, identity.ExpandNothing)
require.NoError(t, err)
assert.NotEqual(t, original.UpdatedAt, updated.UpdatedAt, "UpdatedAt field should be updated")
})
})

t.Run("method=RefreshAvailableAAL", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions persistence/sql/identity/persister_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ func (p *IdentityPersister) UpdateIdentity(ctx context.Context, i *identity.Iden
}

i.NID = p.NetworkID(ctx)
i.UpdatedAt = time.Now().UTC()
if err := sqlcon.HandleError(p.Transaction(ctx, func(ctx context.Context, tx *pop.Connection) error {
// This returns "ErrNoRows" if the identity does not exist
if err := update.Generic(WithTransaction(ctx, tx), tx, p.r.Tracer(ctx).Tracer(), i); err != nil {
Expand Down
Loading