[MM-15802] Migrate "Session.UpdateDeviceId" to Sync by default (#11017)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
201fb5a717
Коммит
4cfe61393b
@@ -213,8 +213,9 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.AppError {
|
func (a *App) AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.AppError {
|
||||||
if result := <-a.Srv.Store.Session().UpdateDeviceId(sessionId, deviceId, expiresAt); result.Err != nil {
|
_, err := a.Srv.Store.Session().UpdateDeviceId(sessionId, deviceId, expiresAt)
|
||||||
return result.Err
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -196,14 +196,14 @@ func (me SqlSessionStore) UpdateRoles(userId, roles string) store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) store.StoreChannel {
|
func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query := "UPDATE Sessions SET DeviceId = :DeviceId, ExpiresAt = :ExpiresAt WHERE Id = :Id"
|
||||||
if _, err := me.GetMaster().Exec("UPDATE Sessions SET DeviceId = :DeviceId, ExpiresAt = :ExpiresAt WHERE Id = :Id", map[string]interface{}{"DeviceId": deviceId, "Id": id, "ExpiresAt": expiresAt}); err != nil {
|
|
||||||
result.Err = model.NewAppError("SqlSessionStore.UpdateDeviceId", "store.sql_session.update_device_id.app_error", nil, err.Error(), http.StatusInternalServerError)
|
_, err := me.GetMaster().Exec(query, map[string]interface{}{"DeviceId": deviceId, "Id": id, "ExpiresAt": expiresAt})
|
||||||
} else {
|
if err != nil {
|
||||||
result.Data = deviceId
|
return "", model.NewAppError("SqlSessionStore.UpdateDeviceId", "store.sql_session.update_device_id.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
})
|
return deviceId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) AnalyticsSessionCount() (int64, *model.AppError) {
|
func (me SqlSessionStore) AnalyticsSessionCount() (int64, *model.AppError) {
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ type SessionStore interface {
|
|||||||
PermanentDeleteSessionsByUser(teamId string) *model.AppError
|
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) (string, *model.AppError)
|
||||||
AnalyticsSessionCount() (int64, *model.AppError)
|
AnalyticsSessionCount() (int64, *model.AppError)
|
||||||
Cleanup(expiryTime int64, batchSize int64)
|
Cleanup(expiryTime int64, batchSize int64)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,19 +181,26 @@ func (_m *SessionStore) Save(session *model.Session) (*model.Session, *model.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateDeviceId provides a mock function with given fields: id, deviceId, expiresAt
|
// UpdateDeviceId provides a mock function with given fields: id, deviceId, expiresAt
|
||||||
func (_m *SessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) store.StoreChannel {
|
func (_m *SessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError) {
|
||||||
ret := _m.Called(id, deviceId, expiresAt)
|
ret := _m.Called(id, deviceId, expiresAt)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 string
|
||||||
if rf, ok := ret.Get(0).(func(string, string, int64) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, int64) string); ok {
|
||||||
r0 = rf(id, deviceId, expiresAt)
|
r0 = rf(id, deviceId, expiresAt)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(string)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, int64) *model.AppError); ok {
|
||||||
|
r1 = rf(id, deviceId, expiresAt)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLastActivityAt provides a mock function with given fields: sessionId, time
|
// UpdateLastActivityAt provides a mock function with given fields: sessionId, time
|
||||||
|
|||||||
@@ -213,8 +213,8 @@ func testSessionUpdateDeviceId(t *testing.T, ss store.Store) {
|
|||||||
s1, err := ss.Session().Save(s1)
|
s1, err := ss.Session().Save(s1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if rs1 := (<-ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt)); rs1.Err != nil {
|
if _, err = ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt); err != nil {
|
||||||
t.Fatal(rs1.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s2 := &model.Session{}
|
s2 := &model.Session{}
|
||||||
@@ -223,8 +223,8 @@ func testSessionUpdateDeviceId(t *testing.T, ss store.Store) {
|
|||||||
s2, err = ss.Session().Save(s2)
|
s2, err = ss.Session().Save(s2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if rs2 := (<-ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt)); rs2.Err != nil {
|
if _, err := ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt); err != nil {
|
||||||
t.Fatal(rs2.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,8 +235,8 @@ func testSessionUpdateDeviceId2(t *testing.T, ss store.Store) {
|
|||||||
s1, err := ss.Session().Save(s1)
|
s1, err := ss.Session().Save(s1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if rs1 := (<-ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs1.Err != nil {
|
if _, err = ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt); err != nil {
|
||||||
t.Fatal(rs1.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s2 := &model.Session{}
|
s2 := &model.Session{}
|
||||||
@@ -245,8 +245,8 @@ func testSessionUpdateDeviceId2(t *testing.T, ss store.Store) {
|
|||||||
s2, err = ss.Session().Save(s2)
|
s2, err = ss.Session().Save(s2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if rs2 := (<-ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs2.Err != nil {
|
if _, err := ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt); err != nil {
|
||||||
t.Fatal(rs2.Err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user