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 =>
|
||||
ModExternalBot {
|
||||
OptionFuResult(UserRepo named username) { user =>
|
||||
Env.mod.jsonView(user) map {
|
||||
case None => NotFound
|
||||
case Some(data) => Ok(data)
|
||||
Env.mod.jsonView(user) flatMap {
|
||||
case None => NotFound.fuccess
|
||||
case Some(data) => Env.mod.userHistory(user) map { history =>
|
||||
Ok(data + ("history" -> history))
|
||||
}
|
||||
} map (_ as JSON)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ final class Env(
|
|||
system: ActorSystem,
|
||||
scheduler: lila.common.Scheduler,
|
||||
firewall: Firewall,
|
||||
reportColl: Coll,
|
||||
reportApi: lila.report.ReportApi,
|
||||
lightUserApi: lila.user.LightUserApi,
|
||||
userSpy: String => Fu[UserSpy],
|
||||
securityApi: lila.security.Api,
|
||||
|
@ -42,7 +42,7 @@ final class Env(
|
|||
|
||||
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(
|
||||
scheduler = scheduler,
|
||||
|
@ -77,7 +77,7 @@ final class Env(
|
|||
|
||||
lazy val gamify = new Gamify(
|
||||
logColl = logColl,
|
||||
reportColl = reportColl,
|
||||
reportApi = reportApi,
|
||||
historyColl = db(CollectionGamingHistory))
|
||||
|
||||
lazy val publicChat = new PublicChat(chatApi, tournamentApi, simulEnv)
|
||||
|
@ -89,6 +89,10 @@ final class Env(
|
|||
lazy val jsonView = new JsonView(
|
||||
assessApi = assessApi)
|
||||
|
||||
lazy val userHistory = new UserHistory(
|
||||
logApi = logApi,
|
||||
reportApi = reportApi)
|
||||
|
||||
// api actor
|
||||
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
|
@ -114,7 +118,7 @@ object Env {
|
|||
system = lila.common.PlayApp.system,
|
||||
scheduler = lila.common.PlayApp.scheduler,
|
||||
firewall = lila.security.Env.current.firewall,
|
||||
reportColl = lila.report.Env.current.reportColl,
|
||||
reportApi = lila.report.Env.current.api,
|
||||
userSpy = lila.security.Env.current.userSpy,
|
||||
lightUserApi = lila.user.Env.current.lightUserApi,
|
||||
securityApi = lila.security.Env.current.api,
|
||||
|
|
|
@ -11,7 +11,7 @@ import lila.memo.AsyncCache
|
|||
|
||||
final class Gamify(
|
||||
logColl: Coll,
|
||||
reportColl: Coll,
|
||||
reportApi: lila.report.ReportApi,
|
||||
historyColl: Coll) {
|
||||
|
||||
import Gamify._
|
||||
|
@ -90,7 +90,7 @@ final class Gamify(
|
|||
}
|
||||
|
||||
private def reportLeaderboard(after: DateTime, before: Option[DateTime]): Fu[List[ModCount]] =
|
||||
reportColl.aggregate(
|
||||
reportApi.coll.aggregate(
|
||||
Match($doc(
|
||||
"createdAt" -> dateRange(after, before),
|
||||
"processedBy" -> notLichess
|
||||
|
|
|
@ -53,3 +53,8 @@ final class JsonView(assessApi: AssessApi) {
|
|||
).noNull
|
||||
}
|
||||
}
|
||||
|
||||
object JsonView {
|
||||
|
||||
private[mod] implicit val modlogWrites: Writes[Modlog] = Json.writes[Modlog]
|
||||
}
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
package lila.mod
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.notify.{ Notification, NotifyApi }
|
||||
import lila.user.User
|
||||
|
||||
private final class ModNotifier(
|
||||
notifyApi: NotifyApi,
|
||||
reportColl: Coll) {
|
||||
reportApi: lila.report.ReportApi) {
|
||||
|
||||
def reporters(user: User): Funit =
|
||||
reportColl.distinct[String, List]("createdBy", $doc(
|
||||
"user" -> user.id,
|
||||
"createdAt" -> $gt(DateTime.now minusDays 3),
|
||||
"createdBy" -> $ne("lichess")
|
||||
).some) flatMap {
|
||||
reportApi.recentReportersOf(user) flatMap {
|
||||
_.map { reporterId =>
|
||||
notifyApi.addNotification(Notification.make(
|
||||
notifies = Notification.Notifies(reporterId),
|
||||
|
|
|
@ -103,7 +103,7 @@ final class ModlogApi(coll: Coll) {
|
|||
))
|
||||
|
||||
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 = {
|
||||
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.user.{ User, UserRepo, NoteApi }
|
||||
|
||||
private[report] final class ReportApi(
|
||||
coll: Coll,
|
||||
final class ReportApi(
|
||||
val coll: Coll,
|
||||
noteApi: NoteApi,
|
||||
isOnline: User.ID => Boolean) {
|
||||
|
||||
|
@ -153,8 +153,18 @@ private[report] final class ReportApi(
|
|||
|
||||
def nbUnprocessed = coll.countSel(unprocessedSelect)
|
||||
|
||||
def recent(nb: Int) =
|
||||
coll.find($empty).sort($sort.createdDesc).cursor[Report]().gather[List](nb)
|
||||
def recent(nb: Int): Fu[List[Report]] =
|
||||
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]] =
|
||||
recentUnprocessed(nb * 2) |+| recentProcessed(nb) flatMap { all =>
|
||||
|
|
Loading…
Reference in New Issue