[MM-46054] Log missing default channels (#20738)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
34832e0a3f
Коммит
2365f1286b
@@ -91,17 +91,10 @@ func (a *App) JoinDefaultChannels(c request.CTX, teamID string, user *model.User
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var err *model.AppError
|
|
||||||
for _, channelName := range a.DefaultChannelNames(c) {
|
for _, channelName := range a.DefaultChannelNames(c) {
|
||||||
channel, channelErr := a.Srv().Store.Channel().GetByName(teamID, channelName, true)
|
channel, channelErr := a.Srv().Store.Channel().GetByName(teamID, channelName, true)
|
||||||
if channelErr != nil {
|
if channelErr != nil {
|
||||||
var nfErr *store.ErrNotFound
|
c.Logger().Warn("No default channel with this name", mlog.String("channelName", channelName), mlog.String("teamID", teamID), mlog.Err(channelErr))
|
||||||
switch {
|
|
||||||
case errors.As(err, &nfErr):
|
|
||||||
err = model.NewAppError("JoinDefaultChannels", "app.channel.get_by_name.missing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
|
||||||
default:
|
|
||||||
err = model.NewAppError("JoinDefaultChannels", "app.channel.get_by_name.existing.app_error", nil, channelErr.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -347,6 +347,33 @@ func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJoinDefaultChannelsExperimentalDefaultChannelsMissing(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
basicChannel2 := th.CreateChannel(th.Context, th.BasicTeam)
|
||||||
|
defer th.App.PermanentDeleteChannel(th.Context, basicChannel2)
|
||||||
|
defaultChannelList := []string{th.BasicChannel.Name, basicChannel2.Name, "thischanneldoesnotexist", basicChannel2.Name}
|
||||||
|
th.App.Config().TeamSettings.ExperimentalDefaultChannels = defaultChannelList
|
||||||
|
|
||||||
|
user := th.CreateUser()
|
||||||
|
require.Nil(t, th.App.JoinDefaultChannels(th.Context, th.BasicTeam.Id, user, false, ""))
|
||||||
|
|
||||||
|
for _, channelName := range defaultChannelList {
|
||||||
|
if channelName == "thischanneldoesnotexist" {
|
||||||
|
continue // skip the non-existent channel
|
||||||
|
}
|
||||||
|
|
||||||
|
channel, err := th.App.GetChannelByName(th.Context, channelName, th.BasicTeam.Id, false)
|
||||||
|
require.Nil(t, err, "Expected nil, didn't receive nil")
|
||||||
|
|
||||||
|
member, err := th.App.GetChannelMember(th.Context, channel.Id, user.Id)
|
||||||
|
|
||||||
|
require.NotNil(t, member, "Expected member object, got nil")
|
||||||
|
require.Nil(t, err, "Expected nil object, didn't receive nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) {
|
func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user