diff --git a/app/user.go b/app/user.go index b77d7925d8..84c975a76d 100644 --- a/app/user.go +++ b/app/user.go @@ -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 { diff --git a/store/sqlstore/session_store.go b/store/sqlstore/session_store.go index 399f13f4cb..c11a0bc21a 100644 --- a/store/sqlstore/session_store.go +++ b/store/sqlstore/session_store.go @@ -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) { diff --git a/store/store.go b/store/store.go index 5eb4b54576..c4561ffd06 100644 --- a/store/store.go +++ b/store/store.go @@ -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) diff --git a/store/storetest/mocks/SessionStore.go b/store/storetest/mocks/SessionStore.go index dc39c4924a..79246becf1 100644 --- a/store/storetest/mocks/SessionStore.go +++ b/store/storetest/mocks/SessionStore.go @@ -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 }