MM-15801 Migrate "Session.UpdateRoles" to Sync by default (#11015)

This commit is contained in:
Bolarinwa Balogun
2019-06-12 14:45:47 -04:00
committed by Hanzei
parent 7b9833405d
commit 58e126b910
4 changed files with 29 additions and 16 deletions

View File

@@ -1390,7 +1390,13 @@ func (a *App) UpdateUserRoles(userId string, newRoles string, sendWebSocketEvent
uchan <- store.StoreResult{Data: userUpdate, Err: err}
close(uchan)
}()
schan := a.Srv.Store.Session().UpdateRoles(user.Id, newRoles)
schan := make(chan store.StoreResult, 1)
go func() {
userId, err := a.Srv.Store.Session().UpdateRoles(user.Id, newRoles)
schan <- store.StoreResult{Data: userId, Err: err}
close(schan)
}()
result := <-uchan
if result.Err != nil {

View File

@@ -178,14 +178,14 @@ func (me SqlSessionStore) UpdateLastActivityAt(sessionId string, time int64) *mo
return nil
}
func (me SqlSessionStore) UpdateRoles(userId, roles string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if _, err := me.GetMaster().Exec("UPDATE Sessions SET Roles = :Roles WHERE UserId = :UserId", map[string]interface{}{"Roles": roles, "UserId": userId}); err != nil {
result.Err = model.NewAppError("SqlSessionStore.UpdateRoles", "store.sql_session.update_roles.app_error", nil, "userId="+userId, http.StatusInternalServerError)
} else {
result.Data = userId
}
})
func (me SqlSessionStore) UpdateRoles(userId, roles string) (string, *model.AppError) {
query := "UPDATE Sessions SET Roles = :Roles WHERE UserId = :UserId"
_, err := me.GetMaster().Exec(query, map[string]interface{}{"Roles": roles, "UserId": userId})
if err != nil {
return "", model.NewAppError("SqlSessionStore.UpdateRoles", "store.sql_session.update_roles.app_error", nil, "userId="+userId, http.StatusInternalServerError)
}
return userId, nil
}
func (me SqlSessionStore) UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError) {

View File

@@ -320,7 +320,7 @@ type SessionStore interface {
RemoveAllSessions() *model.AppError
PermanentDeleteSessionsByUser(teamId string) *model.AppError
UpdateLastActivityAt(sessionId string, time int64) *model.AppError
UpdateRoles(userId string, roles string) StoreChannel
UpdateRoles(userId string, roles string) (string, *model.AppError)
UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError)
AnalyticsSessionCount() (int64, *model.AppError)
Cleanup(expiryTime int64, batchSize int64)

View File

@@ -229,17 +229,24 @@ func (_m *SessionStore) UpdateLastActivityAt(sessionId string, time int64) *mode
}
// UpdateRoles provides a mock function with given fields: userId, roles
func (_m *SessionStore) UpdateRoles(userId string, roles string) store.StoreChannel {
func (_m *SessionStore) UpdateRoles(userId string, roles string) (string, *model.AppError) {
ret := _m.Called(userId, roles)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
var r0 string
if rf, ok := ret.Get(0).(func(string, string) string); ok {
r0 = rf(userId, roles)
} 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) *model.AppError); ok {
r1 = rf(userId, roles)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0
return r0, r1
}