From c23cc60a245c9e56eb461fb44bc0d5fa0befa184 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 25 Jan 2017 00:11:42 +0100 Subject: [PATCH] remove blocking forum granter --- app/controllers/ForumPost.scala | 37 ++++++++++++++++---------------- app/controllers/ForumTopic.scala | 37 +++++++++++++++----------------- app/templating/ForumHelper.scala | 3 --- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/app/controllers/ForumPost.scala b/app/controllers/ForumPost.scala index bd0ca96225..6d5c813164 100644 --- a/app/controllers/ForumPost.scala +++ b/app/controllers/ForumPost.scala @@ -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 => diff --git a/app/controllers/ForumTopic.scala b/app/controllers/ForumTopic.scala index bc3ee0375c..d9d4b9c818 100644 --- a/app/controllers/ForumTopic.scala +++ b/app/controllers/ForumTopic.scala @@ -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) + } } /** diff --git a/app/templating/ForumHelper.scala b/app/templating/ForumHelper.scala index 0b80aceac8..4267c7d07b 100644 --- a/app/templating/ForumHelper.scala +++ b/app/templating/ForumHelper.scala @@ -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)