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 удалений

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

@@ -171,6 +171,18 @@ func (a *App) forEachPersistentNotificationPost(posts []*model.Post, fn func(pos
}
profileMap := channelProfileMap[channel.Id]
// Ensure the sender is always in the profile map: for example, system admins can post
// without being a member.
if _, ok := profileMap[post.UserId]; !ok {
var sender *model.User
sender, err = a.Srv().Store().User().Get(context.Background(), post.UserId)
if err != nil {
return errors.Wrapf(err, "failed to get profile for sender user %s for post %s", post.UserId, post.Id)
}
profileMap[post.UserId] = sender
}
mentions := &MentionResults{}
// In DMs, only the "other" user can be mentioned
if channel.Type == model.ChannelTypeDirect {
@@ -229,15 +241,12 @@ func (a *App) persistentNotificationsAuxiliaryData(channelsMap map[string]*model
}
channelKeywords[c.Id] = make(MentionKeywords, len(profileMap))
validProfileMap := make(map[string]*model.User, len(profileMap))
for userID, user := range profileMap {
if user.IsBot {
continue
if !user.IsBot {
channelKeywords[c.Id].AddUserKeyword(userID, "@"+user.Username)
}
validProfileMap[userID] = user
channelKeywords[c.Id].AddUserKeyword(userID, "@"+user.Username)
}
channelProfileMap[c.Id] = validProfileMap
channelProfileMap[c.Id] = profileMap
}
return channelGroupMap, channelProfileMap, channelKeywords, channelNotifyProps, nil
}