diff --git a/app/channel.go b/app/channel.go index 337743b822..bd1a8ba685 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1589,7 +1589,18 @@ func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.A } func (a *App) GetDeletedChannels(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) { - return a.Srv().Store.Channel().GetDeleted(teamId, offset, limit, userId) + list, err := a.Srv().Store.Channel().GetDeleted(teamId, offset, limit, userId) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.missing.app_error", nil, err.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetDeletedChannels", "app.channel.get_deleted.existing.app_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return list, nil } func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { diff --git a/i18n/en.json b/i18n/en.json index eee42bf7a2..c0555a13c5 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3006,6 +3006,14 @@ "id": "app.channel.get_all_channels_count.app_error", "translation": "Unable to count all the channels." }, + { + "id": "app.channel.get_deleted.existing.app_error", + "translation": "Unable to find the existing deleted channel." + }, + { + "id": "app.channel.get_deleted.missing.app_error", + "translation": "No deleted channels exist." + }, { "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." @@ -6178,14 +6186,6 @@ "id": "store.sql_channel.get_channels_by_ids.not_found.app_error", "translation": "No channel found." }, - { - "id": "store.sql_channel.get_deleted.existing.app_error", - "translation": "Unable to find the existing deleted channel." - }, - { - "id": "store.sql_channel.get_deleted.missing.app_error", - "translation": "No deleted channels exist." - }, { "id": "store.sql_channel.get_deleted_by_name.existing.app_error", "translation": "Unable to find the existing deleted channel." diff --git a/store/opentracing_layer.go b/store/opentracing_layer.go index 1da2074bd1..402ad764b1 100644 --- a/store/opentracing_layer.go +++ b/store/opentracing_layer.go @@ -972,7 +972,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelsByScheme(schemeId string, offs return resultVar0, resultVar1 } -func (s *OpenTracingLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) { +func (s *OpenTracingLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetDeleted") s.Root.Store.SetContext(newCtx) diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 9b7af36a61..b349972f3e 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -1263,7 +1263,7 @@ func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Ch return &channel, nil } -func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) { +func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId string) (*model.ChannelList, error) { channels := &model.ChannelList{} query := ` @@ -1282,9 +1282,9 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId if _, err := s.GetReplica().Select(channels, query, map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset, "UserId": userId}); err != nil { if err == sql.ErrNoRows { - return nil, model.NewAppError("SqlChannelStore.GetDeleted", "store.sql_channel.get_deleted.missing.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusNotFound) + return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s,UserId=%s", teamId, userId)) } - return nil, model.NewAppError("SqlChannelStore.GetDeleted", "store.sql_channel.get_deleted.existing.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get deleted channels with TeamId=%s and UserId=%s", teamId, userId) } return channels, nil diff --git a/store/store.go b/store/store.go index 8b943fde17..5bcea6de29 100644 --- a/store/store.go +++ b/store/store.go @@ -147,7 +147,7 @@ type ChannelStore interface { GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) - GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) + GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error) GetAllChannelsCount(opts ChannelSearchOpts) (int64, error) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index 06a2e52d36..a7af4c6509 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -756,8 +756,8 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) { err := ss.Channel().Delete(o1.Id, model.GetMillis()) require.Nil(t, err, "channel should have been deleted") - list, err := ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId) - require.Nil(t, err, err) + list, nErr := ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId) + require.Nil(t, nErr, nErr) require.Len(t, *list, 1, "wrong list") require.Equal(t, o1.Name, (*list)[0].Name, "missing channel") @@ -769,8 +769,8 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) { _, nErr = ss.Channel().Save(&o2, -1) require.Nil(t, nErr) - list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId) - require.Nil(t, err, err) + list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId) + require.Nil(t, nErr, nErr) require.Len(t, *list, 1, "wrong list") o3 := model.Channel{} @@ -785,16 +785,16 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) { err = ss.Channel().Delete(o3.Id, model.GetMillis()) require.Nil(t, err, "channel should have been deleted") - list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId) - require.Nil(t, err, err) + list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId) + require.Nil(t, nErr, nErr) require.Len(t, *list, 2, "wrong list length") - list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 1, userId) - require.Nil(t, err, err) + list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 1, userId) + require.Nil(t, nErr, nErr) require.Len(t, *list, 1, "wrong list length") - list, err = ss.Channel().GetDeleted(o1.TeamId, 1, 1, userId) - require.Nil(t, err, err) + list, nErr = ss.Channel().GetDeleted(o1.TeamId, 1, 1, userId) + require.Nil(t, nErr, nErr) require.Len(t, *list, 1, "wrong list length") } diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 19f2cb5bc1..a4190f9f43 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -660,7 +660,7 @@ func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit i } // GetDeleted provides a mock function with given fields: team_id, offset, limit, userId -func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) { +func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) { ret := _m.Called(team_id, offset, limit, userId) var r0 *model.ChannelList @@ -672,13 +672,11 @@ func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, int, int, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, int, int, string) error); ok { r1 = rf(team_id, offset, limit, userId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/store/timer_layer.go b/store/timer_layer.go index 85db3c19f1..5685262293 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -904,7 +904,7 @@ func (s *TimerLayerChannelStore) GetChannelsByScheme(schemeId string, offset int return resultVar0, resultVar1 } -func (s *TimerLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) { +func (s *TimerLayerChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error) { start := timemodule.Now() resultVar0, resultVar1 := s.ChannelStore.GetDeleted(team_id, offset, limit, userId)