diff --git a/sql/updates/2024-10-26-warnings.xml b/sql/updates/2024-10-26-warnings.xml index da50a0f2d..961571eb3 100644 --- a/sql/updates/2024-10-26-warnings.xml +++ b/sql/updates/2024-10-26-warnings.xml @@ -111,4 +111,10 @@ + + + + alter type warning_type add value if not exists 'group' + + diff --git a/src/main/scala/ru/org/linux/warning/Warning.scala b/src/main/scala/ru/org/linux/warning/Warning.scala index e28c656dc..a81a80fde 100644 --- a/src/main/scala/ru/org/linux/warning/Warning.scala +++ b/src/main/scala/ru/org/linux/warning/Warning.scala @@ -32,7 +32,7 @@ sealed trait WarningType { } object WarningType { - private val AllTypes = Seq(RuleWarning, TagsWarning, SpellingWarning) + private val AllTypes = Seq(RuleWarning, TagsWarning, SpellingWarning, GroupWarning) val idToType: Map[String, WarningType] = AllTypes.map(t => t.id -> t).toMap } @@ -51,6 +51,11 @@ object SpellingWarning extends WarningType { override def name: String = "Опечатка или форматирование" } +object GroupWarning extends WarningType { + override def id: String = "group" + override def name: String = "Некорректная группа или раздел" +} + case class Warning(id: Int, topicId: Int, commentId: Option[Int], postdate: Instant, authorId: Int, message: String, warningType: WarningType, closedBy: Option[Int], closedWhen: Option[Instant]) diff --git a/src/main/scala/ru/org/linux/warning/WarningController.scala b/src/main/scala/ru/org/linux/warning/WarningController.scala index 364fead6d..41cf3fb7b 100644 --- a/src/main/scala/ru/org/linux/warning/WarningController.scala +++ b/src/main/scala/ru/org/linux/warning/WarningController.scala @@ -62,9 +62,9 @@ class WarningController(warningService: WarningService, topicDao: TopicDao, comm Seq(RuleWarning) } else { if (group.isPremoderated) { - Seq(RuleWarning, SpellingWarning, TagsWarning) + Seq(RuleWarning, SpellingWarning, TagsWarning, GroupWarning) } else { - Seq(RuleWarning, TagsWarning) + Seq(RuleWarning, TagsWarning, GroupWarning) } } } diff --git a/src/main/scala/ru/org/linux/warning/WarningService.scala b/src/main/scala/ru/org/linux/warning/WarningService.scala index 69263a4c6..cebc0e264 100644 --- a/src/main/scala/ru/org/linux/warning/WarningService.scala +++ b/src/main/scala/ru/org/linux/warning/WarningService.scala @@ -35,7 +35,7 @@ class WarningService(warningDao: WarningDao, eventService: UserEventService, use def postWarning(topic: Topic, comment: Option[Comment], author: User, message: String, warningType: WarningType): Unit = transactional() { _ => val notifyList = warningType match { - case RuleWarning => + case RuleWarning | GroupWarning => userService.getModerators.filter(_._2).map(_._1) case TagsWarning | SpellingWarning => (userService.getModerators.filter(_._2).map(_._1) ++ userService.getCorrectors.filter(_._2).map(_._1)).distinct