remove blocking forum granter

mixed-cache-boot
Thibault Duplessis 2017-01-25 00:11:42 +01:00
parent 3ba1a5b55f
commit c23cc60a24
3 changed files with 35 additions and 42 deletions

View File

@ -1,8 +1,8 @@
package controllers package controllers
import scala.concurrent.duration._
import lila.common.HTTPRequest
import lila.app._ import lila.app._
import lila.common.HTTPRequest
import scala.concurrent.duration._
import views._ import views._
object ForumPost extends LilaController with ForumController { object ForumPost extends LilaController with ForumController {
@ -38,11 +38,11 @@ object ForumPost extends LilaController with ForumController {
case (categ, topic, posts) => case (categ, topic, posts) =>
if (topic.closed) fuccess(BadRequest("This topic is closed")) if (topic.closed) fuccess(BadRequest("This topic is closed"))
else forms.post.bindFromRequest.fold( else forms.post.bindFromRequest.fold(
err => forms.anyCaptcha flatMap { captcha => err => for {
ctx.userId ?? Env.timeline.status(s"forum:${topic.id}") map { unsub => captcha <- forms.anyCaptcha
BadRequest(html.forum.topic.show(categ, topic, posts, Some(err -> captcha), unsub)) unsub <- ctx.userId ?? Env.timeline.status(s"forum:${topic.id}")
} canModCateg <- isGrantedMod(categ.slug)
}, } yield BadRequest(html.forum.topic.show(categ, topic, posts, Some(err -> captcha), unsub, canModCateg = canModCateg)),
data => postApi.makePost(categ, topic, data) map { post => data => postApi.makePost(categ, topic, data) map { post =>
Redirect(routes.ForumPost.redirect(post.id)) Redirect(routes.ForumPost.redirect(post.id))
} }
@ -52,23 +52,22 @@ object ForumPost extends LilaController with ForumController {
} }
} }
def edit(postId: String) = AuthBody { implicit ctx => def edit(postId: String) = AuthBody { implicit ctx => me =>
me =>
implicit val req = ctx.body implicit val req = ctx.body
forms.postEdit.bindFromRequest.fold(err => Redirect(routes.ForumPost.redirect(postId)).fuccess, forms.postEdit.bindFromRequest.fold(
data => err => Redirect(routes.ForumPost.redirect(postId)).fuccess,
postApi.editPost(postId, data.changes, me).map { post => data =>
Redirect(routes.ForumPost.redirect(post.id)) postApi.editPost(postId, data.changes, me).map { post =>
} Redirect(routes.ForumPost.redirect(post.id))
}
) )
} }
def delete(categSlug: String, id: String) = Auth { implicit ctx => def delete(categSlug: String, id: String) = Auth { implicit ctx => me =>
me => CategGrantMod(categSlug) {
CategGrantMod(categSlug) { postApi.delete(categSlug, id, me) map { Ok(_) }
postApi.delete(categSlug, id, me) map { Ok(_) } }
}
} }
def redirect(id: String) = Open { implicit ctx => def redirect(id: String) = Open { implicit ctx =>

View File

@ -2,8 +2,8 @@ package controllers
import scala.concurrent.duration._ import scala.concurrent.duration._
import lila.common.HTTPRequest
import lila.app._ import lila.app._
import lila.common.HTTPRequest
import lila.forum.CategRepo import lila.forum.CategRepo
import play.api.libs.json._ import play.api.libs.json._
import views._ import views._
@ -46,33 +46,30 @@ object ForumTopic extends LilaController with ForumController {
NotForKids { NotForKids {
CategGrantRead(categSlug) { CategGrantRead(categSlug) {
OptionFuOk(topicApi.show(categSlug, slug, page, ctx.troll)) { OptionFuOk(topicApi.show(categSlug, slug, page, ctx.troll)) {
case (categ, topic, posts) => case (categ, topic, posts) => for {
ctx.userId ?? Env.timeline.status(s"forum:${topic.id}") flatMap { unsub => unsub <- ctx.userId ?? Env.timeline.status(s"forum:${topic.id}")
(!posts.hasNextPage && isGrantedWrite(categSlug) && topic.open) ?? forms.postWithCaptcha.map(_.some) map { form => form <- (!posts.hasNextPage && isGrantedWrite(categSlug) && topic.open) ?? forms.postWithCaptcha.map(_.some)
html.forum.topic.show(categ, topic, posts, form, unsub) canModCateg <- isGrantedMod(categ.slug)
} } yield html.forum.topic.show(categ, topic, posts, form, unsub, canModCateg = canModCateg)
}
} }
} }
} }
} }
def close(categSlug: String, slug: String) = Auth { implicit ctx => def close(categSlug: String, slug: String) = Auth { implicit ctx => me =>
me => CategGrantMod(categSlug) {
CategGrantMod(categSlug) {
OptionFuRedirect(topicApi.show(categSlug, slug, 1, ctx.troll)) {
case (categ, topic, pag) => topicApi.toggleClose(categ, topic, me) inject
routes.ForumTopic.show(categSlug, slug, pag.nbPages)
}
}
}
def hide(categSlug: String, slug: String) = Secure(_.ModerateForum) { implicit ctx =>
me =>
OptionFuRedirect(topicApi.show(categSlug, slug, 1, ctx.troll)) { OptionFuRedirect(topicApi.show(categSlug, slug, 1, ctx.troll)) {
case (categ, topic, pag) => topicApi.toggleHide(categ, topic, me) inject case (categ, topic, pag) => topicApi.toggleClose(categ, topic, me) inject
routes.ForumTopic.show(categSlug, slug, pag.nbPages) routes.ForumTopic.show(categSlug, slug, pag.nbPages)
} }
}
}
def hide(categSlug: String, slug: String) = Secure(_.ModerateForum) { implicit ctx => me =>
OptionFuRedirect(topicApi.show(categSlug, slug, 1, ctx.troll)) {
case (categ, topic, pag) => topicApi.toggleHide(categ, topic, me) inject
routes.ForumTopic.show(categSlug, slug, pag.nbPages)
}
} }
/** /**

View File

@ -23,9 +23,6 @@ trait ForumHelper { self: UserHelper with StringHelper =>
def isGrantedWrite(categSlug: String)(implicit ctx: Context) = def isGrantedWrite(categSlug: String)(implicit ctx: Context) =
Granter isGrantedWrite categSlug Granter isGrantedWrite categSlug
def isGrantedMod(categSlug: String)(implicit ctx: Context) =
Granter.isGrantedMod(categSlug).await
def authorName(post: Post) = post.userId match { def authorName(post: Post) = post.userId match {
case Some(userId) => userIdSpanMini(userId, withOnline = true) case Some(userId) => userIdSpanMini(userId, withOnline = true)
case None => Html(lila.user.User.anonymous) case None => Html(lila.user.User.anonymous)