[MM-55143] Disallow reacting with an emoji that does not exist, limit the total number of unique reactions per post (#25331)
* [MM-55143] Disallow reacting with an emoji that does not exist * WIP for server limit on emoji reactions * WIP * Implement default limit of 25 unique emoji reactions * Add modal for reaction limit * Fix test * PR feedback * Fix i18n * Update admin string * Merge'd * Fixing some issues, check limits correctly based on other users reactions * Fix typos * Fix lint/test * Add tests, fix other tests --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0a38042d58
Коммит
eaa5cce3ce
@@ -20,6 +20,30 @@ func (a *App) SaveReactionForPost(c request.CTX, reaction *model.Reaction) (*mod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Check whether this is a valid emoji
|
||||
if _, ok := model.GetSystemEmojiId(reaction.EmojiName); !ok {
|
||||
if _, emojiErr := a.GetEmojiByName(c, reaction.EmojiName); emojiErr != nil {
|
||||
return nil, emojiErr
|
||||
}
|
||||
}
|
||||
|
||||
existing, dErr := a.Srv().Store().Reaction().ExistsOnPost(reaction.PostId, reaction.EmojiName)
|
||||
if dErr != nil {
|
||||
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(dErr)
|
||||
}
|
||||
|
||||
// If it exists already, we don't need to check for the limit
|
||||
if !existing {
|
||||
count, dErr := a.Srv().Store().Reaction().GetUniqueCountForPost(reaction.PostId)
|
||||
if dErr != nil {
|
||||
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.app_error", nil, "", http.StatusInternalServerError).Wrap(dErr)
|
||||
}
|
||||
|
||||
if count >= *a.Config().ServiceSettings.UniqueEmojiReactionLimitPerPost {
|
||||
return nil, model.NewAppError("SaveReactionForPost", "app.reaction.save.save.too_many_reactions", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Ссылка в новой задаче
Block a user