Migrate User.UpdateFailedPasswordAttempts to sync by default (#11507)

* Migrate User.UpdateFailedPasswordAttempts to sync by default

* Removed unused return value
This commit is contained in:
Rodrigo Villablanca Vásquez
2019-07-06 03:05:44 -04:00
committed by Jesús Espino
parent 2ecca12bed
commit 7da08e7a0f
5 changed files with 22 additions and 24 deletions

View File

@@ -255,14 +255,12 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) store.Store
})
}
func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if _, err := us.GetMaster().Exec("UPDATE Users SET FailedAttempts = :FailedAttempts WHERE Id = :UserId", map[string]interface{}{"FailedAttempts": attempts, "UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlUserStore.UpdateFailedPasswordAttempts", "store.sql_user.update_failed_pwd_attempts.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
} else {
result.Data = userId
}
})
func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError {
if _, err := us.GetMaster().Exec("UPDATE Users SET FailedAttempts = :FailedAttempts WHERE Id = :UserId", map[string]interface{}{"FailedAttempts": attempts, "UserId": userId}); err != nil {
return model.NewAppError("SqlUserStore.UpdateFailedPasswordAttempts", "store.sql_user.update_failed_pwd_attempts.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
}
return nil
}
func (us SqlUserStore) UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) {

View File

@@ -282,7 +282,7 @@ type UserStore interface {
VerifyEmail(userId, email string) (string, *model.AppError)
GetEtagForAllProfiles() string
GetEtagForProfiles(teamId string) string
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError
GetSystemAdminProfiles() (map[string]*model.User, *model.AppError)
PermanentDelete(userId string) *model.AppError
AnalyticsActiveCount(time int64) (int64, *model.AppError)

View File

@@ -1072,15 +1072,15 @@ func (_m *UserStore) UpdateAuthData(userId string, service string, authData *str
}
// UpdateFailedPasswordAttempts provides a mock function with given fields: userId, attempts
func (_m *UserStore) UpdateFailedPasswordAttempts(userId string, attempts int) store.StoreChannel {
func (_m *UserStore) UpdateFailedPasswordAttempts(userId string, attempts int) *model.AppError {
ret := _m.Called(userId, attempts)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string, int) store.StoreChannel); ok {
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, int) *model.AppError); ok {
r0 = rf(userId, attempts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.AppError)
}
}

View File

@@ -235,7 +235,7 @@ func testUserStoreUpdateFailedPasswordAttempts(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.User().PermanentDelete(u1.Id)) }()
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id}, -1))
if err := (<-ss.User().UpdateFailedPasswordAttempts(u1.Id, 3)).Err; err != nil {
if err := ss.User().UpdateFailedPasswordAttempts(u1.Id, 3); err != nil {
t.Fatal(err)
}