<commit_before>package views.html.team

import controllers.routes
import play.api.libs.json.Json

import lila.api.Context
import lila.app.mashup.TeamInfo
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import lila.common.String.html.{ richText, safeJsonValue }
import lila.team.Team

object show {

  import trans.team._

  def apply(
      t: Team,
      members: Paginator[lila.common.LightUser],
      info: TeamInfo,
      chatOption: Option[lila.chat.UserChat.Mine],
      socketVersion: Option[lila.socket.Socket.SocketVersion]
  )(implicit
      ctx: Context
  ) =
    bits.layout(
      title = t.name,
      openGraph = lila.app.ui
        .OpenGraph(
          title = s"${t.name} team",
          url = s"$netBaseUrl${routes.Team.show(t.id).url}",
          description = shorten(t.description, 152)
        )
        .some,
      moreJs = frag(
        jsModule("team"),
        embedJsUnsafeLoadThen(s"""teamStart(${safeJsonValue(
          Json
            .obj("id" -> t.id)
            .add("socketVersion" -> socketVersion.map(_.value))
            .add("chat" -> chatOption.map { chat =>
              views.html.chat.json(
                chat.chat,
                name = if (t.isChatFor(_.LEADERS)) leadersChat.txt() else trans.chatRoom.txt(),
                timeout = chat.timeout,
                public = true,
                resourceId = lila.chat.Chat.ResourceId(s"team/${chat.chat.id}"),
                localMod = ctx.userId exists t.leaders.contains
              )
            })
        )})""")
      )
    ) {
      val enabledOrLeader = t.enabled || info.ledByMe || isGranted(_.Admin)
      main(
        cls := "team-show box",
        socketVersion.map { v =>
          data("socket-version") := v.value
        }
      )(
        div(cls := "box__top")(
          h1(cls := "text", dataIcon := "")(t.name),
          div(
            if (t.disabled) span(cls := "staff")("CLOSED")
            else nbMembers.plural(t.nbMembers, strong(t.nbMembers.localize))
          )
        ),
        div(cls := "team-show__content")(
          div(cls := "team-show__content__col1")(
            enabledOrLeader option st.section(cls := "team-show__meta")(
              p(
                teamLeaders.pluralSame(t.leaders.size),
                ": ",
                fragList(t.leaders.toList.map { l =>
                  userIdLink(l.some)
                })
              ),
              info.ledByMe option a(
                dataIcon := "",
                href := routes.Page.loneBookmark("team-etiquette"),
                cls := "text team-show__meta__etiquette"
              )("Team Etiquette")
            ),
            (t.enabled && chatOption.isDefined) option frag(
              views.html.chat.frag,
              views.html.chat.spectatorsFrag
            ),
            div(cls := "team-show__actions")(
              (t.enabled && !info.mine) option frag(
                if (info.requestedByMe)
                  frag(
                    strong(beingReviewed()),
                    postForm(action := routes.Team.quit(t.id))(
                      submitButton(cls := "button button-red button-empty confirm")(trans.cancel())
                    )
                  )
                else ctx.isAuth option joinButton(t)
              ),
              ctx.userId.ifTrue(t.enabled && info.mine) map { myId =>
                postForm(
                  cls := "team-show__subscribe form3",
                  action := routes.Team.subscribe(t.id)
                )(
                  div(
                    span(form3.cmnToggle("team-subscribe", "subscribe", checked = info.subscribed)),
                    label(`for` := "team-subscribe")(subToTeamMessages.txt())
                  )
                )
              },
              (info.mine && !info.ledByMe) option
                postForm(cls := "quit", action := routes.Team.quit(t.id))(
                  submitButton(cls := "button button-empty button-red confirm")(quitTeam.txt())
                ),
              t.enabled && info.ledByMe option frag(
                a(
                  href := routes.Tournament.teamBattleForm(t.id),
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(teamBattle()),
                    em(teamBattleOverview())
                  )
                ),
                a(
                  href := s"${routes.Tournament.form}?team=${t.id}",
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(teamTournament()),
                    em(teamTournamentOverview())
                  )
                ),
                a(
                  href := s"${routes.Swiss.form(t.id)}",
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(trans.swiss.swissTournaments()),
                    em(swissTournamentOverview())
                  )
                ),
                a(
                  href := routes.Team.pmAll(t.id),
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(messageAllMembers()),
                    em(messageAllMembersOverview())
                  )
                )
              ),
              ((t.enabled && info.ledByMe) || isGranted(_.Admin)) option
                a(href := routes.Team.edit(t.id), cls := "button button-empty text", dataIcon := "")(
                  trans.settings.settings()
                )
            ),<commit_msg>Fix team permissions<commit_after>package views.html.team

import controllers.routes
import play.api.libs.json.Json

import lila.api.Context
import lila.app.mashup.TeamInfo
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import lila.common.String.html.{ richText, safeJsonValue }
import lila.team.Team

object show {

  import trans.team._

  def apply(
      t: Team,
      members: Paginator[lila.common.LightUser],
      info: TeamInfo,
      chatOption: Option[lila.chat.UserChat.Mine],
      socketVersion: Option[lila.socket.Socket.SocketVersion]
  )(implicit
      ctx: Context
  ) =
    bits.layout(
      title = t.name,
      openGraph = lila.app.ui
        .OpenGraph(
          title = s"${t.name} team",
          url = s"$netBaseUrl${routes.Team.show(t.id).url}",
          description = shorten(t.description, 152)
        )
        .some,
      moreJs = frag(
        jsModule("team"),
        embedJsUnsafeLoadThen(s"""teamStart(${safeJsonValue(
          Json
            .obj("id" -> t.id)
            .add("socketVersion" -> socketVersion.map(_.value))
            .add("chat" -> chatOption.map { chat =>
              views.html.chat.json(
                chat.chat,
                name = if (t.isChatFor(_.LEADERS)) leadersChat.txt() else trans.chatRoom.txt(),
                timeout = chat.timeout,
                public = true,
                resourceId = lila.chat.Chat.ResourceId(s"team/${chat.chat.id}"),
                localMod = ctx.userId exists t.leaders.contains
              )
            })
        )})""")
      )
    ) {
      val enabledOrLeader = t.enabled || info.ledByMe || isGranted(_.ManageTeam)
      main(
        cls := "team-show box",
        socketVersion.map { v =>
          data("socket-version") := v.value
        }
      )(
        div(cls := "box__top")(
          h1(cls := "text", dataIcon := "")(t.name),
          div(
            if (t.disabled) span(cls := "staff")("CLOSED")
            else nbMembers.plural(t.nbMembers, strong(t.nbMembers.localize))
          )
        ),
        div(cls := "team-show__content")(
          div(cls := "team-show__content__col1")(
            enabledOrLeader option st.section(cls := "team-show__meta")(
              p(
                teamLeaders.pluralSame(t.leaders.size),
                ": ",
                fragList(t.leaders.toList.map { l =>
                  userIdLink(l.some)
                })
              ),
              info.ledByMe option a(
                dataIcon := "",
                href := routes.Page.loneBookmark("team-etiquette"),
                cls := "text team-show__meta__etiquette"
              )("Team Etiquette")
            ),
            (t.enabled && chatOption.isDefined) option frag(
              views.html.chat.frag,
              views.html.chat.spectatorsFrag
            ),
            div(cls := "team-show__actions")(
              (t.enabled && !info.mine) option frag(
                if (info.requestedByMe)
                  frag(
                    strong(beingReviewed()),
                    postForm(action := routes.Team.quit(t.id))(
                      submitButton(cls := "button button-red button-empty confirm")(trans.cancel())
                    )
                  )
                else ctx.isAuth option joinButton(t)
              ),
              ctx.userId.ifTrue(t.enabled && info.mine) map { myId =>
                postForm(
                  cls := "team-show__subscribe form3",
                  action := routes.Team.subscribe(t.id)
                )(
                  div(
                    span(form3.cmnToggle("team-subscribe", "subscribe", checked = info.subscribed)),
                    label(`for` := "team-subscribe")(subToTeamMessages.txt())
                  )
                )
              },
              (info.mine && !info.ledByMe) option
                postForm(cls := "quit", action := routes.Team.quit(t.id))(
                  submitButton(cls := "button button-empty button-red confirm")(quitTeam.txt())
                ),
              t.enabled && info.ledByMe option frag(
                a(
                  href := routes.Tournament.teamBattleForm(t.id),
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(teamBattle()),
                    em(teamBattleOverview())
                  )
                ),
                a(
                  href := s"${routes.Tournament.form}?team=${t.id}",
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(teamTournament()),
                    em(teamTournamentOverview())
                  )
                ),
                a(
                  href := s"${routes.Swiss.form(t.id)}",
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(trans.swiss.swissTournaments()),
                    em(swissTournamentOverview())
                  )
                ),
                a(
                  href := routes.Team.pmAll(t.id),
                  cls := "button button-empty text",
                  dataIcon := ""
                )(
                  span(
                    strong(messageAllMembers()),
                    em(messageAllMembersOverview())
                  )
                )
              ),
              ((t.enabled && info.ledByMe) || isGranted(_.ManageTeam)) option
                a(href := routes.Team.edit(t.id), cls := "button button-empty text", dataIcon := "")(
                  trans.settings.settings()
                )
            ),
{'fraction_non_alphanumeric': 0.12761200447157967, 'fraction_numerical': 0.0012038868346375441, 'mean_word_length': 1.2790515383107977, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3917194', 'n_tokens_mistral': 3325, 'n_tokens_neox': 3130, 'n_words': 520}