complete modlog implementation

This commit is contained in:
Thibault Duplessis 2012-07-21 18:32:10 +02:00
parent d9be9c4db0
commit eb195ebddb
9 changed files with 64 additions and 15 deletions

View file

@ -12,6 +12,7 @@ import scalaz.effects._
object Mod extends LilaController {
def modApi = env.mod.api
def modLogApi = env.mod.logApi
def engine(username: String) = Secure(Permission.MarkEngine) { _
me
@ -33,4 +34,9 @@ object Mod extends LilaController {
modApi.ipban(me, username) map { _ routes.User show username }
}
}
val log = Auth { implicit ctx
me =>
IOk(modLogApi.recent map { html.mod.log(_) })
}
}

View file

@ -7,17 +7,25 @@ import org.joda.time.DateTime
import org.scala_tools.time.Imports._
case class Modlog(
mod: String,
user: Option[String],
action: String,
date: DateTime = DateTime.now)
mod: String,
user: Option[String],
action: String,
date: DateTime = DateTime.now) {
def showAction = action match {
case Modlog.engine "mark as engine"
case Modlog.unengine "un-mark as engine"
case Modlog.deletePost "delete forum post"
case a a
}
}
object Modlog {
val engine = "engine"
val unengine = "un-engine"
val unengine = "unengine"
val mute = "mute"
val unmute = "un-mute"
val unmute = "unmute"
val ipban = "ipban"
val deletePost = "remove post"
val deletePost = "deletePost"
}

View file

@ -19,5 +19,7 @@ final class ModlogApi(repo: ModlogRepo) {
Modlog(mod.id, user.id.some, Modlog.ipban)
}
def recent = repo recent 200
private def add(modLog: Modlog): IO[Unit] = repo saveIO modLog
}

View file

@ -15,4 +15,8 @@ class ModlogRepo(collection: MongoCollection)
def saveIO(modlog: Modlog): IO[Unit] = io {
save(modlog)
}
def recent(nb: Int): IO[List[Modlog]] = io {
find(DBObject()).sort(DBObject("$natural" -> -1)).limit(nb).toList
}
}

View file

@ -5,17 +5,11 @@
@base.layout(title = title) {
<style type="text/css">
table td {
padding: 5px 10px 5px 10px;
}
table tr:nth-child(odd) {
background: #f7f7f7;
}
</style>
<div class="content_box">
<h1>@title</h1>
<br /><br />
<table><tbody>
<table class="datatable"><tbody>
@messages.map { message =>
<tr>
<td>@showDate(message.createdAt)</td>

View file

@ -0,0 +1,26 @@
@(logs: List[lila.mod.Modlog])(implicit ctx: Context)
@title = @{ "Mod logs" }
@base.layout(title = title) {
<style type="text/css">
table td {
padding: 5px 10px 5px 10px;
}
</style>
<div class="content_box">
<h1>@title</h1>
<br /><br />
<table class="datatable"><tbody>
@logs.map { log =>
<tr>
<td>@showDate(log.date)</td>
<td>@userIdLink(log.mod.some)</td>
<td>@log.showAction.capitalize</td>
<td>@userIdLink(log.user)</td>
</tr>
}
</tbody></table>
</div>
}

View file

@ -88,6 +88,7 @@ POST /account/closeConfirm controllers.User.closeConfirm
POST /mod/:username/engine controllers.Mod.engine(username: String)
POST /mod/:username/mute controllers.Mod.mute(username: String)
POST /mod/:username/ban controllers.Mod.ban(username: String)
GET /mod/log controllers.Mod.log
# Wiki
GET /wiki controllers.Wiki.home

View file

@ -195,6 +195,13 @@ div.content_box .lichess_title {
margin-bottom: 0.5em;
}
div.content_box table.datatable td {
padding: 5px 10px 5px 10px;
}
div.content_box table.datatable tr:nth-child(odd) {
background: #f7f7f7;
}
div.lichess_goodies div.box {
margin-top: 1em;
margin-left: -30px;

View file

@ -203,7 +203,8 @@ body.dark div.user_show .elo_with_me,
body.dark div.content_box_inter,
body.dark #GameText tr:nth-child(even),
body.dark table.translations tbody tr:nth-child(even),
body.dark form.translation_form div.message:nth-child(even)
body.dark form.translation_form div.message:nth-child(even),
body.dark div.content_box table.datatable tr:nth-child(odd)
{
background: #343434;
}