lila/app/controllers/Report.scala

81 lines
2.2 KiB
Scala
Raw Normal View History

package controllers
import play.api.mvc._
2014-06-01 15:22:17 -06:00
import play.twirl.api.Html
import views._
import lila.app._
import lila.security.Granter
2014-02-17 02:12:19 -07:00
import lila.user.{ User => UserModel, UserRepo }
object Report extends LilaController {
private def forms = Env.report.forms
private def api = Env.report.api
2016-10-19 08:55:32 -06:00
def list = Secure(_.SeeReport) { implicit ctx => _ =>
api unprocessedAndRecent 200 map { reports =>
2013-07-27 14:55:29 -06:00
html.report.list(reports)
}
}
def listWithFilter(reason: String) = Secure(_.SeeReport) { implicit ctx => _ =>
api unprocessedAndRecentWithFilter(200, reason) map { reports =>
html.report.list(reports)
}
}
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 =>
forms.createWithCaptcha map {
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
forms.create.bindFromRequest.fold(
err => get("username") ?? UserRepo.named flatMap { user =>
forms.anyCaptcha map { captcha =>
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 {
api unprocessedAndRecent 100 map { all =>
2016-10-19 08:55:32 -06:00
all.find { r =>
2016-12-19 13:02:33 -07:00
r.report.isCheat && r.report.unprocessed && !r.hasIrwinNote &&
2016-12-19 12:49:47 -07:00
!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
}
}
}