Skip to content

Commit

Permalink
Limit for Broadcast/Study Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGlorias committed Aug 25, 2024
1 parent 3881ce9 commit be07ac5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions modules/core/src/main/user.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
4 changes: 4 additions & 0 deletions modules/ui/src/main/helper/Form3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
)
),
Expand Down
6 changes: 4 additions & 2 deletions modules/user/src/main/FlairApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit be07ac5

Please sign in to comment.