Skip to content

Commit

Permalink
Added replyBlocked function in ForumAccess and added the trans key in…
Browse files Browse the repository at this point in the history
… ublog.xml instead of site.xml
  • Loading branch information
Carbrex committed Feb 25, 2024
1 parent 1c61ee3 commit 98d79a4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
11 changes: 3 additions & 8 deletions app/controllers/ForumPost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import views.*
import lila.app.{ given, * }
import lila.common.IpAddress
import lila.msg.MsgPreset
import lila.relation.{ Block }
import lila.i18n.{ I18nKeys as trans }

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

Expand Down Expand Up @@ -40,14 +40,9 @@ final class ForumPost(env: Env) extends LilaController(env) with ForumController
else
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
replyBlocked <- access.isReplyBlockedOnUBlog(topic, canModCateg)
res <-
if replyBlocked then Future.successful(BadRequest("You are blocked by the blog author"))
if replyBlocked then fuccess(BadRequest(trans.ublog.youBlockedByBlogAuthor()))
else
categ.team.so(env.team.api.isLeader(_, me)) flatMap { inOwnTeam =>
forms
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/ForumTopic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import lila.app.{ given, * }
import lila.common.IpAddress
import lila.forum.ForumCateg.diagnosticId
import lila.Lila.{ UserId }
import lila.relation.{ Block }

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

Expand Down Expand Up @@ -59,14 +58,9 @@ final class ForumTopic(env: Env) extends LilaController(env) with ForumControlle
for
unsub <- ctx.me soUse env.timeline.status(s"forum:${topic.id}")
canRead <- access.isGrantedRead(categ.slug)
topicUserId = topic.userId.getOrElse(UserId(""))
relation <- ctx.userId.so(
env.relation.api.fetchRelation(topicUserId: UserId, _)
)
canWrite <- access.isGrantedWrite(categ.slug, tryingToPostAsMod = true)
canModCateg <- access.isGrantedMod(categ.slug)
isUblog = topic.ublogId.isDefined
replyBlocked = relation.exists(_ == Block) && !canModCateg && isUblog
replyBlocked <- access.isReplyBlockedOnUBlog(topic, canModCateg)
inOwnTeam <- ~(categ.team, ctx.me).mapN(env.team.api.isLeader(_, _))
form <- ctx.me
.filter(_ => canWrite && topic.open && !topic.isOld && !replyBlocked)
Expand Down
2 changes: 1 addition & 1 deletion app/views/forum/topic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ object topic:
a(href := teamRoutes.show(teamId))(trans.teamNamedX(teamLink(teamId, true)))
.orElse:
if ctx.me.exists(_.isBot) then p("Bots cannot post in the forum.").some
else if replyBlocked then p(trans.youBlockedByBlogAuthor()).some
else if replyBlocked then p(trans.ublog.youBlockedByBlogAuthor()).some
else ctx.isAuth option p(trans.youCannotPostYetPlaySomeGames())
,
div(
Expand Down
15 changes: 14 additions & 1 deletion modules/api/src/main/ForumAccess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import lila.forum.ForumCateg
import lila.security.{ Granter, Permission }
import lila.team.Team
import lila.user.{ User, Me }
import lila.relation.Block

final class ForumAccess(teamApi: lila.team.TeamApi, teamCached: lila.team.Cached)(using
final class ForumAccess(
teamApi: lila.team.TeamApi,
teamCached: lila.team.Cached,
relationApi: lila.relation.RelationApi
)(using
Executor
):

Expand Down Expand Up @@ -45,3 +50,11 @@ final class ForumAccess(teamApi: lila.team.TeamApi, teamCached: lila.team.Cached
def isGrantedMod(categId: ForumCategId)(using meOpt: Option[Me]): Fu[Boolean] = meOpt.so: me =>
if Granter.opt(_.ModerateForum) then fuTrue
else ForumCateg.toTeamId(categId).so(teamApi.hasPerm(_, me, _.Comm))

def isReplyBlockedOnUBlog(topic: lila.forum.ForumTopic, canModCateg: Boolean)(using
meOpt: Option[Me]
): Fu[Boolean] = meOpt.so: me =>
if topic.ublogId.isEmpty then fuFalse
else if topic.userId.isEmpty then fuFalse
else if canModCateg then fuFalse
else relationApi.fetchRelation(topic.userId.get, me).map(_.contains(Block))
2 changes: 1 addition & 1 deletion modules/i18n/src/main/I18nKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,6 @@ object I18nKeys:
val `joinTheTeamXToPost` = I18nKey("joinTheTeamXToPost")
val `teamNamedX` = I18nKey("teamNamedX")
val `youCannotPostYetPlaySomeGames` = I18nKey("youCannotPostYetPlaySomeGames")
val `youBlockedByBlogAuthor` = I18nKey("youBlockedByBlogAuthor")
val `subscribe` = I18nKey("subscribe")
val `unsubscribe` = I18nKey("unsubscribe")
val `mentionedYouInX` = I18nKey("mentionedYouInX")
Expand Down Expand Up @@ -2457,6 +2456,7 @@ object I18nKeys:
val `inappropriateContentAccountClosed` = I18nKey("ublog:inappropriateContentAccountClosed")
val `blogTips` = I18nKey("ublog:blogTips")
val `discussThisBlogPostInTheForum` = I18nKey("ublog:discussThisBlogPostInTheForum")
val `youBlockedByBlogAuthor` = I18nKey("ublog:youBlockedByBlogAuthor")
val `publishedNbBlogPosts` = I18nKey("ublog:publishedNbBlogPosts")
val `nbViews` = I18nKey("ublog:nbViews")
val `viewAllNbPosts` = I18nKey("ublog:viewAllNbPosts")
Expand Down
1 change: 0 additions & 1 deletion translation/source/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,6 @@
<string name="joinTheTeamXToPost">Join the %1$s, to post in this forum</string>
<string name="teamNamedX">%1$s team</string>
<string name="youCannotPostYetPlaySomeGames">You can't post in the forums yet. Play some games!</string>
<string name="youBlockedByBlogAuthor">You are blocked by the blog author.</string>
<string name="subscribe">Subscribe</string>
<string name="unsubscribe">Unsubscribe</string>
<string name="mentionedYouInX">mentioned you in "%1$s".</string>
Expand Down
1 change: 1 addition & 0 deletions translation/source/ublog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
<string name="inappropriateContentAccountClosed">Anything inappropriate could get your account closed.</string>
<string name="blogTips">Our simple tips to write great blog posts</string>
<string name="discussThisBlogPostInTheForum">Discuss this blog post in the forum</string>
<string name="youBlockedByBlogAuthor">You are blocked by the blog author.</string>
</resources>

0 comments on commit 98d79a4

Please sign in to comment.