MM - 15795 Migrate "Session.GetSessions" to Sync by default (#11000)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
9c9d510a73
Коммит
367ffbfb42
@@ -89,21 +89,15 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetSessions(userId string) ([]*model.Session, *model.AppError) {
|
func (a *App) GetSessions(userId string) ([]*model.Session, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Session().GetSessions(userId)
|
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.([]*model.Session), nil
|
|
||||||
|
|
||||||
|
return a.Srv.Store.Session().GetSessions(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) RevokeAllSessions(userId string) *model.AppError {
|
func (a *App) RevokeAllSessions(userId string) *model.AppError {
|
||||||
result := <-a.Srv.Store.Session().GetSessions(userId)
|
sessions, err := a.Srv.Store.Session().GetSessions(userId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return result.Err
|
return err
|
||||||
}
|
}
|
||||||
sessions := result.Data.([]*model.Session)
|
|
||||||
|
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
if session.IsOAuth {
|
if session.IsOAuth {
|
||||||
a.RevokeAccessToken(session.Token)
|
a.RevokeAccessToken(session.Token)
|
||||||
@@ -159,11 +153,10 @@ func (a *App) SessionCacheLength() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) RevokeSessionsForDeviceId(userId string, deviceId string, currentSessionId string) *model.AppError {
|
func (a *App) RevokeSessionsForDeviceId(userId string, deviceId string, currentSessionId string) *model.AppError {
|
||||||
result := <-a.Srv.Store.Session().GetSessions(userId)
|
sessions, err := a.Srv.Store.Session().GetSessions(userId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return result.Err
|
return err
|
||||||
}
|
}
|
||||||
sessions := result.Data.([]*model.Session)
|
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
if session.DeviceId == deviceId && session.Id != currentSessionId {
|
if session.DeviceId == deviceId && session.Id != currentSessionId {
|
||||||
mlog.Debug(fmt.Sprintf("Revoking sessionId=%v for userId=%v re-login with same device Id", session.Id, userId), mlog.String("user_id", userId))
|
mlog.Debug(fmt.Sprintf("Revoking sessionId=%v for userId=%v re-login with same device Id", session.Id, userId), mlog.String("user_id", userId))
|
||||||
|
|||||||
@@ -99,34 +99,29 @@ func (me SqlSessionStore) Get(sessionIdOrToken string) (*model.Session, *model.A
|
|||||||
return session, nil
|
return session, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) GetSessions(userId string) store.StoreChannel {
|
func (me SqlSessionStore) GetSessions(userId string) ([]*model.Session, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var sessions []*model.Session
|
||||||
var sessions []*model.Session
|
|
||||||
|
|
||||||
tcs := me.Team().GetTeamsForUser(userId)
|
tcs := me.Team().GetTeamsForUser(userId)
|
||||||
|
if _, err := me.GetReplica().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = :UserId ORDER BY LastActivityAt DESC", map[string]interface{}{"UserId": userId}); err != nil {
|
||||||
|
return nil, model.NewAppError("SqlSessionStore.GetSessions", "store.sql_session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := me.GetReplica().Select(&sessions, "SELECT * FROM Sessions WHERE UserId = :UserId ORDER BY LastActivityAt DESC", map[string]interface{}{"UserId": userId}); err != nil {
|
rtcs := <-tcs
|
||||||
result.Err = model.NewAppError("SqlSessionStore.GetSessions", "store.sql_session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
if rtcs.Err != nil {
|
||||||
} else {
|
return nil, model.NewAppError("SqlSessionStore.GetSessions", "store.sql_session.get_sessions.app_error", nil, rtcs.Err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
result.Data = sessions
|
for _, session := range sessions {
|
||||||
}
|
tempMembers := rtcs.Data.([]*model.TeamMember)
|
||||||
|
session.TeamMembers = make([]*model.TeamMember, 0, len(tempMembers))
|
||||||
if rtcs := <-tcs; rtcs.Err != nil {
|
for _, tm := range tempMembers {
|
||||||
result.Err = model.NewAppError("SqlSessionStore.GetSessions", "store.sql_session.get_sessions.app_error", nil, rtcs.Err.Error(), http.StatusInternalServerError)
|
if tm.DeleteAt == 0 {
|
||||||
return
|
session.TeamMembers = append(session.TeamMembers, tm)
|
||||||
} else {
|
|
||||||
for _, session := range sessions {
|
|
||||||
tempMembers := rtcs.Data.([]*model.TeamMember)
|
|
||||||
session.TeamMembers = make([]*model.TeamMember, 0, len(tempMembers))
|
|
||||||
for _, tm := range tempMembers {
|
|
||||||
if tm.DeleteAt == 0 {
|
|
||||||
session.TeamMembers = append(session.TeamMembers, tm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
return sessions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (me SqlSessionStore) GetSessionsWithActiveDeviceIds(userId string) ([]*model.Session, *model.AppError) {
|
func (me SqlSessionStore) GetSessionsWithActiveDeviceIds(userId string) ([]*model.Session, *model.AppError) {
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ type BotStore interface {
|
|||||||
type SessionStore interface {
|
type SessionStore interface {
|
||||||
Get(sessionIdOrToken string) (*model.Session, *model.AppError)
|
Get(sessionIdOrToken string) (*model.Session, *model.AppError)
|
||||||
Save(session *model.Session) (*model.Session, *model.AppError)
|
Save(session *model.Session) (*model.Session, *model.AppError)
|
||||||
GetSessions(userId string) StoreChannel
|
GetSessions(userId string) ([]*model.Session, *model.AppError)
|
||||||
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
|
||||||
|
|||||||
@@ -67,19 +67,28 @@ func (_m *SessionStore) Get(sessionIdOrToken string) (*model.Session, *model.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSessions provides a mock function with given fields: userId
|
// GetSessions provides a mock function with given fields: userId
|
||||||
func (_m *SessionStore) GetSessions(userId string) store.StoreChannel {
|
func (_m *SessionStore) GetSessions(userId string) ([]*model.Session, *model.AppError) {
|
||||||
ret := _m.Called(userId)
|
ret := _m.Called(userId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Session
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) []*model.Session); ok {
|
||||||
r0 = rf(userId)
|
r0 = rf(userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).([]*model.Session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
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, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSessionsWithActiveDeviceIds provides a mock function with given fields: userId
|
// GetSessionsWithActiveDeviceIds provides a mock function with given fields: userId
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ func testSessionGet(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rs2 := (<-ss.Session().GetSessions(s1.UserId)); rs2.Err != nil {
|
if session, err := ss.Session().GetSessions(s1.UserId); err != nil {
|
||||||
t.Fatal(rs2.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if len(rs2.Data.([]*model.Session)) != 3 {
|
if len(session) != 3 {
|
||||||
t.Fatal("should match len")
|
t.Fatal("should match len")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,10 +197,10 @@ func testSessionRemoveToken(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal("should have been removed")
|
t.Fatal("should have been removed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if rs3 := (<-ss.Session().GetSessions(s1.UserId)); rs3.Err != nil {
|
if session, err := ss.Session().GetSessions(s1.UserId); err != nil {
|
||||||
t.Fatal(rs3.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if len(rs3.Data.([]*model.Session)) != 0 {
|
if len(session) != 0 {
|
||||||
t.Fatal("should match len")
|
t.Fatal("should match len")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user