[MM-34725] app/user: check if username or email is in use before patching a user (#17392)

* app/user: check if username or email is in use before patching a user

* reflect review comments

* fix tests
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2021-04-16 18:41:32 +03:00
коммит произвёл GitHub
родитель 3ea75332e7
Коммит 3a13987ee1
23 изменённых файлов: 57 добавлений и 85 удалений

Просмотреть файл

@@ -210,10 +210,10 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) (*model.
count, err := us.GetMaster().Update(user)
if err != nil {
if IsUniqueConstraintError(err, []string{"Email", "users_email_key", "idx_users_email_unique"}) {
return nil, store.NewErrInvalidInput("User", "id", user.Id)
return nil, store.NewErrConflict("Email", err, user.Email)
}
if IsUniqueConstraintError(err, []string{"Username", "users_username_key", "idx_users_username_unique"}) {
return nil, store.NewErrInvalidInput("User", "id", user.Id)
return nil, store.NewErrConflict("Username", err, user.Username)
}
return nil, errors.Wrapf(err, "failed to update User with userId=%s", user.Id)
}