withdraw from all tournaments when converting account to bot
parent
96c3234f90
commit
139c04e7a6
|
@ -144,9 +144,10 @@ final class Env(
|
|||
_ <- user.repo.disable(u, keepEmail = badApple || playbanned)
|
||||
_ <- relation.api.unfollowAll(u.id)
|
||||
_ <- user.rankingApi.remove(u.id)
|
||||
_ <- team.api.quitAll(u.id)
|
||||
teamIds <- team.api.quitAll(u.id)
|
||||
_ <- challenge.api.removeByUserId(u.id)
|
||||
_ <- tournament.api.withdrawAll(u)
|
||||
_ <- swiss.api.withdrawAll(u, teamIds)
|
||||
_ <- plan.api.cancel(u).nevermind
|
||||
_ <- lobby.seekApi.removeByUser(u)
|
||||
_ <- security.store.closeAllSessionsOf(u.id)
|
||||
|
|
|
@ -35,7 +35,9 @@ final class PlayApi(
|
|||
env.user.repo.isManaged(me.id) flatMap {
|
||||
case true => notFoundJson()
|
||||
case _ =>
|
||||
env.user.repo.setBot(me) >>
|
||||
env.tournament.api.withdrawAll(me) >>
|
||||
env.team.cached.teamIdsList(me.id).flatMap { env.swiss.api.withdrawAll(me, _) } >>
|
||||
env.user.repo.setBot(me) >>
|
||||
env.pref.api.setBot(me) >>-
|
||||
env.user.lightUserApi.invalidate(me.id) pipe
|
||||
toResult recover {
|
||||
|
|
|
@ -550,6 +550,41 @@ final class SwissApi(
|
|||
private def systemChat(id: Swiss.Id, text: String, volatile: Boolean = false): Unit =
|
||||
chatApi.userChat.service(Chat.Id(id.value), text, _.Swiss, volatile)
|
||||
|
||||
def withdrawAll(user: User, teamIds: List[TeamID]): Funit =
|
||||
colls.swiss
|
||||
.aggregateList(Int.MaxValue, readPreference = ReadPreference.secondaryPreferred) { implicit framework =>
|
||||
import framework._
|
||||
Match($doc("finishedAt" $exists false, "nbPlayers" $gt 0, "teamId" $in teamIds)) -> List(
|
||||
PipelineOperator(
|
||||
$doc(
|
||||
"$lookup" -> $doc(
|
||||
"from" -> colls.player.name,
|
||||
"let" -> $doc("s" -> "$_id"),
|
||||
"pipeline" -> $arr(
|
||||
$doc(
|
||||
"$match" -> $doc(
|
||||
"$expr" -> $doc(
|
||||
"$and" -> $arr(
|
||||
$doc("$eq" -> $arr("$u", user.id)),
|
||||
$doc("$eq" -> $arr("$s", "$$s"))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
"as" -> "player"
|
||||
)
|
||||
)
|
||||
),
|
||||
Match("player" $ne $arr()),
|
||||
Project($id(true))
|
||||
)
|
||||
}
|
||||
.map(_.flatMap(_.getAsOpt[Swiss.Id]("_id")))
|
||||
.flatMap {
|
||||
_.map { withdraw(_, user.id) }.sequenceFu.void
|
||||
}
|
||||
|
||||
private def Sequencing[A: Zero](
|
||||
id: Swiss.Id
|
||||
)(fetch: Swiss.Id => Fu[Option[Swiss]])(run: Swiss => Fu[A]): Fu[A] =
|
||||
|
|
|
@ -206,10 +206,10 @@ final class TeamApi(
|
|||
}
|
||||
}
|
||||
|
||||
def quitAll(userId: User.ID): Funit =
|
||||
def quitAll(userId: User.ID): Fu[List[Team.ID]] =
|
||||
cached.teamIdsList(userId) flatMap { teamIds =>
|
||||
memberRepo.removeByUser(userId) >>
|
||||
teamIds.map { teamRepo.incMembers(_, -1) }.sequenceFu.void
|
||||
teamIds.map { teamRepo.incMembers(_, -1) }.sequenceFu.void inject teamIds
|
||||
}
|
||||
|
||||
def kick(team: Team, userId: User.ID, me: User): Funit =
|
||||
|
|
Loading…
Reference in New Issue