MM-65575: Fix server panic when bot posts trigger persistent notifications (#34174) (#34778)

* reproduce panic with test

* allow bots in the profile map

* explicitly prevent sending notifications to bots

* persistent notifications: handle senders not in the channel
Этот коммит содержится в:
Jesse Hallam
2025-12-17 11:06:57 -04:00
коммит произвёл GitHub
родитель e150243a7f
Коммит c9d60357db
5 изменённых файлов: 178 добавлений и 6 удалений

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

@@ -1140,6 +1140,50 @@ func TestShouldSendPushNotifications(t *testing.T) {
result := th.App.ShouldSendPushNotification(user, channelNotifyProps, false, status, post, false)
assert.False(t, result)
})
t.Run("should return false if recipient is a bot", func(t *testing.T) {
botUser := &model.User{Id: model.NewId(), Email: "bot@test.com", IsBot: true, NotifyProps: make(map[string]string)}
botUser.NotifyProps[model.PushNotifyProp] = model.UserNotifyAll
post := &model.Post{UserId: model.NewId(), ChannelId: model.NewId()}
channelNotifyProps := map[string]string{model.PushNotifyProp: model.ChannelNotifyAll}
status := &model.Status{UserId: botUser.Id, Status: model.StatusOnline, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
result := th.App.ShouldSendPushNotification(botUser, channelNotifyProps, true, status, post, false)
assert.False(t, result)
})
t.Run("should return false if recipient is a bot even with force notification", func(t *testing.T) {
botUser := &model.User{Id: model.NewId(), Email: "bot@test.com", IsBot: true, NotifyProps: make(map[string]string)}
botUser.NotifyProps[model.PushNotifyProp] = model.UserNotifyAll
post := &model.Post{UserId: model.NewId(), ChannelId: model.NewId()}
post.AddProp(model.PostPropsForceNotification, model.NewId())
channelNotifyProps := map[string]string{model.PushNotifyProp: model.ChannelNotifyAll}
status := &model.Status{UserId: botUser.Id, Status: model.StatusOnline, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
result := th.App.ShouldSendPushNotification(botUser, channelNotifyProps, true, status, post, false)
assert.False(t, result)
})
t.Run("should return true for regular user even when post author is a bot", func(t *testing.T) {
botId := model.NewId()
regularUser := &model.User{Id: model.NewId(), Email: "user@test.com", IsBot: false, NotifyProps: make(map[string]string)}
regularUser.NotifyProps[model.PushNotifyProp] = model.UserNotifyAll
post := &model.Post{UserId: botId, ChannelId: model.NewId()}
channelNotifyProps := map[string]string{model.PushNotifyProp: model.ChannelNotifyAll}
status := &model.Status{UserId: regularUser.Id, Status: model.StatusOnline, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
result := th.App.ShouldSendPushNotification(regularUser, channelNotifyProps, true, status, post, false)
assert.True(t, result)
})
}
// testPushNotificationHandler is an HTTP handler to record push notifications