Migrate GetDeletedByName from ChannelStore to return error interface (#14709)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1d9c8a490d
Коммит
8dc7c5762f
@@ -536,7 +536,7 @@ func (a *App) SlackAddChannels(teamId string, slackchannels []SlackChannel, post
|
||||
if mChannel, err = a.Srv().Store.Channel().GetByName(teamId, sChannel.Name, true); err == nil {
|
||||
// The channel already exists as an active channel. Merge with the existing one.
|
||||
importerLog.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
|
||||
} else if _, err := a.Srv().Store.Channel().GetDeletedByName(teamId, sChannel.Name); err == nil {
|
||||
} else if _, nErr := a.Srv().Store.Channel().GetDeletedByName(teamId, sChannel.Name); nErr == nil {
|
||||
// The channel already exists but has been deleted. Generate a random string for the handle instead.
|
||||
newChannel.Name = model.NewId()
|
||||
newChannel = SlackSanitiseChannelProperties(newChannel)
|
||||
|
||||
@@ -6198,14 +6198,6 @@
|
||||
"id": "store.sql_channel.get_channels_by_ids.not_found.app_error",
|
||||
"translation": "No channel found."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.get_deleted_by_name.existing.app_error",
|
||||
"translation": "Unable to find the existing deleted channel."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.get_deleted_by_name.missing.app_error",
|
||||
"translation": "No deleted channel exists with that name."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.get_for_post.app_error",
|
||||
"translation": "Unable to get the channel for the given post."
|
||||
|
||||
@@ -990,7 +990,7 @@ func (s *OpenTracingLayerChannelStore) GetDeleted(team_id string, offset int, li
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) {
|
||||
func (s *OpenTracingLayerChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetDeletedByName")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -1256,14 +1256,14 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Channel, *model.AppError) {
|
||||
func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Channel, error) {
|
||||
channel := model.Channel{}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&channel, "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND Name = :Name AND DeleteAt != 0", map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.missing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusNotFound)
|
||||
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("name=%s", name))
|
||||
}
|
||||
return nil, model.NewAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.existing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusInternalServerError)
|
||||
return nil, errors.Wrapf(err, "failed to get channel by teamId=%s and name=%s", teamId, name)
|
||||
}
|
||||
|
||||
return &channel, nil
|
||||
|
||||
@@ -146,7 +146,7 @@ type ChannelStore interface {
|
||||
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, error)
|
||||
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, error)
|
||||
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, error)
|
||||
GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError)
|
||||
GetDeletedByName(team_id string, name string) (*model.Channel, error)
|
||||
GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, error)
|
||||
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, error)
|
||||
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
|
||||
|
||||
@@ -734,12 +734,12 @@ func testChannelStoreGetDeletedByName(t *testing.T, ss store.Store) {
|
||||
o1.DeleteAt = now
|
||||
o1.UpdateAt = now
|
||||
|
||||
r1, err := ss.Channel().GetDeletedByName(o1.TeamId, o1.Name)
|
||||
require.Nil(t, err)
|
||||
r1, nErr := ss.Channel().GetDeletedByName(o1.TeamId, o1.Name)
|
||||
require.Nil(t, nErr)
|
||||
require.Equal(t, o1, r1)
|
||||
|
||||
_, err = ss.Channel().GetDeletedByName(o1.TeamId, "")
|
||||
require.NotNil(t, err, "missing id should have failed")
|
||||
_, nErr = ss.Channel().GetDeletedByName(o1.TeamId, "")
|
||||
require.NotNil(t, nErr, "missing id should have failed")
|
||||
}
|
||||
|
||||
func testChannelStoreGetDeleted(t *testing.T, ss store.Store) {
|
||||
|
||||
@@ -675,7 +675,7 @@ func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId
|
||||
}
|
||||
|
||||
// GetDeletedByName provides a mock function with given fields: team_id, name
|
||||
func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) {
|
||||
func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, error) {
|
||||
ret := _m.Called(team_id, name)
|
||||
|
||||
var r0 *model.Channel
|
||||
@@ -687,13 +687,11 @@ func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Ch
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
||||
r1 = rf(team_id, name)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
|
||||
@@ -920,7 +920,7 @@ func (s *TimerLayerChannelStore) GetDeleted(team_id string, offset int, limit in
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) {
|
||||
func (s *TimerLayerChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0, resultVar1 := s.ChannelStore.GetDeletedByName(team_id, name)
|
||||
|
||||
Ссылка в новой задаче
Block a user