Migrate GetDeleted method from ChannelStore to return error interface (#14710)
* Migrate GetDeleted method from ChannelStore to return error interface * Moving i18n translations to the correct place Co-authored-by: Jesús Espino <jespinog@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f2253df8a1
Коммит
9b0ae49b55
@@ -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) {
|
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) {
|
func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||||
|
|||||||
16
i18n/en.json
16
i18n/en.json
@@ -3006,6 +3006,14 @@
|
|||||||
"id": "app.channel.get_all_channels_count.app_error",
|
"id": "app.channel.get_all_channels_count.app_error",
|
||||||
"translation": "Unable to count all the channels."
|
"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",
|
"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."
|
||||||
@@ -6178,14 +6186,6 @@
|
|||||||
"id": "store.sql_channel.get_channels_by_ids.not_found.app_error",
|
"id": "store.sql_channel.get_channels_by_ids.not_found.app_error",
|
||||||
"translation": "No channel found."
|
"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",
|
"id": "store.sql_channel.get_deleted_by_name.existing.app_error",
|
||||||
"translation": "Unable to find the existing deleted channel."
|
"translation": "Unable to find the existing deleted channel."
|
||||||
|
|||||||
@@ -972,7 +972,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelsByScheme(schemeId string, offs
|
|||||||
return resultVar0, resultVar1
|
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()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetDeleted")
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetDeleted")
|
||||||
s.Root.Store.SetContext(newCtx)
|
s.Root.Store.SetContext(newCtx)
|
||||||
|
|||||||
@@ -1263,7 +1263,7 @@ func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Ch
|
|||||||
return &channel, nil
|
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{}
|
channels := &model.ChannelList{}
|
||||||
|
|
||||||
query := `
|
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 := s.GetReplica().Select(channels, query, map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset, "UserId": userId}); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
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
|
return channels, nil
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ type ChannelStore interface {
|
|||||||
GetByNames(team_id string, names []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)
|
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
|
||||||
GetDeletedByName(team_id string, name string) (*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)
|
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||||
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
|
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
|
||||||
GetAllChannelsCount(opts ChannelSearchOpts) (int64, error)
|
GetAllChannelsCount(opts ChannelSearchOpts) (int64, error)
|
||||||
|
|||||||
@@ -756,8 +756,8 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) {
|
|||||||
err := ss.Channel().Delete(o1.Id, model.GetMillis())
|
err := ss.Channel().Delete(o1.Id, model.GetMillis())
|
||||||
require.Nil(t, err, "channel should have been deleted")
|
require.Nil(t, err, "channel should have been deleted")
|
||||||
|
|
||||||
list, err := ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
|
list, nErr := ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
|
||||||
require.Nil(t, err, err)
|
require.Nil(t, nErr, nErr)
|
||||||
require.Len(t, *list, 1, "wrong list")
|
require.Len(t, *list, 1, "wrong list")
|
||||||
require.Equal(t, o1.Name, (*list)[0].Name, "missing channel")
|
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)
|
_, nErr = ss.Channel().Save(&o2, -1)
|
||||||
require.Nil(t, nErr)
|
require.Nil(t, nErr)
|
||||||
|
|
||||||
list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
|
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
|
||||||
require.Nil(t, err, err)
|
require.Nil(t, nErr, nErr)
|
||||||
require.Len(t, *list, 1, "wrong list")
|
require.Len(t, *list, 1, "wrong list")
|
||||||
|
|
||||||
o3 := model.Channel{}
|
o3 := model.Channel{}
|
||||||
@@ -785,16 +785,16 @@ func testChannelStoreGetDeleted(t *testing.T, ss store.Store) {
|
|||||||
err = ss.Channel().Delete(o3.Id, model.GetMillis())
|
err = ss.Channel().Delete(o3.Id, model.GetMillis())
|
||||||
require.Nil(t, err, "channel should have been deleted")
|
require.Nil(t, err, "channel should have been deleted")
|
||||||
|
|
||||||
list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
|
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 100, userId)
|
||||||
require.Nil(t, err, err)
|
require.Nil(t, nErr, nErr)
|
||||||
require.Len(t, *list, 2, "wrong list length")
|
require.Len(t, *list, 2, "wrong list length")
|
||||||
|
|
||||||
list, err = ss.Channel().GetDeleted(o1.TeamId, 0, 1, userId)
|
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 0, 1, userId)
|
||||||
require.Nil(t, err, err)
|
require.Nil(t, nErr, nErr)
|
||||||
require.Len(t, *list, 1, "wrong list length")
|
require.Len(t, *list, 1, "wrong list length")
|
||||||
|
|
||||||
list, err = ss.Channel().GetDeleted(o1.TeamId, 1, 1, userId)
|
list, nErr = ss.Channel().GetDeleted(o1.TeamId, 1, 1, userId)
|
||||||
require.Nil(t, err, err)
|
require.Nil(t, nErr, nErr)
|
||||||
require.Len(t, *list, 1, "wrong list length")
|
require.Len(t, *list, 1, "wrong list length")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// 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)
|
ret := _m.Called(team_id, offset, limit, userId)
|
||||||
|
|
||||||
var r0 *model.ChannelList
|
var r0 *model.ChannelList
|
||||||
@@ -672,13 +672,11 @@ func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 *model.AppError
|
var r1 error
|
||||||
if rf, ok := ret.Get(1).(func(string, int, int, string) *model.AppError); ok {
|
if rf, ok := ret.Get(1).(func(string, int, int, string) error); ok {
|
||||||
r1 = rf(team_id, offset, limit, userId)
|
r1 = rf(team_id, offset, limit, userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(1) != nil {
|
r1 = ret.Error(1)
|
||||||
r1 = ret.Get(1).(*model.AppError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0, r1
|
return r0, r1
|
||||||
|
|||||||
@@ -904,7 +904,7 @@ func (s *TimerLayerChannelStore) GetChannelsByScheme(schemeId string, offset int
|
|||||||
return resultVar0, resultVar1
|
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()
|
start := timemodule.Now()
|
||||||
|
|
||||||
resultVar0, resultVar1 := s.ChannelStore.GetDeleted(team_id, offset, limit, userId)
|
resultVar0, resultVar1 := s.ChannelStore.GetDeleted(team_id, offset, limit, userId)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user