From be07ac569220385ebcd7daa08ceb8f6d0608d004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Gl=C3=B3rias?= Date: Sun, 25 Aug 2024 18:24:47 +0000 Subject: [PATCH] Limit for Broadcast/Study Admin --- modules/core/src/main/user.scala | 2 ++ modules/ui/src/main/helper/Form3.scala | 4 ++++ modules/user/src/main/FlairApi.scala | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/user.scala b/modules/core/src/main/user.scala index c7e2ffbe6d8f9..b1ed1aeece890 100644 --- a/modules/core/src/main/user.scala +++ b/modules/core/src/main/user.scala @@ -86,6 +86,7 @@ object user: def isAdmin = Granter.ofUser(_.Admin)(this) def isVerified = Granter.ofUser(_.Verified)(this) def isApiHog = Granter.ofUser(_.ApiHog)(this) + def isStudyAdmin = Granter.ofUser(_.StudyAdmin)(this) def isVerifiedOrAdmin = isVerified || isAdmin def isVerifiedOrChallengeAdmin = isVerifiedOrAdmin || Granter.ofUser(_.ApiChallengeAdmin)(this) end User @@ -306,6 +307,7 @@ object user: given flairOf: FlairGet given flairsOf: FlairGetMap val adminFlairs: Set[Flair] + val relayFlairs: Set[Flair] def formField(anyFlair: Boolean = false, asAdmin: Boolean = false): play.api.data.Mapping[Option[Flair]] def find(name: String): Option[Flair] diff --git a/modules/ui/src/main/helper/Form3.scala b/modules/ui/src/main/helper/Form3.scala index 0adc2d902c8cd..44ed103169111 100644 --- a/modules/ui/src/main/helper/Form3.scala +++ b/modules/ui/src/main/helper/Form3.scala @@ -244,6 +244,9 @@ final class Form3(formHelper: FormHelper & I18nHelper, flairApi: FlairApi): ) private lazy val exceptEmojis = data("except-emojis") := flairApi.adminFlairs.mkString(" ") + + private lazy val relayEmojis = data("except-emojis") := flairApi.relayFlairs.mkString(" ") + def flairPickerGroup(field: Field, current: Option[Flair], label: Frag)(view: Frag)(using Context): Tag = group(field, trans.site.flair(), half = true): f => flairPicker(f, current, label)(view) @@ -262,6 +265,7 @@ final class Form3(formHelper: FormHelper & I18nHelper, flairApi: FlairApi): hidden(field, current.map(_.value)), div( cls := "flair-picker", + (!ctx.me.exists(_.isStudyAdmin) && !anyFlair).option(relayEmojis), (!ctx.me.exists(_.isAdmin) && !anyFlair).option(exceptEmojis) ) ), diff --git a/modules/user/src/main/FlairApi.scala b/modules/user/src/main/FlairApi.scala index 03f105548bea4..abf1e0849c8a2 100644 --- a/modules/user/src/main/FlairApi.scala +++ b/modules/user/src/main/FlairApi.scala @@ -17,18 +17,20 @@ object FlairApi: text .into[Flair] .verifying(exists) - .verifying(f => anyFlair || !adminFlairs(f) || asAdmin) + .verifying(f => anyFlair || !adminFlairs(f) || !relayFlairs(f) || asAdmin) def formPair(anyFlair: Boolean = false, asAdmin: Boolean = false) = "flair" -> formField(anyFlair, asAdmin) val adminFlairs: Set[Flair] = Set(Flair("activity.lichess")) + val relayFlairs: Set[Flair] = Set(Flair("activity.lichess-broadcast")) + final class FlairApi(lightUserApi: LightUserApi)(using Executor)(using scheduler: Scheduler) extends lila.core.user.FlairApi: import FlairApi.* - export FlairApi.{ find, formField, adminFlairs } + export FlairApi.{ find, formField, adminFlairs, relayFlairs } given flairOf: FlairGet = id => lightUserApi.async(id).dmap(_.flatMap(_.flair))