mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-15802] Migrate "Session.UpdateDeviceId" to Sync by default (#11017)
This commit is contained in:
committed by
Hanzei
parent
201fb5a717
commit
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 {
|
||||
if result := <-a.Srv.Store.Session().UpdateDeviceId(sessionId, deviceId, expiresAt); result.Err != nil {
|
||||
return result.Err
|
||||
_, err := a.Srv.Store.Session().UpdateDeviceId(sessionId, deviceId, expiresAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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 {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
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)
|
||||
} else {
|
||||
result.Data = deviceId
|
||||
}
|
||||
})
|
||||
func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError) {
|
||||
query := "UPDATE Sessions SET DeviceId = :DeviceId, ExpiresAt = :ExpiresAt WHERE Id = :Id"
|
||||
|
||||
_, err := me.GetMaster().Exec(query, map[string]interface{}{"DeviceId": deviceId, "Id": id, "ExpiresAt": expiresAt})
|
||||
if err != nil {
|
||||
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) {
|
||||
|
||||
@@ -321,7 +321,7 @@ type SessionStore interface {
|
||||
PermanentDeleteSessionsByUser(teamId string) *model.AppError
|
||||
UpdateLastActivityAt(sessionId string, time int64) 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)
|
||||
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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64) store.StoreChannel); ok {
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func(string, string, int64) string); ok {
|
||||
r0 = rf(id, deviceId, expiresAt)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -213,8 +213,8 @@ func testSessionUpdateDeviceId(t *testing.T, ss store.Store) {
|
||||
s1, err := ss.Session().Save(s1)
|
||||
require.Nil(t, err)
|
||||
|
||||
if rs1 := (<-ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt)); rs1.Err != nil {
|
||||
t.Fatal(rs1.Err)
|
||||
if _, err = ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s2 := &model.Session{}
|
||||
@@ -223,8 +223,8 @@ func testSessionUpdateDeviceId(t *testing.T, ss store.Store) {
|
||||
s2, err = ss.Session().Save(s2)
|
||||
require.Nil(t, err)
|
||||
|
||||
if rs2 := (<-ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt)); rs2.Err != nil {
|
||||
t.Fatal(rs2.Err)
|
||||
if _, err := ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,8 +235,8 @@ func testSessionUpdateDeviceId2(t *testing.T, ss store.Store) {
|
||||
s1, err := ss.Session().Save(s1)
|
||||
require.Nil(t, err)
|
||||
|
||||
if rs1 := (<-ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs1.Err != nil {
|
||||
t.Fatal(rs1.Err)
|
||||
if _, err = ss.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s2 := &model.Session{}
|
||||
@@ -245,8 +245,8 @@ func testSessionUpdateDeviceId2(t *testing.T, ss store.Store) {
|
||||
s2, err = ss.Session().Save(s2)
|
||||
require.Nil(t, err)
|
||||
|
||||
if rs2 := (<-ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs2.Err != nil {
|
||||
t.Fatal(rs2.Err)
|
||||
if _, err := ss.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user