Skip to content

Commit

Permalink
Added check for is user blocked by forum author in controller.ForumPo…
Browse files Browse the repository at this point in the history
…st.create
  • Loading branch information
Carbrex committed Feb 21, 2024
1 parent 9194180 commit 30070d1
Showing 1 changed file with 72 additions and 24 deletions.
96 changes: 72 additions & 24 deletions app/controllers/ForumPost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import views.*
import lila.app.{ given, * }
import lila.common.IpAddress
import lila.msg.MsgPreset
import lila.relation.{ Block }
import lila.Lila.{ UserId }

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

Expand Down Expand Up @@ -37,30 +39,76 @@ final class ForumPost(env: Env) extends LilaController(env) with ForumController
if topic.closed then BadRequest("This topic is closed")
else if topic.isOld then BadRequest("This topic is archived")
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))
}
)
}
topic.userId match
case Some(userId) =>
env.relation.api.fetchRelation(userId: UserId, me.userId).flatMap {
case Some(relation) if relation == Block =>
Future.successful(BadRequest("You are blocked by the topic author"))
case _ =>
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))
}
)
}
}
case None =>
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))
}
)
}
}

def edit(postId: ForumPostId) = AuthBody { ctx ?=> me ?=>
Expand Down

0 comments on commit 30070d1

Please sign in to comment.