lila/app/controllers/Report.scala

84 lines
2.4 KiB
Scala
Raw Normal View History

package controllers
import views._
import lila.api.Context
import lila.app._
2017-01-08 11:41:22 -07:00
import lila.report.Reason
2017-01-15 05:26:08 -07:00
import lila.user.UserRepo
object Report extends LilaController {
private def env = Env.report
private def api = env.api
def list = Secure(_.SeeReport) { implicit ctx => me =>
renderList(env.modFilters.get(me).fold("all")(_.key))
}
def listWithFilter(reason: String) = Secure(_.SeeReport) { implicit ctx => me =>
env.modFilters.set(me, Reason(reason))
renderList(reason)
}
2013-07-27 14:55:29 -06:00
2017-03-30 09:17:02 -06:00
private def renderList(reason: String)(implicit ctx: Context) =
api.unprocessedAndRecentWithFilter(50, Reason(reason)) zip
api.countUnprocesssedByReasons flatMap {
case reports ~ counts =>
(Env.user.lightUserApi preloadMany reports.flatMap(_.userIds)) inject
Ok(html.report.list(reports, reason, counts))
}
2016-10-19 08:55:32 -06:00
def process(id: String) = Secure(_.SeeReport) { implicit ctx => me =>
api.process(id, me) inject Redirect(routes.Report.list)
2013-07-27 14:55:29 -06:00
}
2016-10-19 08:55:32 -06:00
def form = Auth { implicit ctx => implicit me =>
NotForKids {
get("username") ?? UserRepo.named flatMap { user =>
env.forms.createWithCaptcha map {
2016-10-19 08:55:32 -06:00
case (form, captcha) => Ok(html.report.form(form, user, captcha))
}
}
2016-10-19 08:55:32 -06:00
}
}
2016-10-19 08:55:32 -06:00
def create = AuthBody { implicit ctx => implicit me =>
implicit val req = ctx.body
env.forms.create.bindFromRequest.fold(
2016-10-19 08:55:32 -06:00
err => get("username") ?? UserRepo.named flatMap { user =>
env.forms.anyCaptcha map { captcha =>
2016-10-19 08:55:32 -06:00
BadRequest(html.report.form(err, user, captcha))
}
},
data => api.create(data, me) map { report =>
Redirect(routes.Report.thanks(data.user.username))
}
)
}
2016-10-19 08:55:32 -06:00
def thanks(reported: String) = Auth { implicit ctx => me =>
Env.relation.api.fetchBlocks(me.id, reported) map { blocked =>
html.report.thanks(reported, blocked)
}
}
2016-11-23 08:06:37 -07:00
import scala.concurrent.duration._
2016-12-19 12:49:47 -07:00
private lazy val irwinProcessedUserIds = new lila.memo.ExpireSetMemo(ttl = 30 minutes)
2016-11-23 08:06:37 -07:00
2016-12-19 12:49:47 -07:00
def irwinBotNext = Open { implicit ctx =>
2016-10-19 08:55:32 -06:00
Mod.ModExternalBot {
2017-01-08 11:41:22 -07:00
api.unprocessedAndRecentWithFilter(100, Reason.Cheat.some) map { all =>
2016-10-19 08:55:32 -06:00
all.find { r =>
2017-01-08 11:41:22 -07:00
r.report.unprocessed && !r.hasIrwinNote && !irwinProcessedUserIds.get(r.user.id)
2016-10-19 08:55:32 -06:00
} match {
2016-11-23 08:06:37 -07:00
case None => NotFound
case Some(r) =>
2016-12-19 12:49:47 -07:00
irwinProcessedUserIds put r.user.id
2016-11-23 08:06:37 -07:00
Ok(r.user.id)
2016-10-19 08:55:32 -06:00
}
}
2016-10-19 08:55:32 -06:00
}
}
}