From 172eb1853f85916a7781155e39ba265597c3e537 Mon Sep 17 00:00:00 2001 From: Rodrigo Villablanca Date: Thu, 11 Jun 2020 11:26:35 -0400 Subject: [PATCH] =?UTF-8?q?Migrate=20PermanentDeleteByTeam=20method=20from?= =?UTF-8?q?=20ChannelStore=20to=20return=20erro=E2=80=A6=20(#14707)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic Merge --- i18n/en.json | 16 ---------------- store/opentracing_layer.go | 2 +- store/sqlstore/channel_store.go | 14 +++++++------- store/store.go | 2 +- store/storetest/channel_store.go | 4 ++-- store/storetest/mocks/ChannelStore.go | 10 ++++------ store/timer_layer.go | 2 +- 7 files changed, 16 insertions(+), 34 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index ba6eff0235..8459b909b4 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -6258,22 +6258,6 @@ "id": "store.sql_channel.migrate_channel_members.update.app_error", "translation": "Failed to update the channel member." }, - { - "id": "store.sql_channel.permanent_delete_by_team.app_error", - "translation": "Unable to delete the channels." - }, - { - "id": "store.sql_channel.permanent_delete_by_team.commit_transaction.app_error", - "translation": "Unable to commit transaction." - }, - { - "id": "store.sql_channel.permanent_delete_by_team.delete_public_channels.app_error", - "translation": "Unable to delete materialized public channels." - }, - { - "id": "store.sql_channel.permanent_delete_by_team.open_transaction.app_error", - "translation": "Unable to open transaction." - }, { "id": "store.sql_channel.permanent_delete_members_by_user.app_error", "translation": "Unable to remove the channel member." diff --git a/store/opentracing_layer.go b/store/opentracing_layer.go index 5d3d431512..9cce851fac 100644 --- a/store/opentracing_layer.go +++ b/store/opentracing_layer.go @@ -1521,7 +1521,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) error { return resultVar0 } -func (s *OpenTracingLayerChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { +func (s *OpenTracingLayerChannelStore) PermanentDeleteByTeam(teamId string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteByTeam") s.Root.Store.SetContext(newCtx) diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 77d720805b..f8345a0755 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -826,15 +826,15 @@ func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId s } // PermanentDeleteByTeam removes all channels for the given team from the database. -func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { +func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) error { transaction, err := s.GetMaster().Begin() if err != nil { - return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "PermanentDeleteByTeam: begin_transaction") } defer finalizeTransaction(transaction) if err := s.permanentDeleteByTeamtT(transaction, teamId); err != nil { - return err + return errors.Wrap(err, "permanentDeleteByTeamtT") } // Additionally propagate the deletions to the PublicChannels table. @@ -846,19 +846,19 @@ func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { `, map[string]interface{}{ "TeamId": teamId, }); err != nil { - return model.NewAppError("SqlChannelStore.PermanentDeleteByTeamt", "store.sql_channel.permanent_delete_by_team.delete_public_channels.app_error", nil, "team_id="+teamId+", "+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete public channels by team with teamId=%s", teamId) } if err := transaction.Commit(); err != nil { - return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "PermanentDeleteByTeam: commit_transaction") } return nil } -func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, teamId string) *model.AppError { +func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, teamId string) error { if _, err := transaction.Exec("DELETE FROM Channels WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil { - return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete channel by team with teamId=%s", teamId) } return nil diff --git a/store/store.go b/store/store.go index 52df8ccd24..79dc7513ba 100644 --- a/store/store.go +++ b/store/store.go @@ -142,7 +142,7 @@ type ChannelStore interface { Restore(channelId string, time int64) error SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error PermanentDelete(channelId string) error - PermanentDeleteByTeam(teamId string) *model.AppError + PermanentDeleteByTeam(teamId string) error GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index bc36db4b49..453427c5df 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -628,8 +628,8 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) { require.Equal(t, &model.ChannelList{}, list) } - err = ss.Channel().PermanentDeleteByTeam(o1.TeamId) - require.Nil(t, err, err) + nErr = ss.Channel().PermanentDeleteByTeam(o1.TeamId) + require.Nil(t, nErr, nErr) } func testChannelStoreGetByName(t *testing.T, ss store.Store) { diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index a158b52f0e..9959521e42 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -1278,16 +1278,14 @@ func (_m *ChannelStore) PermanentDelete(channelId string) error { } // PermanentDeleteByTeam provides a mock function with given fields: teamId -func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { +func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) error { ret := _m.Called(teamId) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(teamId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 diff --git a/store/timer_layer.go b/store/timer_layer.go index 40955bee91..ce6398adf8 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -1425,7 +1425,7 @@ func (s *TimerLayerChannelStore) PermanentDelete(channelId string) error { return resultVar0 } -func (s *TimerLayerChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { +func (s *TimerLayerChannelStore) PermanentDeleteByTeam(teamId string) error { start := timemodule.Now() resultVar0 := s.ChannelStore.PermanentDeleteByTeam(teamId)