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))