fix fetching all user IDs by IP

icc-ip-api
Thibault Duplessis 2015-09-13 00:27:15 +02:00
parent 85ec3bf188
commit 6b2fb74095
2 changed files with 9 additions and 1 deletions

View File

@ -78,6 +78,14 @@ private[security] final class Api(firewall: Firewall, tor: Tor) {
_.flatMap(_.getAs[String]("user"))
}
}
def userIdsByIp(ip: String): Fu[List[String]] =
tube.storeColl.find(
BSONDocument("ip" -> ip),
BSONDocument("user" -> true)
).cursor[BSONDocument]().collect[List]().map {
_.flatMap(_.getAs[String]("user"))
}.map(_.distinct)
}
object Api {

View File

@ -8,7 +8,7 @@ final class Whois(key: String, api: Api, tor: Tor, userJson: lila.user.JsonView)
def apply(ip: String, reqKey: String): Fu[Either[String, JsObject]] =
if (reqKey != key) fuccess(Left("Invalid key"))
else api.userIdsSharingIp(ip) flatMap lila.user.UserRepo.byIds map { users =>
else api.userIdsByIp(ip) flatMap lila.user.UserRepo.byIds map { users =>
Right(Json.obj(
"ip" -> ip,
"tor" -> tor.isExitNode(ip),