Migrate "User.UpdateMfaActive" to Sync by default (#11566)

This commit is contained in:
Micah Thompson
2019-07-10 14:55:17 -04:00
committed by Joram Wilander
parent e9b82bc1ce
commit 903085feb8
6 changed files with 27 additions and 30 deletions

View File

@@ -303,16 +303,14 @@ func (us SqlUserStore) UpdateMfaSecret(userId, secret string) *model.AppError {
return nil
}
func (us SqlUserStore) UpdateMfaActive(userId string, active bool) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
updateAt := model.GetMillis()
func (us SqlUserStore) UpdateMfaActive(userId string, active bool) *model.AppError {
updateAt := model.GetMillis()
if _, err := us.GetMaster().Exec("UPDATE Users SET MfaActive = :Active, UpdateAt = :UpdateAt WHERE Id = :UserId", map[string]interface{}{"Active": active, "UpdateAt": updateAt, "UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlUserStore.UpdateMfaActive", "store.sql_user.update_mfa_active.app_error", nil, "id="+userId+", "+err.Error(), http.StatusInternalServerError)
} else {
result.Data = userId
}
})
if _, err := us.GetMaster().Exec("UPDATE Users SET MfaActive = :Active, UpdateAt = :UpdateAt WHERE Id = :UserId", map[string]interface{}{"Active": active, "UpdateAt": updateAt, "UserId": userId}); err != nil {
return model.NewAppError("SqlUserStore.UpdateMfaActive", "store.sql_user.update_mfa_active.app_error", nil, "id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
return nil
}
func (us SqlUserStore) Get(id string) (*model.User, *model.AppError) {

View File

@@ -257,7 +257,7 @@ type UserStore interface {
UpdateUpdateAt(userId string) (int64, *model.AppError)
UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError)
UpdateMfaSecret(userId, secret string) *model.AppError
UpdateMfaActive(userId string, active bool) StoreChannel
UpdateMfaActive(userId string, active bool) *model.AppError
Get(id string) (*model.User, *model.AppError)
GetAll() ([]*model.User, *model.AppError)
ClearCaches()

View File

@@ -1127,15 +1127,15 @@ func (_m *UserStore) UpdateLastPictureUpdate(userId string) *model.AppError {
}
// UpdateMfaActive provides a mock function with given fields: userId, active
func (_m *UserStore) UpdateMfaActive(userId string, active bool) store.StoreChannel {
func (_m *UserStore) UpdateMfaActive(userId string, active bool) *model.AppError {
ret := _m.Called(userId, active)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok {
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, bool) *model.AppError); ok {
r0 = rf(userId, active)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.AppError)
}
}

View File

@@ -1987,16 +1987,16 @@ func testUserStoreUpdateMfaActive(t *testing.T, ss store.Store) {
time.Sleep(100 * time.Millisecond)
if err = (<-ss.User().UpdateMfaActive(u1.Id, true)).Err; err != nil {
if err = ss.User().UpdateMfaActive(u1.Id, true); err != nil {
t.Fatal(err)
}
if err = (<-ss.User().UpdateMfaActive(u1.Id, false)).Err; err != nil {
if err = ss.User().UpdateMfaActive(u1.Id, false); err != nil {
t.Fatal(err)
}
// should pass, no update will occur though
if err = (<-ss.User().UpdateMfaActive("junk", true)).Err; err != nil {
if err = ss.User().UpdateMfaActive("junk", true); err != nil {
t.Fatal(err)
}
}