diff --git a/app/controllers/ForumPost.scala b/app/controllers/ForumPost.scala index 2d2e364ff2f79..791e2138690d7 100644 --- a/app/controllers/ForumPost.scala +++ b/app/controllers/ForumPost.scala @@ -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: @@ -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 diff --git a/app/controllers/ForumTopic.scala b/app/controllers/ForumTopic.scala index 7b4689f71db4d..9185fa341224f 100644 --- a/app/controllers/ForumTopic.scala +++ b/app/controllers/ForumTopic.scala @@ -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: @@ -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) diff --git a/app/views/forum/topic.scala b/app/views/forum/topic.scala index 2794a5dab7cda..cb18904833187 100644 --- a/app/views/forum/topic.scala +++ b/app/views/forum/topic.scala @@ -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( diff --git a/modules/api/src/main/ForumAccess.scala b/modules/api/src/main/ForumAccess.scala index 146bbaff685bc..82cbfc98e361b 100644 --- a/modules/api/src/main/ForumAccess.scala +++ b/modules/api/src/main/ForumAccess.scala @@ -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 ): @@ -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)) diff --git a/modules/i18n/src/main/I18nKeys.scala b/modules/i18n/src/main/I18nKeys.scala index 79d7c109ee327..6618725e7ff85 100644 --- a/modules/i18n/src/main/I18nKeys.scala +++ b/modules/i18n/src/main/I18nKeys.scala @@ -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") @@ -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") diff --git a/translation/source/site.xml b/translation/source/site.xml index a287474e1d959..68f67e94bf31e 100644 --- a/translation/source/site.xml +++ b/translation/source/site.xml @@ -911,7 +911,6 @@ Join the %1$s, to post in this forum %1$s team You can't post in the forums yet. Play some games! - You are blocked by the blog author. Subscribe Unsubscribe mentioned you in "%1$s". diff --git a/translation/source/ublog.xml b/translation/source/ublog.xml index 2d44135ff8c6d..a4dfa225fa0fd 100644 --- a/translation/source/ublog.xml +++ b/translation/source/ublog.xml @@ -52,4 +52,5 @@ Anything inappropriate could get your account closed. Our simple tips to write great blog posts Discuss this blog post in the forum + You are blocked by the blog author.