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
|
|
|
|
|
|
|
import play.api.mvc._
|
|
|
|
import play.api.mvc.Results._
|
|
|
|
|
|
|
|
object Mod extends LilaController {
|
|
|
|
|
2013-05-06 10:41:02 -06:00
|
|
|
private def modApi = Env.mod.api
|
|
|
|
private def modLogApi = Env.mod.logApi
|
2013-05-06 08:51:19 -06:00
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def engine(username: String) = Secure(_.MarkEngine) { _ =>
|
|
|
|
me => modApi.adjust(me.id, username) inject redirect(username)
|
2013-05-10 03:56:34 -06:00
|
|
|
}
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def troll(username: String) = Secure(_.MarkTroll) { _ =>
|
|
|
|
me =>
|
2014-01-16 01:46:01 -07:00
|
|
|
modApi.troll(me.id, username) inject 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 =>
|
|
|
|
me => modApi.closeAccount(me.id, 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 {
|
2014-06-10 02:27:29 -06:00
|
|
|
isReported <- Env.report.api recent 100 map {
|
2014-05-22 13:01:54 -06:00
|
|
|
_ exists (r => r.user == user.id && r.isCommunication)
|
|
|
|
}
|
|
|
|
povs <- isReported ?? lila.game.GameRepo.recentPovsByUser(user, 50)
|
|
|
|
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
|
|
|
|
threads <- isReported ?? {
|
|
|
|
lila.message.ThreadRepo.visibleByUser(user.id, 50) map {
|
|
|
|
_ filter (_ hasPostsWrittenBy user.id) take 9
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} yield html.mod.communication(user, isReported, povWithChats, threads)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def redirect(username: String, mod: Boolean = true) =
|
2014-02-26 17:18:09 -07:00
|
|
|
Redirect(routes.User.show(username).url + mod.??("?mod"))
|
2013-05-06 08:51:19 -06:00
|
|
|
}
|