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

View File

@ -2,8 +2,8 @@ package controllers
import scala.concurrent.duration._
import lila.common.HTTPRequest
import lila.app._
import lila.common.HTTPRequest
import lila.forum.CategRepo
import play.api.libs.json._
import views._
@ -46,33 +46,30 @@ object ForumTopic extends LilaController with ForumController {
NotForKids {
CategGrantRead(categSlug) {
OptionFuOk(topicApi.show(categSlug, slug, page, ctx.troll)) {
case (categ, topic, posts) =>
ctx.userId ?? Env.timeline.status(s"forum:${topic.id}") flatMap { unsub =>
(!posts.hasNextPage && isGrantedWrite(categSlug) && topic.open) ?? forms.postWithCaptcha.map(_.some) map { form =>
html.forum.topic.show(categ, topic, posts, form, unsub)
}
}
case (categ, topic, posts) => for {
unsub <- ctx.userId ?? Env.timeline.status(s"forum:${topic.id}")
form <- (!posts.hasNextPage && isGrantedWrite(categSlug) && topic.open) ?? forms.postWithCaptcha.map(_.some)
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 =>
me =>
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 =>
def close(categSlug: String, slug: String) = Auth { implicit ctx => me =>
CategGrantMod(categSlug) {
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)
}
}
}
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) =
Granter isGrantedWrite categSlug
def isGrantedMod(categSlug: String)(implicit ctx: Context) =
Granter.isGrantedMod(categSlug).await
def authorName(post: Post) = post.userId match {
case Some(userId) => userIdSpanMini(userId, withOnline = true)
case None => Html(lila.user.User.anonymous)