discard puzzle theme flood

pull/7776/head
Thibault Duplessis 2020-12-23 13:00:13 +01:00
parent 9c1f0cd669
commit fe3ee253d0
2 changed files with 6 additions and 1 deletions

View File

@ -106,7 +106,8 @@ final class PuzzleApi(
round.themeVote(theme, vote) ?? { newThemes =>
import PuzzleRound.{ BSONFields => F }
val update =
if (newThemes.isEmpty) fuccess($unset(F.themes, F.puzzle).some)
if (newThemes.isEmpty || !PuzzleRound.themesLookSane(newThemes))
fuccess($unset(F.themes, F.puzzle).some)
else
vote match {
case None =>

View File

@ -47,6 +47,10 @@ object PuzzleRound {
case class Theme(theme: PuzzleTheme.Key, vote: Boolean)
// max 7 theme upvotes
// unlimited downvotes
def themesLookSane(themes: List[Theme]): Boolean = themes.count(_.vote) < 8
object BSONFields {
val id = "_id"
val win = "w"