Migrate PermanentDelete method from ChannelStore to return error inte… (#14706)

Automatic Merge
Этот коммит содержится в:
Rodrigo Villablanca
2020-06-06 05:47:18 -04:00
коммит произвёл GitHub
родитель 88e8f56f03
Коммит 6f28f3526d
10 изменённых файлов: 26 добавлений и 40 удалений

Просмотреть файл

@@ -2296,8 +2296,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
return err return err
} }
if err := a.Srv().Store.Channel().PermanentDelete(channel.Id); err != nil { if nErr := a.Srv().Store.Channel().PermanentDelete(channel.Id); nErr != nil {
return err return model.NewAppError("PermanentDeleteChannel", "app.channel.permanent_delete.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
return nil return nil

Просмотреть файл

@@ -3002,6 +3002,10 @@
"id": "app.channel.move_channel.members_do_not_match.error", "id": "app.channel.move_channel.members_do_not_match.error",
"translation": "Unable to move a channel unless all its members are already members of the destination team." "translation": "Unable to move a channel unless all its members are already members of the destination team."
}, },
{
"id": "app.channel.permanent_delete.app_error",
"translation": "Unable to delete the channel."
},
{ {
"id": "app.channel.post_update_channel_purpose_message.post.error", "id": "app.channel.post_update_channel_purpose_message.post.error",
"translation": "Failed to post channel purpose message" "translation": "Failed to post channel purpose message"
@@ -6246,22 +6250,6 @@
"id": "store.sql_channel.migrate_channel_members.update.app_error", "id": "store.sql_channel.migrate_channel_members.update.app_error",
"translation": "Failed to update the channel member." "translation": "Failed to update the channel member."
}, },
{
"id": "store.sql_channel.permanent_delete.app_error",
"translation": "Unable to delete the channel."
},
{
"id": "store.sql_channel.permanent_delete.commit_transaction.app_error",
"translation": "Unable to commit transaction."
},
{
"id": "store.sql_channel.permanent_delete.delete_public_channel.app_error",
"translation": "Unable to delete materialized public channel."
},
{
"id": "store.sql_channel.permanent_delete.open_transaction.app_error",
"translation": "Unable to open transaction."
},
{ {
"id": "store.sql_channel.permanent_delete_by_team.app_error", "id": "store.sql_channel.permanent_delete_by_team.app_error",
"translation": "Unable to delete the channels." "translation": "Unable to delete the channels."

Просмотреть файл

@@ -1503,7 +1503,7 @@ func (s *OpenTracingLayerChannelStore) MigratePublicChannels() error {
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) *model.AppError { func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDelete") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDelete")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)

Просмотреть файл

@@ -194,7 +194,7 @@ func (c *SearchChannelStore) PermanentDeleteMembersByChannel(channelId string) *
return err return err
} }
func (c *SearchChannelStore) PermanentDelete(channelId string) *model.AppError { func (c *SearchChannelStore) PermanentDelete(channelId string) error {
channel, channelErr := c.ChannelStore.Get(channelId, true) channel, channelErr := c.ChannelStore.Get(channelId, true)
if channelErr != nil { if channelErr != nil {
mlog.Error("Encountered error deleting channel", mlog.String("channel_id", channelId), mlog.Err(channelErr)) mlog.Error("Encountered error deleting channel", mlog.String("channel_id", channelId), mlog.Err(channelErr))

Просмотреть файл

@@ -317,9 +317,9 @@ func (th *SearchTestHelper) deleteChannel(channel *model.Channel) error {
return errors.New(appError.Error()) return errors.New(appError.Error())
} }
appError = th.Store.Channel().PermanentDelete(channel.Id) err := th.Store.Channel().PermanentDelete(channel.Id)
if appError != nil { if err != nil {
return errors.New(appError.Error()) return err
} }
return nil return nil

Просмотреть файл

@@ -865,15 +865,15 @@ func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction,
} }
// PermanentDelete removes the given channel from the database. // PermanentDelete removes the given channel from the database.
func (s SqlChannelStore) PermanentDelete(channelId string) *model.AppError { func (s SqlChannelStore) PermanentDelete(channelId string) error {
transaction, err := s.GetMaster().Begin() transaction, err := s.GetMaster().Begin()
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "PermanentDelete: begin_transaction")
} }
defer finalizeTransaction(transaction) defer finalizeTransaction(transaction)
if err := s.permanentDeleteT(transaction, channelId); err != nil { if err := s.permanentDeleteT(transaction, channelId); err != nil {
return err return errors.Wrap(err, "permanentDeleteT")
} }
// Additionally propagate the deletion to the PublicChannels table. // Additionally propagate the deletion to the PublicChannels table.
@@ -885,19 +885,19 @@ func (s SqlChannelStore) PermanentDelete(channelId string) *model.AppError {
`, map[string]interface{}{ `, map[string]interface{}{
"ChannelId": channelId, "ChannelId": channelId,
}); err != nil { }); err != nil {
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.delete_public_channel.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete public channels with id=%s", channelId)
} }
if err := transaction.Commit(); err != nil { if err := transaction.Commit(); err != nil {
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "PermanentDelete: commit_transaction")
} }
return nil return nil
} }
func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channelId string) *model.AppError { func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channelId string) error {
if _, err := transaction.Exec("DELETE FROM Channels WHERE Id = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil { if _, err := transaction.Exec("DELETE FROM Channels WHERE Id = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil {
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete channel with id=%s", channelId)
} }
return nil return nil

Просмотреть файл

@@ -141,7 +141,7 @@ type ChannelStore interface {
Delete(channelId string, time int64) error Delete(channelId string, time int64) error
Restore(channelId string, time int64) error Restore(channelId string, time int64) error
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error
PermanentDelete(channelId string) *model.AppError PermanentDelete(channelId string) error
PermanentDeleteByTeam(teamId string) *model.AppError PermanentDeleteByTeam(teamId string) *model.AppError
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError)

Просмотреть файл

@@ -31,8 +31,8 @@ func cleanupStoreState(t *testing.T, ss store.Store) {
allChannels, err := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true}) allChannels, err := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nilf(t, err, "error cleaning all test channels: %v", err) require.Nilf(t, err, "error cleaning all test channels: %v", err)
for _, channel := range *allChannels { for _, channel := range *allChannels {
err = ss.Channel().PermanentDelete(channel.Id) nErr := ss.Channel().PermanentDelete(channel.Id)
require.Nil(t, err, "failed cleaning up test channel %s", channel.Id) require.Nil(t, nErr, "failed cleaning up test channel %s", channel.Id)
} }
//remove existing teams //remove existing teams

Просмотреть файл

@@ -1272,16 +1272,14 @@ func (_m *ChannelStore) MigratePublicChannels() error {
} }
// PermanentDelete provides a mock function with given fields: channelId // PermanentDelete provides a mock function with given fields: channelId
func (_m *ChannelStore) PermanentDelete(channelId string) *model.AppError { func (_m *ChannelStore) PermanentDelete(channelId string) error {
ret := _m.Called(channelId) ret := _m.Called(channelId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(channelId) r0 = rf(channelId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0

Просмотреть файл

@@ -1409,7 +1409,7 @@ func (s *TimerLayerChannelStore) MigratePublicChannels() error {
return resultVar0 return resultVar0
} }
func (s *TimerLayerChannelStore) PermanentDelete(channelId string) *model.AppError { func (s *TimerLayerChannelStore) PermanentDelete(channelId string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.ChannelStore.PermanentDelete(channelId) resultVar0 := s.ChannelStore.PermanentDelete(channelId)