[MM-15799] Migrate "Session.PermanentDeleteSessionsByUser" to Sync by default (#11038)

Этот коммит содержится в:
Woolim Cho
2019-06-03 20:22:02 +09:00
коммит произвёл Hanzei
родитель d88de07b9d
Коммит d1f81842a5
5 изменённых файлов: 16 добавлений и 15 удалений

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

@@ -1415,8 +1415,8 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
return err return err
} }
if result := <-a.Srv.Store.Session().PermanentDeleteSessionsByUser(user.Id); result.Err != nil { if err := a.Srv.Store.Session().PermanentDeleteSessionsByUser(user.Id); err != nil {
return result.Err return err
} }
if result := <-a.Srv.Store.UserAccessToken().DeleteAllForUser(user.Id); result.Err != nil { if result := <-a.Srv.Store.UserAccessToken().DeleteAllForUser(user.Id); result.Err != nil {

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

@@ -167,13 +167,13 @@ func (me SqlSessionStore) RemoveAllSessions() store.StoreChannel {
}) })
} }
func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) store.StoreChannel { func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) *model.AppError {
return store.Do(func(result *store.StoreResult) {
_, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}) _, err := me.GetMaster().Exec("DELETE FROM Sessions WHERE UserId = :UserId", map[string]interface{}{"UserId": userId})
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlSessionStore.RemoveAllSessionsForUser", "store.sql_session.permanent_delete_sessions_by_user.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError) return model.NewAppError("SqlSessionStore.RemoveAllSessionsForUser", "store.sql_session.permanent_delete_sessions_by_user.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError)
} }
})
return nil
} }
func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) store.StoreChannel { func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) store.StoreChannel {

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

@@ -318,7 +318,7 @@ type SessionStore interface {
GetSessionsWithActiveDeviceIds(userId string) ([]*model.Session, *model.AppError) GetSessionsWithActiveDeviceIds(userId string) ([]*model.Session, *model.AppError)
Remove(sessionIdOrToken string) StoreChannel Remove(sessionIdOrToken string) StoreChannel
RemoveAllSessions() StoreChannel RemoveAllSessions() StoreChannel
PermanentDeleteSessionsByUser(teamId string) StoreChannel PermanentDeleteSessionsByUser(teamId string) *model.AppError
UpdateLastActivityAt(sessionId string, time int64) StoreChannel UpdateLastActivityAt(sessionId string, time int64) StoreChannel
UpdateRoles(userId string, roles string) StoreChannel UpdateRoles(userId string, roles string) StoreChannel
UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel UpdateDeviceId(id string, deviceId string, expiresAt int64) StoreChannel

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

@@ -108,15 +108,15 @@ func (_m *SessionStore) GetSessionsWithActiveDeviceIds(userId string) ([]*model.
} }
// PermanentDeleteSessionsByUser provides a mock function with given fields: teamId // PermanentDeleteSessionsByUser provides a mock function with given fields: teamId
func (_m *SessionStore) PermanentDeleteSessionsByUser(teamId string) store.StoreChannel { func (_m *SessionStore) PermanentDeleteSessionsByUser(teamId string) *model.AppError {
ret := _m.Called(teamId) ret := _m.Called(teamId)
var r0 store.StoreChannel var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(teamId) r0 = rf(teamId)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.AppError)
} }
} }

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

@@ -168,7 +168,8 @@ func testSessionRemoveByUser(t *testing.T, ss store.Store) {
} }
} }
store.Must(ss.Session().PermanentDeleteSessionsByUser(s1.UserId)) deleteErr := ss.Session().PermanentDeleteSessionsByUser(s1.UserId)
require.Nil(t, deleteErr)
if _, err := ss.Session().Get(s1.Id); err == nil { if _, err := ss.Session().Get(s1.Id); err == nil {
t.Fatal("should have been removed") t.Fatal("should have been removed")