[MM-16653] Migrate "User.UpdateUpdateAt" to Sync by default (#11517)
* Migrate "User.UpdateUpdateAt" to Sync by default * Fixed errors in app/team.go that prevented successful build * Reverted some changes in user_store test that caused errors in pipeline * return of UpdateUpdateAt changed to model.AppError * Ensured that UpdateUpdateAt in sqlstore/user_store.go returns int64 and *model.AppError, adjusted tests accordingly * Generated mocks and ensured storetest/user_store.go had no errors * Added require.Nil(t, err) to proper places in tests * Added 'err' for second return value as opposed to _ in 4 UpdateUpdateAt() occurrences in storetest/user_store.go
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
797d1dc40f
Коммит
2e48b6ef3f
@@ -565,8 +565,8 @@ func (a *App) JoinUserToTeam(team *model.Team, user *model.User, userRequestorId
|
||||
})
|
||||
}
|
||||
|
||||
if uua := <-a.Srv.Store.User().UpdateUpdateAt(user.Id); uua.Err != nil {
|
||||
return uua.Err
|
||||
if _, err := a.Srv.Store.User().UpdateUpdateAt(user.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
shouldBeAdmin := team.Email == user.Email
|
||||
@@ -897,8 +897,8 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string)
|
||||
})
|
||||
}
|
||||
|
||||
if uua := <-a.Srv.Store.User().UpdateUpdateAt(user.Id); uua.Err != nil {
|
||||
return uua.Err
|
||||
if _, err := a.Srv.Store.User().UpdateUpdateAt(user.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// delete the preferences that set the last channel used in the team and other team specific preferences
|
||||
|
||||
@@ -232,17 +232,14 @@ func (us SqlUserStore) ResetLastPictureUpdate(userId string) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) UpdateUpdateAt(userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
curTime := model.GetMillis()
|
||||
func (us SqlUserStore) UpdateUpdateAt(userId string) (int64, *model.AppError) {
|
||||
curTime := model.GetMillis()
|
||||
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"Time": curTime, "UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.UpdateUpdateAt", "store.sql_user.update_update.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if _, err := us.GetMaster().Exec("UPDATE Users SET UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"Time": curTime, "UserId": userId}); err != nil {
|
||||
return curTime, model.NewAppError("SqlUserStore.UpdateUpdateAt", "store.sql_user.update_update.app_error", nil, "user_id="+userId, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = curTime
|
||||
})
|
||||
return curTime, nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) store.StoreChannel {
|
||||
|
||||
@@ -253,7 +253,7 @@ type UserStore interface {
|
||||
Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, *model.AppError)
|
||||
UpdateLastPictureUpdate(userId string) *model.AppError
|
||||
ResetLastPictureUpdate(userId string) *model.AppError
|
||||
UpdateUpdateAt(userId string) StoreChannel
|
||||
UpdateUpdateAt(userId string) (int64, *model.AppError)
|
||||
UpdatePassword(userId, newPassword string) StoreChannel
|
||||
UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError)
|
||||
UpdateMfaSecret(userId, secret string) *model.AppError
|
||||
|
||||
@@ -1159,19 +1159,26 @@ func (_m *UserStore) UpdatePassword(userId string, newPassword string) store.Sto
|
||||
}
|
||||
|
||||
// UpdateUpdateAt provides a mock function with given fields: userId
|
||||
func (_m *UserStore) UpdateUpdateAt(userId string) store.StoreChannel {
|
||||
func (_m *UserStore) UpdateUpdateAt(userId string) (int64, *model.AppError) {
|
||||
ret := _m.Called(userId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||
r0 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(userId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// VerifyEmail provides a mock function with given fields: userId, email
|
||||
|
||||
@@ -217,7 +217,7 @@ func testUserStoreUpdateUpdateAt(t *testing.T, ss store.Store) {
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
if err := (<-ss.User().UpdateUpdateAt(u1.Id)).Err; err != nil {
|
||||
if _, err := ss.User().UpdateUpdateAt(u1.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3360,7 +3360,8 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
// Add u2 to team 1
|
||||
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u2.Id}, -1))
|
||||
u2.UpdateAt = store.Must(ss.User().UpdateUpdateAt(u2.Id)).(int64)
|
||||
u2.UpdateAt, err = ss.User().UpdateUpdateAt(u2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("etag for profiles not in team 1 after update", func(t *testing.T) {
|
||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||
@@ -3382,8 +3383,10 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
store.Must(ss.Team().RemoveMember(teamId, u1.Id))
|
||||
store.Must(ss.Team().RemoveMember(teamId, u2.Id))
|
||||
u1.UpdateAt = store.Must(ss.User().UpdateUpdateAt(u1.Id)).(int64)
|
||||
u2.UpdateAt = store.Must(ss.User().UpdateUpdateAt(u2.Id)).(int64)
|
||||
u1.UpdateAt, err = ss.User().UpdateUpdateAt(u1.Id)
|
||||
require.Nil(t, err)
|
||||
u2.UpdateAt, err = ss.User().UpdateUpdateAt(u2.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
t.Run("etag for profiles not in team 1 after second update", func(t *testing.T) {
|
||||
result := <-ss.User().GetEtagForProfilesNotInTeam(teamId)
|
||||
@@ -3422,7 +3425,8 @@ func testUserStoreGetProfilesNotInTeam(t *testing.T, ss store.Store) {
|
||||
|
||||
// Add u3 to team 2
|
||||
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: u3.Id}, -1))
|
||||
u3.UpdateAt = store.Must(ss.User().UpdateUpdateAt(u3.Id)).(int64)
|
||||
u3.UpdateAt, err = ss.User().UpdateUpdateAt(u3.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// GetEtagForProfilesNotInTeam produces a new etag every time a member, not
|
||||
// in the team, gets a new UpdateAt value. In the case that an older member
|
||||
|
||||
Ссылка в новой задаче
Block a user