2013-05-06 08:51:19 -06:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import lila.app._
|
|
|
|
import lila.security.Permission
|
2013-05-16 16:00:28 -06:00
|
|
|
import lila.user.UserRepo
|
2014-02-26 17:18:09 -07:00
|
|
|
import views._
|
2013-05-06 08:51:19 -06:00
|
|
|
|
2015-01-23 01:13:56 -07:00
|
|
|
import org.joda.time.DateTime
|
2013-05-06 08:51:19 -06:00
|
|
|
import play.api.mvc._
|
|
|
|
import play.api.mvc.Results._
|
|
|
|
|
2015-01-17 04:12:34 -07:00
|
|
|
import lila.evaluation.{ PlayerAssessment }
|
2015-01-15 04:15:28 -07:00
|
|
|
|
2015-01-19 08:07:02 -07:00
|
|
|
import chess.Color
|
|
|
|
|
2013-05-06 08:51:19 -06:00
|
|
|
object Mod extends LilaController {
|
|
|
|
|
2013-05-06 10:41:02 -06:00
|
|
|
private def modApi = Env.mod.api
|
|
|
|
private def modLogApi = Env.mod.logApi
|
2015-01-15 04:15:28 -07:00
|
|
|
private def assessApi = Env.mod.assessApi
|
2013-05-06 08:51:19 -06:00
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def engine(username: String) = Secure(_.MarkEngine) { _ =>
|
2015-02-24 03:43:09 -07:00
|
|
|
me => modApi.toggleEngine(me.id, username) inject redirect(username)
|
2013-05-10 03:56:34 -06:00
|
|
|
}
|
|
|
|
|
2015-02-13 07:14:39 -07:00
|
|
|
def booster(username: String) = Secure(_.MarkBooster) { _ =>
|
2015-02-24 03:43:09 -07:00
|
|
|
me => modApi.toggleBooster(me.id, username) inject redirect(username)
|
2015-02-13 07:14:39 -07:00
|
|
|
}
|
|
|
|
|
2015-07-01 03:15:54 -06:00
|
|
|
def troll(username: String) = Secure(_.MarkTroll) { implicit ctx =>
|
2014-02-17 02:12:19 -07:00
|
|
|
me =>
|
2015-07-08 03:53:56 -06:00
|
|
|
modApi.troll(me.id, username, getBool("set")) inject {
|
2015-07-01 03:15:54 -06:00
|
|
|
get("then") match {
|
|
|
|
case Some("reports") => Redirect(routes.Report.list)
|
|
|
|
case _ => redirect(username)
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 03:56:34 -06:00
|
|
|
}
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def ban(username: String) = Secure(_.IpBan) { implicit ctx =>
|
|
|
|
me => modApi.ban(me.id, username) inject redirect(username)
|
2013-05-10 03:56:34 -06:00
|
|
|
}
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def ipban(ip: String) = Secure(_.IpBan) { implicit ctx =>
|
|
|
|
me => modApi.ipban(me.id, ip)
|
2013-05-06 10:41:02 -06:00
|
|
|
}
|
2013-05-06 08:51:19 -06:00
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def closeAccount(username: String) = Secure(_.CloseAccount) { implicit ctx =>
|
2015-07-04 02:23:02 -06:00
|
|
|
me => modApi.closeAccount(me.id, username) >>
|
|
|
|
Env.relation.api.unfollowAll(lila.user.User normalize username) inject redirect(username)
|
2014-02-01 06:13:22 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def reopenAccount(username: String) = Secure(_.ReopenAccount) { implicit ctx =>
|
|
|
|
me => modApi.reopenAccount(me.id, username) inject redirect(username)
|
2013-09-11 04:38:16 -06:00
|
|
|
}
|
|
|
|
|
2014-02-26 17:18:09 -07:00
|
|
|
def setTitle(username: String) = AuthBody { implicit ctx =>
|
|
|
|
me =>
|
|
|
|
implicit def req = ctx.body
|
|
|
|
if (isGranted(_.SetTitle))
|
|
|
|
lila.user.DataForm.title.bindFromRequest.fold(
|
|
|
|
err => fuccess(Redirect(routes.User.show(username))),
|
|
|
|
title => modApi.setTitle(me.id, username, title) inject redirect(username, false)
|
|
|
|
)
|
|
|
|
else fuccess(authorizationFailed(ctx.req))
|
|
|
|
}
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def log = Auth { implicit ctx =>
|
|
|
|
me => modLogApi.recent map { html.mod.log(_) }
|
2013-05-10 03:56:34 -06:00
|
|
|
}
|
2014-01-16 01:46:01 -07:00
|
|
|
|
2014-05-22 13:01:54 -06:00
|
|
|
def communication(username: String) = Secure(_.MarkTroll) { implicit ctx =>
|
|
|
|
me =>
|
|
|
|
OptionFuOk(UserRepo named username) { user =>
|
|
|
|
for {
|
2015-06-29 10:20:21 -06:00
|
|
|
povs <- lila.game.GameRepo.recentPovsByUser(user, 100)
|
2014-05-22 13:01:54 -06:00
|
|
|
chats <- povs.map(p => Env.chat.api.playerChat findNonEmpty p.gameId).sequence
|
|
|
|
povWithChats = (povs zip chats) collect {
|
|
|
|
case (p, Some(c)) => p -> c
|
|
|
|
} take 9
|
2015-05-29 05:09:30 -06:00
|
|
|
threads <- {
|
2014-05-22 13:01:54 -06:00
|
|
|
lila.message.ThreadRepo.visibleByUser(user.id, 50) map {
|
|
|
|
_ filter (_ hasPostsWrittenBy user.id) take 9
|
|
|
|
}
|
|
|
|
}
|
2015-07-01 04:22:06 -06:00
|
|
|
publicLines <- Env.shutup.api getPublicLines user.id
|
|
|
|
} yield html.mod.communication(user, povWithChats, threads, publicLines)
|
2014-05-22 13:01:54 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-13 03:44:12 -07:00
|
|
|
def redirect(username: String, mod: Boolean = true) = Redirect(routes.User.show(username).url + mod.??("?mod"))
|
|
|
|
|
2015-02-22 23:12:25 -07:00
|
|
|
def refreshUserAssess(username: String) = Secure(_.MarkEngine) { implicit ctx =>
|
|
|
|
me => assessApi.refreshAssessByUsername(username) inject redirect(username)
|
|
|
|
}
|
2013-05-06 08:51:19 -06:00
|
|
|
}
|