Skip to content

Commit

Permalink
chore: rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Mar 1, 2024
1 parent 0ce369e commit 0963e41
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/api/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (a *API) DeleteIdentity(w http.ResponseWriter, r *http.Request) error {
if terr := tx.Destroy(identityToBeDeleted); terr != nil {
return internalServerError("Database error deleting identity").WithInternalError(terr)
}
if terr := user.UpdateUserEmail(tx); terr != nil {
if terr := user.UpdateUserEmailFromIdentities(tx); terr != nil {
if models.IsUniqueConstraintViolatedError(terr) {
return forbiddenError("Unable to unlink identity due to email conflict").WithInternalError(terr)
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (a *API) linkIdentityToUser(r *http.Request, ctx context.Context, tx *stora
}

if targetUser.GetEmail() == "" {
if terr := targetUser.UpdateUserEmail(tx); terr != nil {
if terr := targetUser.UpdateUserEmailFromIdentities(tx); terr != nil {
if models.IsUniqueConstraintViolatedError(terr) {
return nil, badRequestError(DuplicateEmailMsg)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (u *User) UpdateAppMetaDataProviders(tx *storage.Connection) error {

// UpdateUserEmail updates the user's email to one of the identity's email
// if the current email used doesn't match any of the identities email
func (u *User) UpdateUserEmail(tx *storage.Connection) error {
func (u *User) UpdateUserEmailFromIdentities(tx *storage.Connection) error {
identities, terr := FindIdentitiesByUserID(tx, u.ID)
if terr != nil {
return terr
Expand Down
6 changes: 3 additions & 3 deletions internal/models/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ func (ts *UserTestSuite) TestUpdateUserEmailSuccess() {
require.NoError(ts.T(), ts.db.Create(secondaryIdentity))

// UpdateUserEmail should not do anything and the user's email should still use the primaryIdentity
require.NoError(ts.T(), userA.UpdateUserEmail(ts.db))
require.NoError(ts.T(), userA.UpdateUserEmailFromIdentities(ts.db))
require.Equal(ts.T(), primaryIdentity.GetEmail(), userA.GetEmail())

// remove primary identity
require.NoError(ts.T(), ts.db.Destroy(primaryIdentity))

// UpdateUserEmail should update the user to use the secondary identity's email
require.NoError(ts.T(), userA.UpdateUserEmail(ts.db))
require.NoError(ts.T(), userA.UpdateUserEmailFromIdentities(ts.db))
require.Equal(ts.T(), secondaryIdentity.GetEmail(), userA.GetEmail())
}

Expand Down Expand Up @@ -364,7 +364,7 @@ func (ts *UserTestSuite) TestUpdateUserEmailFailure() {

// UpdateUserEmail should fail with the email unique constraint violation error
// since userB is using the secondary identity's email
require.ErrorIs(ts.T(), userA.UpdateUserEmail(ts.db), UserEmailUniqueConflictError{})
require.ErrorIs(ts.T(), userA.UpdateUserEmailFromIdentities(ts.db), UserEmailUniqueConflictError{})
require.Equal(ts.T(), primaryIdentity.GetEmail(), userA.GetEmail())
}

Expand Down

0 comments on commit 0963e41

Please sign in to comment.