log forum post deletions
This commit is contained in:
parent
b0a049725b
commit
be55e85c58
|
@ -38,7 +38,7 @@ object ForumPost extends LilaController with forum.Controller {
|
|||
}
|
||||
|
||||
def delete(id: String) = Secure(Permission.ModerateForum) { implicit ctx ⇒
|
||||
_ ⇒
|
||||
IOk(postApi delete id)
|
||||
me ⇒
|
||||
IOk(postApi.delete(id, me))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ final class CoreEnv private (application: Application, val settings: Settings) {
|
|||
settings = settings,
|
||||
captcha = site.captcha,
|
||||
mongodb = mongodb.apply _,
|
||||
userRepo = user.userRepo)
|
||||
userRepo = user.userRepo,
|
||||
modLog = mod.logApi)
|
||||
|
||||
lazy val message = new lila.message.MessageEnv(
|
||||
settings = settings,
|
||||
|
|
|
@ -4,6 +4,7 @@ package forum
|
|||
import user.{ User, UserRepo }
|
||||
import core.Settings
|
||||
import site.Captcha
|
||||
import mod.ModlogApi
|
||||
|
||||
import com.mongodb.casbah.MongoCollection
|
||||
|
||||
|
@ -11,7 +12,8 @@ final class ForumEnv(
|
|||
settings: Settings,
|
||||
captcha: Captcha,
|
||||
mongodb: String ⇒ MongoCollection,
|
||||
userRepo: UserRepo) {
|
||||
userRepo: UserRepo,
|
||||
modLog: ModlogApi) {
|
||||
|
||||
import settings._
|
||||
|
||||
|
@ -25,7 +27,7 @@ final class ForumEnv(
|
|||
|
||||
lazy val topicApi = new TopicApi(this, ForumTopicMaxPerPage)
|
||||
|
||||
lazy val postApi = new PostApi(this, ForumPostMaxPerPage)
|
||||
lazy val postApi = new PostApi(this, modLog, ForumPostMaxPerPage)
|
||||
|
||||
lazy val recent = new Recent(
|
||||
env = this,
|
||||
|
|
|
@ -3,12 +3,16 @@ package forum
|
|||
|
||||
import user.User
|
||||
import http.Context
|
||||
import mod.ModlogApi
|
||||
|
||||
import scalaz.effects._
|
||||
import com.github.ornicar.paginator._
|
||||
import scala.math.ceil
|
||||
|
||||
final class PostApi(env: ForumEnv, maxPerPage: Int) {
|
||||
final class PostApi(
|
||||
env: ForumEnv,
|
||||
modLog: ModlogApi,
|
||||
maxPerPage: Int) {
|
||||
|
||||
def create(categSlug: String, slug: String, page: Int): IO[Option[(Categ, Topic, Paginator[Post])]] =
|
||||
for {
|
||||
|
@ -64,7 +68,7 @@ final class PostApi(env: ForumEnv, maxPerPage: Int) {
|
|||
def lastNumberOf(topic: Topic): IO[Int] =
|
||||
env.postRepo lastByTopics List(topic) map (_.number)
|
||||
|
||||
def lastPageOf(topic: Topic) =
|
||||
def lastPageOf(topic: Topic) =
|
||||
ceil(topic.nbPosts / maxPerPage.toFloat).toInt
|
||||
|
||||
def paginator(topic: Topic, page: Int): Paginator[Post] =
|
||||
|
@ -77,21 +81,25 @@ final class PostApi(env: ForumEnv, maxPerPage: Int) {
|
|||
maxPerPage = maxPerPage
|
||||
) | paginator(topic, 1)
|
||||
|
||||
def delete(postId: String): IO[Unit] = for {
|
||||
def delete(postId: String, mod: User): IO[Unit] = for {
|
||||
postOption ← env.postRepo byId postId
|
||||
viewOption ← postOption.fold(view, io(none))
|
||||
_ ← viewOption.fold(
|
||||
view ⇒ (view.topic.nbPosts == 1).fold(
|
||||
env.topicApi.delete(view.categ, view.topic),
|
||||
for {
|
||||
_ ← env.postRepo removeIO view.post
|
||||
_ ← env.topicApi denormalize view.topic
|
||||
_ ← env.categApi denormalize view.categ
|
||||
_ ← env.recent.invalidate
|
||||
} yield ()
|
||||
),
|
||||
view ⇒ for {
|
||||
_ ← (view.topic.nbPosts == 1).fold(
|
||||
env.topicApi.delete(view.categ, view.topic),
|
||||
for {
|
||||
_ ← env.postRepo removeIO view.post
|
||||
_ ← env.topicApi denormalize view.topic
|
||||
_ ← env.categApi denormalize view.categ
|
||||
_ ← env.recent.invalidate
|
||||
} yield ()
|
||||
)
|
||||
post = view.post
|
||||
_ ← modLog.deletePost(mod, post.userId, post.author, post.ip,
|
||||
text = "%s / %s / %s".format(view.categ.name, view.topic.name, post.text))
|
||||
} yield (),
|
||||
io()
|
||||
)
|
||||
} yield ()
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,12 @@ final class ModlogApi(repo: ModlogRepo) {
|
|||
Modlog(mod.id, none, Modlog.ipban, ip.some)
|
||||
}
|
||||
|
||||
def deletePost(mod: User, userId: Option[String], author: Option[String], ip: Option[String], text: String) = add {
|
||||
Modlog(mod.id, userId, Modlog.deletePost, details = Some(
|
||||
author.fold(_ + " ", "") + ip.fold(_ + " ", "") + text.take(140)
|
||||
))
|
||||
}
|
||||
|
||||
def recent = repo recent 200
|
||||
|
||||
private def add(modLog: Modlog): IO[Unit] = repo saveIO modLog
|
||||
|
|
Loading…
Reference in a new issue