Skip to content

Commit

Permalink
Only prohibit commenting on blog discussions not forums and not prohi…
Browse files Browse the repository at this point in the history
…bit admins changed in controllers.forumpost.create
  • Loading branch information
Carbrex committed Feb 23, 2024
1 parent c4426d3 commit b53de7e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 48 deletions.
90 changes: 43 additions & 47 deletions app/controllers/ForumPost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import lila.app.{ given, * }
import lila.common.IpAddress
import lila.msg.MsgPreset
import lila.relation.{ Block }
import lila.user.User
import lila.common.paginator.Paginator
import scala.concurrent.Future

final class ForumPost(env: Env) extends LilaController(env) with ForumController:

Expand Down Expand Up @@ -36,55 +33,54 @@ final class ForumPost(env: Env) extends LilaController(env) with ForumController
yield Ok(page)

def create(categId: ForumCategId, slug: String, page: Int) = AuthBody { ctx ?=> me ?=>
def processRequest(
categ: lila.forum.ForumCateg,
topic: lila.forum.ForumTopic,
posts: lila.common.paginator.Paginator[lila.forum.ForumPost.WithFrag]
) =
categ.team.so(env.team.api.isLeader(_, me)) flatMap { inOwnTeam =>
forms
.post(inOwnTeam)
.bindFromRequest()
.fold(
err =>
CategGrantWrite(categId, tryingToPostAsMod = true):
for
captcha <- forms.anyCaptcha
unsub <- env.timeline.status(s"forum:${topic.id}")
canModCateg <- access.isGrantedMod(categ.slug)
page <- renderPage:
html.forum.topic
.show(
categ,
topic,
posts,
Some(err -> captcha),
unsub,
canModCateg = canModCateg
)
yield BadRequest(page)
,
data =>
CategGrantWrite(categId, tryingToPostAsMod = ~data.modIcon):
CreateRateLimit(ctx.ip, rateLimited):
postApi.makePost(categ, topic, data) map { post =>
Redirect(routes.ForumPost.redirect(post.id))
}
)
}
NoBot:
Found(topicApi.show(categId, slug, page)): (categ, topic, posts) =>
if topic.closed then BadRequest("This topic is closed")
else if topic.isOld then BadRequest("This topic is archived")
else
topic.pp.userId match
case Some(userId) =>
env.relation.api.fetchRelation(userId: UserId, me.userId).flatMap {
case Some(relation) if relation == Block =>
BadRequest("You are blocked by the forum author")
case _ => processRequest(categ, topic, posts)
}
case None => processRequest(categ, topic, posts)
for
canModCateg <- access.isGrantedMod(categ.slug)
topicUserId = topic.userId.getOrElse(UserId(""))
relation <- ctx.userId.so(
env.relation.api.fetchRelation(topicUserId: UserId, _)
)
isUblog = topic.ublogId.isDefined
replyBlocked = relation.exists(_ == Block) && !canModCateg && isUblog
res <-
if replyBlocked then Future.successful(BadRequest("You are blocked by the blog author"))
else
categ.team.so(env.team.api.isLeader(_, me)) flatMap { inOwnTeam =>
forms
.post(inOwnTeam)
.bindFromRequest()
.fold(
err =>
CategGrantWrite(categId, tryingToPostAsMod = true):
for
captcha <- forms.anyCaptcha
unsub <- env.timeline.status(s"forum:${topic.id}")
canModCateg <- access.isGrantedMod(categ.slug)
page <- renderPage:
html.forum.topic
.show(
categ,
topic,
posts,
Some(err -> captcha),
unsub,
canModCateg = canModCateg
)
yield BadRequest(page)
,
data =>
CategGrantWrite(categId, tryingToPostAsMod = ~data.modIcon):
CreateRateLimit(ctx.ip, rateLimited):
postApi.makePost(categ, topic, data) map { post =>
Redirect(routes.ForumPost.redirect(post.id))
}
)
}
yield res
}

def edit(postId: ForumPostId) = AuthBody { ctx ?=> me ?=>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ForumTopic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import lila.app.{ given, * }
import lila.common.IpAddress
import lila.forum.ForumCateg.diagnosticId
import lila.Lila.{ UserId }
import lila.relation.{ Follow, Block }
import lila.relation.{ Block }

final class ForumTopic(env: Env) extends LilaController(env) with ForumController:

Expand Down

0 comments on commit b53de7e

Please sign in to comment.