add user moderation history to assessment endpoint
parent
5aeb80cadc
commit
5147fa8347
|
@ -96,9 +96,11 @@ object Mod extends LilaController {
|
||||||
def assessment(username: String) = Open { implicit ctx =>
|
def assessment(username: String) = Open { implicit ctx =>
|
||||||
ModExternalBot {
|
ModExternalBot {
|
||||||
OptionFuResult(UserRepo named username) { user =>
|
OptionFuResult(UserRepo named username) { user =>
|
||||||
Env.mod.jsonView(user) map {
|
Env.mod.jsonView(user) flatMap {
|
||||||
case None => NotFound
|
case None => NotFound.fuccess
|
||||||
case Some(data) => Ok(data)
|
case Some(data) => Env.mod.userHistory(user) map { history =>
|
||||||
|
Ok(data + ("history" -> history))
|
||||||
|
}
|
||||||
} map (_ as JSON)
|
} map (_ as JSON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ final class Env(
|
||||||
system: ActorSystem,
|
system: ActorSystem,
|
||||||
scheduler: lila.common.Scheduler,
|
scheduler: lila.common.Scheduler,
|
||||||
firewall: Firewall,
|
firewall: Firewall,
|
||||||
reportColl: Coll,
|
reportApi: lila.report.ReportApi,
|
||||||
lightUserApi: lila.user.LightUserApi,
|
lightUserApi: lila.user.LightUserApi,
|
||||||
userSpy: String => Fu[UserSpy],
|
userSpy: String => Fu[UserSpy],
|
||||||
securityApi: lila.security.Api,
|
securityApi: lila.security.Api,
|
||||||
|
@ -42,7 +42,7 @@ final class Env(
|
||||||
|
|
||||||
lazy val logApi = new ModlogApi(logColl)
|
lazy val logApi = new ModlogApi(logColl)
|
||||||
|
|
||||||
private lazy val notifier = new ModNotifier(notifyApi, reportColl)
|
private lazy val notifier = new ModNotifier(notifyApi, reportApi)
|
||||||
|
|
||||||
private lazy val ratingRefund = new RatingRefund(
|
private lazy val ratingRefund = new RatingRefund(
|
||||||
scheduler = scheduler,
|
scheduler = scheduler,
|
||||||
|
@ -77,7 +77,7 @@ final class Env(
|
||||||
|
|
||||||
lazy val gamify = new Gamify(
|
lazy val gamify = new Gamify(
|
||||||
logColl = logColl,
|
logColl = logColl,
|
||||||
reportColl = reportColl,
|
reportApi = reportApi,
|
||||||
historyColl = db(CollectionGamingHistory))
|
historyColl = db(CollectionGamingHistory))
|
||||||
|
|
||||||
lazy val publicChat = new PublicChat(chatApi, tournamentApi, simulEnv)
|
lazy val publicChat = new PublicChat(chatApi, tournamentApi, simulEnv)
|
||||||
|
@ -89,6 +89,10 @@ final class Env(
|
||||||
lazy val jsonView = new JsonView(
|
lazy val jsonView = new JsonView(
|
||||||
assessApi = assessApi)
|
assessApi = assessApi)
|
||||||
|
|
||||||
|
lazy val userHistory = new UserHistory(
|
||||||
|
logApi = logApi,
|
||||||
|
reportApi = reportApi)
|
||||||
|
|
||||||
// api actor
|
// api actor
|
||||||
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
|
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
|
||||||
def receive = {
|
def receive = {
|
||||||
|
@ -114,7 +118,7 @@ object Env {
|
||||||
system = lila.common.PlayApp.system,
|
system = lila.common.PlayApp.system,
|
||||||
scheduler = lila.common.PlayApp.scheduler,
|
scheduler = lila.common.PlayApp.scheduler,
|
||||||
firewall = lila.security.Env.current.firewall,
|
firewall = lila.security.Env.current.firewall,
|
||||||
reportColl = lila.report.Env.current.reportColl,
|
reportApi = lila.report.Env.current.api,
|
||||||
userSpy = lila.security.Env.current.userSpy,
|
userSpy = lila.security.Env.current.userSpy,
|
||||||
lightUserApi = lila.user.Env.current.lightUserApi,
|
lightUserApi = lila.user.Env.current.lightUserApi,
|
||||||
securityApi = lila.security.Env.current.api,
|
securityApi = lila.security.Env.current.api,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import lila.memo.AsyncCache
|
||||||
|
|
||||||
final class Gamify(
|
final class Gamify(
|
||||||
logColl: Coll,
|
logColl: Coll,
|
||||||
reportColl: Coll,
|
reportApi: lila.report.ReportApi,
|
||||||
historyColl: Coll) {
|
historyColl: Coll) {
|
||||||
|
|
||||||
import Gamify._
|
import Gamify._
|
||||||
|
@ -90,7 +90,7 @@ final class Gamify(
|
||||||
}
|
}
|
||||||
|
|
||||||
private def reportLeaderboard(after: DateTime, before: Option[DateTime]): Fu[List[ModCount]] =
|
private def reportLeaderboard(after: DateTime, before: Option[DateTime]): Fu[List[ModCount]] =
|
||||||
reportColl.aggregate(
|
reportApi.coll.aggregate(
|
||||||
Match($doc(
|
Match($doc(
|
||||||
"createdAt" -> dateRange(after, before),
|
"createdAt" -> dateRange(after, before),
|
||||||
"processedBy" -> notLichess
|
"processedBy" -> notLichess
|
||||||
|
|
|
@ -53,3 +53,8 @@ final class JsonView(assessApi: AssessApi) {
|
||||||
).noNull
|
).noNull
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object JsonView {
|
||||||
|
|
||||||
|
private[mod] implicit val modlogWrites: Writes[Modlog] = Json.writes[Modlog]
|
||||||
|
}
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
package lila.mod
|
package lila.mod
|
||||||
|
|
||||||
import org.joda.time.DateTime
|
|
||||||
|
|
||||||
import lila.db.dsl._
|
|
||||||
import lila.notify.{ Notification, NotifyApi }
|
import lila.notify.{ Notification, NotifyApi }
|
||||||
import lila.user.User
|
import lila.user.User
|
||||||
|
|
||||||
private final class ModNotifier(
|
private final class ModNotifier(
|
||||||
notifyApi: NotifyApi,
|
notifyApi: NotifyApi,
|
||||||
reportColl: Coll) {
|
reportApi: lila.report.ReportApi) {
|
||||||
|
|
||||||
def reporters(user: User): Funit =
|
def reporters(user: User): Funit =
|
||||||
reportColl.distinct[String, List]("createdBy", $doc(
|
reportApi.recentReportersOf(user) flatMap {
|
||||||
"user" -> user.id,
|
|
||||||
"createdAt" -> $gt(DateTime.now minusDays 3),
|
|
||||||
"createdBy" -> $ne("lichess")
|
|
||||||
).some) flatMap {
|
|
||||||
_.map { reporterId =>
|
_.map { reporterId =>
|
||||||
notifyApi.addNotification(Notification.make(
|
notifyApi.addNotification(Notification.make(
|
||||||
notifies = Notification.Notifies(reporterId),
|
notifies = Notification.Notifies(reporterId),
|
||||||
|
|
|
@ -103,7 +103,7 @@ final class ModlogApi(coll: Coll) {
|
||||||
))
|
))
|
||||||
|
|
||||||
def userHistory(userId: String): Fu[List[Modlog]] =
|
def userHistory(userId: String): Fu[List[Modlog]] =
|
||||||
coll.find($doc("user" -> userId)).sort($sort desc "date").cursor[Modlog]().gather[List](100)
|
coll.find($doc("user" -> userId)).sort($sort desc "date").cursor[Modlog]().gather[List](30)
|
||||||
|
|
||||||
private def add(m: Modlog): Funit = {
|
private def add(m: Modlog): Funit = {
|
||||||
lila.mon.mod.log.create()
|
lila.mon.mod.log.create()
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package lila.mod
|
||||||
|
|
||||||
|
import play.api.libs.json._
|
||||||
|
|
||||||
|
import lila.report.Report
|
||||||
|
import lila.user.User
|
||||||
|
|
||||||
|
final class UserHistory(
|
||||||
|
logApi: ModlogApi,
|
||||||
|
reportApi: lila.report.ReportApi) {
|
||||||
|
|
||||||
|
import JsonView.modlogWrites
|
||||||
|
import lila.report.JsonView.reportWrites
|
||||||
|
|
||||||
|
def apply(user: User): Fu[JsArray] = for {
|
||||||
|
logs <- logApi.userHistory(user.id)
|
||||||
|
reports <- reportApi.recent(user, 15)
|
||||||
|
} yield {
|
||||||
|
val all: List[Either[Modlog, Report]] = logs.map(Left.apply) ::: reports.map(Right.apply)
|
||||||
|
val sorted = all.sortBy {
|
||||||
|
case Left(log) => -log.date.getMillis
|
||||||
|
case Right(rep) => -rep.createdAt.getMillis
|
||||||
|
}
|
||||||
|
JsArray {
|
||||||
|
sorted map {
|
||||||
|
case Left(log) => Json.obj(
|
||||||
|
"type" -> "modAction",
|
||||||
|
"data" -> (modlogWrites writes log))
|
||||||
|
case Right(rep) => Json.obj(
|
||||||
|
"type" -> "report",
|
||||||
|
"data" -> (reportWrites writes rep))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package lila.report
|
||||||
|
|
||||||
|
import play.api.libs.json._
|
||||||
|
|
||||||
|
object JsonView {
|
||||||
|
|
||||||
|
implicit val reportWrites: Writes[Report] = Json.writes[Report]
|
||||||
|
}
|
|
@ -6,8 +6,8 @@ import org.joda.time.DateTime
|
||||||
import lila.db.dsl._
|
import lila.db.dsl._
|
||||||
import lila.user.{ User, UserRepo, NoteApi }
|
import lila.user.{ User, UserRepo, NoteApi }
|
||||||
|
|
||||||
private[report] final class ReportApi(
|
final class ReportApi(
|
||||||
coll: Coll,
|
val coll: Coll,
|
||||||
noteApi: NoteApi,
|
noteApi: NoteApi,
|
||||||
isOnline: User.ID => Boolean) {
|
isOnline: User.ID => Boolean) {
|
||||||
|
|
||||||
|
@ -153,8 +153,18 @@ private[report] final class ReportApi(
|
||||||
|
|
||||||
def nbUnprocessed = coll.countSel(unprocessedSelect)
|
def nbUnprocessed = coll.countSel(unprocessedSelect)
|
||||||
|
|
||||||
def recent(nb: Int) =
|
def recent(nb: Int): Fu[List[Report]] =
|
||||||
coll.find($empty).sort($sort.createdDesc).cursor[Report]().gather[List](nb)
|
coll.find($empty).sort($sort.createdDesc).list[Report](nb)
|
||||||
|
|
||||||
|
def recent(user: User, nb: Int): Fu[List[Report]] =
|
||||||
|
coll.find($doc("user" -> user.id)).sort($sort.createdDesc).list[Report](nb)
|
||||||
|
|
||||||
|
def recentReportersOf(user: User): Fu[List[User.ID]] =
|
||||||
|
coll.distinct[String, List]("createdBy", $doc(
|
||||||
|
"user" -> user.id,
|
||||||
|
"createdAt" -> $gt(DateTime.now minusDays 3),
|
||||||
|
"createdBy" -> $ne("lichess")
|
||||||
|
).some)
|
||||||
|
|
||||||
def unprocessedAndRecent(nb: Int): Fu[List[Report.WithUserAndNotes]] =
|
def unprocessedAndRecent(nb: Int): Fu[List[Report.WithUserAndNotes]] =
|
||||||
recentUnprocessed(nb * 2) |+| recentProcessed(nb) flatMap { all =>
|
recentUnprocessed(nb * 2) |+| recentProcessed(nb) flatMap { all =>
|
||||||
|
|
Loading…
Reference in New Issue