keep user email on close if they're currently playbanned - closes #3877
parent
ba2c053185
commit
411ac03501
|
@ -73,20 +73,22 @@ final class Env(
|
|||
none
|
||||
}
|
||||
|
||||
def closeAccount(userId: lila.user.User.ID): Funit =
|
||||
lila.user.UserRepo byId userId flatten s"No such user $userId" flatMap { user =>
|
||||
(lila.user.UserRepo disable user) >>-
|
||||
Env.user.onlineUserIdMemo.remove(user.id) >>
|
||||
Env.relation.api.unfollowAll(user.id) >>
|
||||
Env.user.rankingApi.remove(user.id) >>
|
||||
Env.team.api.quitAll(user.id) >>-
|
||||
Env.challenge.api.removeByUserId(user.id) >>-
|
||||
Env.tournament.api.withdrawAll(user) >>
|
||||
Env.plan.api.cancel(user).nevermind >>
|
||||
Env.lobby.seekApi.removeByUser(user) >>
|
||||
Env.security.store.disconnect(user.id) >>-
|
||||
system.lilaBus.publish(lila.hub.actorApi.security.CloseAccount(user.id), 'accountClose)
|
||||
}
|
||||
def closeAccount(userId: lila.user.User.ID): Funit = for {
|
||||
user <- lila.user.UserRepo byId userId flatten s"No such user $userId"
|
||||
keepEmail <- if (user.lameOrTroll) fuccess(true) else Env.playban.api.hasCurrentBan(user.id)
|
||||
_ <- lila.user.UserRepo.disable(user, keepEmail = keepEmail)
|
||||
_ = Env.user.onlineUserIdMemo.remove(user.id)
|
||||
_ <- Env.relation.api.unfollowAll(user.id)
|
||||
_ <- Env.user.rankingApi.remove(user.id)
|
||||
_ <- Env.team.api.quitAll(user.id)
|
||||
_ = Env.challenge.api.removeByUserId(user.id)
|
||||
_ = Env.tournament.api.withdrawAll(user)
|
||||
_ <- Env.plan.api.cancel(user).nevermind
|
||||
_ <- Env.lobby.seekApi.removeByUser(user)
|
||||
_ <- Env.security.store.disconnect(user.id)
|
||||
} yield {
|
||||
system.lilaBus.publish(lila.hub.actorApi.security.CloseAccount(user.id), 'accountClose)
|
||||
}
|
||||
|
||||
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
|
|
|
@ -6,7 +6,7 @@ import chess.{ Status, Color }
|
|||
import lila.db.BSON._
|
||||
import lila.db.dsl._
|
||||
import lila.game.{ Pov, Game, Player, Source }
|
||||
import lila.user.UserRepo
|
||||
import lila.user.{ User, UserRepo }
|
||||
|
||||
final class PlaybanApi(
|
||||
coll: Coll,
|
||||
|
@ -101,16 +101,16 @@ final class PlaybanApi(
|
|||
save(if (isSandbag) Outcome.Sandbag else Outcome.Good)
|
||||
}
|
||||
|
||||
def currentBan(userId: String): Fu[Option[TempBan]] = coll.find(
|
||||
def currentBan(userId: User.ID): Fu[Option[TempBan]] = coll.find(
|
||||
$doc("_id" -> userId, "b.0" $exists true),
|
||||
$doc("_id" -> false, "b" -> $doc("$slice" -> -1))
|
||||
).uno[Bdoc].map {
|
||||
_.flatMap(_.getAs[List[TempBan]]("b")).??(_.find(_.inEffect))
|
||||
}
|
||||
|
||||
def hasCurrentBan(userId: String): Fu[Boolean] = currentBan(userId).map(_.isDefined)
|
||||
def hasCurrentBan(userId: User.ID): Fu[Boolean] = currentBan(userId).map(_.isDefined)
|
||||
|
||||
def completionRate(userId: String): Fu[Option[Double]] =
|
||||
def completionRate(userId: User.ID): Fu[Option[Double]] =
|
||||
coll.primitiveOne[List[Outcome]]($id(userId), "o").map(~_) map { outcomes =>
|
||||
outcomes.collect {
|
||||
case Outcome.RageQuit | Outcome.Sitting | Outcome.NoPlay => false
|
||||
|
@ -121,21 +121,21 @@ final class PlaybanApi(
|
|||
}
|
||||
}
|
||||
|
||||
def bans(userId: String): Fu[List[TempBan]] =
|
||||
def bans(userId: User.ID): Fu[List[TempBan]] =
|
||||
coll.primitiveOne[List[TempBan]]($doc("_id" -> userId, "b.0" $exists true), "b").map(~_)
|
||||
|
||||
def bans(userIds: List[String]): Fu[Map[String, Int]] = coll.find(
|
||||
def bans(userIds: List[User.ID]): Fu[Map[User.ID, Int]] = coll.find(
|
||||
$inIds(userIds),
|
||||
$doc("b" -> true)
|
||||
).cursor[Bdoc]().gather[List]().map {
|
||||
_.flatMap { obj =>
|
||||
obj.getAs[String]("_id") flatMap { id =>
|
||||
obj.getAs[User.ID]("_id") flatMap { id =>
|
||||
obj.getAs[Barr]("b") map { id -> _.stream.size }
|
||||
}
|
||||
}(scala.collection.breakOut)
|
||||
}
|
||||
|
||||
private def save(outcome: Outcome): String => Funit = userId => {
|
||||
private def save(outcome: Outcome): User.ID => Funit = userId => {
|
||||
lila.mon.playban.outcome(outcome.key)()
|
||||
coll.findAndUpdate(
|
||||
selector = $id(userId),
|
||||
|
|
|
@ -294,10 +294,10 @@ object UserRepo {
|
|||
|
||||
def enable(id: ID) = coll.updateField($id(id), F.enabled, true)
|
||||
|
||||
def disable(user: User) = coll.update(
|
||||
def disable(user: User, keepEmail: Boolean) = coll.update(
|
||||
$id(user.id),
|
||||
$set(F.enabled -> false) ++ {
|
||||
if (user.lameOrTroll) $empty
|
||||
if (keepEmail) $empty
|
||||
else $doc("$rename" -> $doc(F.email -> F.prevEmail))
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue