join 15 teams + 1 per week, up to 50 teams

pull/8198/head
Thibault Duplessis 2021-02-16 16:33:05 +01:00
parent ed244b8382
commit 218c948648
4 changed files with 23 additions and 8 deletions

View File

@ -198,9 +198,8 @@ final class Team(
def create =
AuthBody { implicit ctx => implicit me =>
api countTeamsOf me flatMap { nb =>
if (nb >= TeamModel.maxJoin)
BadRequest(views.html.site.message.teamJoinLimit).fuccess
api hasJoinedTooManyTeams me flatMap { tooMany =>
if (tooMany) tooManyTeams(me)
else
LimitPerWeek(me) {
implicit val req = ctx.body
@ -227,6 +226,11 @@ final class Team(
}
}
private def tooManyTeams(me: UserModel)(implicit ctx: Context) =
api mine me map {
html.team.list.mine(_, tooMany = true)
} map { BadRequest(_) }
def leader =
Auth { implicit ctx => me =>
env.team.teamRepo enabledTeamsByLeader me.id map {
@ -240,10 +244,10 @@ final class Team(
me =>
api.team(id) flatMap {
_ ?? { team =>
api countTeamsOf me flatMap { nb =>
if (nb >= TeamModel.maxJoin)
api hasJoinedTooManyTeams me flatMap { tooMany =>
if (tooMany)
negotiate(
html = BadRequest(views.html.site.message.teamJoinLimit).fuccess,
html = tooManyTeams(me),
api = _ => BadRequest(jsonError("You have joined too many teams")).fuccess
)
else

View File

@ -26,13 +26,18 @@ object list {
nextPageUrl = n => routes.Team.all(n).url
)
def mine(teams: List[lila.team.Team])(implicit ctx: Context) =
def mine(teams: List[lila.team.Team], tooMany: Boolean = false)(implicit ctx: Context) =
bits.layout(title = myTeams.txt()) {
main(cls := "team-list page-menu")(
bits.menu("mine".some),
div(cls := "page-menu__content box")(
h1(myTeams()),
standardFlash(),
ctx.me.ifTrue(tooMany) map { me =>
flashMessage(cls := "flash-failure")(
s"You have joined ${teams.size} out of ${lila.team.Team.maxJoin(me)} teams. Leave some teams before you can join others."
)
},
table(cls := "slist slist-pad")(
if (teams.nonEmpty) tbody(teams.map(bits.teamTr(_)))
else noTeam()

View File

@ -4,6 +4,7 @@ import org.joda.time.DateTime
import scala.util.chaining._
import lila.user.User
import org.joda.time.Days
case class Team(
_id: Team.ID, // also the url slug
@ -32,7 +33,9 @@ case class Team(
object Team {
val maxJoin = 32
def maxJoin(u: User) = {
15 + Days.daysBetween(u.createdAt, DateTime.now).getDays / 7
} atMost 50
type ID = String

View File

@ -95,6 +95,9 @@ final class TeamApi(
def countTeamsOf(me: User) =
cached teamIdsList me.id dmap (_.size)
def hasJoinedTooManyTeams(me: User) =
countTeamsOf(me).dmap(_ > Team.maxJoin(me))
def hasTeams(me: User): Fu[Boolean] = cached.teamIds(me.id).map(_.value.nonEmpty)
def countCreatedRecently(me: User): Fu[Int] =