diff --git a/app/permissions.go b/app/permissions.go index 5fdd0a77b3..dd6ebb2c5c 100644 --- a/app/permissions.go +++ b/app/permissions.go @@ -23,8 +23,8 @@ func (a *App) ResetPermissionsSystem() *model.AppError { } // Reset all Channels to not have a scheme. - if result := <-a.Srv.Store.Channel().ResetAllChannelSchemes(); result.Err != nil { - return result.Err + if err := a.Srv.Store.Channel().ResetAllChannelSchemes(); err != nil { + return err } // Reset all Custom Role assignments to Users. diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index c3406236a4..a3c126e6fe 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -2340,36 +2340,31 @@ func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId return data, nil } -func (s SqlChannelStore) ResetAllChannelSchemes() store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - transaction, err := s.GetMaster().Begin() - if err != nil { - result.Err = model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) - return - } - defer finalizeTransaction(transaction) +func (s SqlChannelStore) ResetAllChannelSchemes() *model.AppError { + transaction, err := s.GetMaster().Begin() + if err != nil { + return model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + } + defer finalizeTransaction(transaction) - *result = s.resetAllChannelSchemesT(transaction) - if result.Err != nil { - return - } - - if err := transaction.Commit(); err != nil { - result.Err = model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) - return - } - }) -} - -func (s SqlChannelStore) resetAllChannelSchemesT(transaction *gorp.Transaction) store.StoreResult { - result := store.StoreResult{} - - if _, err := transaction.Exec("UPDATE Channels SET SchemeId=''"); err != nil { - result.Err = model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.app_error", nil, err.Error(), http.StatusInternalServerError) - return result + resetErr := s.resetAllChannelSchemesT(transaction) + if resetErr != nil { + return resetErr } - return result + if err := transaction.Commit(); err != nil { + return model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return nil +} + +func (s SqlChannelStore) resetAllChannelSchemesT(transaction *gorp.Transaction) *model.AppError { + if _, err := transaction.Exec("UPDATE Channels SET SchemeId=''"); err != nil { + return model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return nil } func (s SqlChannelStore) ClearAllCustomRoleAssignments() *model.AppError { diff --git a/store/store.go b/store/store.go index 1ead84f72c..3a03184d34 100644 --- a/store/store.go +++ b/store/store.go @@ -191,7 +191,7 @@ type ChannelStore interface { ClearCaches() GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError) - ResetAllChannelSchemes() StoreChannel + ResetAllChannelSchemes() *model.AppError ClearAllCustomRoleAssignments() *model.AppError MigratePublicChannels() error GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 66ebcceef1..83fe844480 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -3037,8 +3037,8 @@ func testResetAllChannelSchemes(t *testing.T, ss store.Store) { assert.Equal(t, s1.Id, *c1.SchemeId) assert.Equal(t, s1.Id, *c2.SchemeId) - res := <-ss.Channel().ResetAllChannelSchemes() - assert.Nil(t, res.Err) + err := ss.Channel().ResetAllChannelSchemes() + assert.Nil(t, err) c1, _ = ss.Channel().Get(c1.Id, true) c2, _ = ss.Channel().Get(c2.Id, true) diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 7d2617de6f..2b52c4db91 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -1161,15 +1161,15 @@ func (_m *ChannelStore) RemoveMember(channelId string, userId string) *model.App } // ResetAllChannelSchemes provides a mock function with given fields: -func (_m *ChannelStore) ResetAllChannelSchemes() store.StoreChannel { +func (_m *ChannelStore) ResetAllChannelSchemes() *model.AppError { ret := _m.Called() - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func() store.StoreChannel); ok { + var r0 *model.AppError + if rf, ok := ret.Get(0).(func() *model.AppError); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).(*model.AppError) } }