From 0a82d9c34dccbe5fa2f1e4d2f80983a2a518ff7b Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 23 Jul 2017 14:57:01 +0200 Subject: [PATCH] show other users notes in mod view - closes #3332 --- app/controllers/User.scala | 8 ++++---- app/views/user/mod.scala.html | 6 +++--- modules/security/src/main/UserSpy.scala | 2 ++ modules/user/src/main/NoteApi.scala | 5 +++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/User.scala b/app/controllers/User.scala index 0d80d50030..3e61cf7fe2 100644 --- a/app/controllers/User.scala +++ b/app/controllers/User.scala @@ -248,14 +248,14 @@ object User extends LilaController { Env.plan.api.recentChargesOf(user) zip Env.report.api.byAndAbout(user, 20) zip Env.pref.api.getPref(user) zip - Env.irwin.api.status(user) zip - Env.user.noteApi.forMod(user.id) flatMap { - case emails ~ spy ~ assess ~ history ~ charges ~ reports ~ pref ~ irwin ~ notes => + Env.irwin.api.status(user) flatMap { + case emails ~ spy ~ assess ~ history ~ charges ~ reports ~ pref ~ irwin => (Env.playban.api bans spy.usersSharingIp.map(_.id)) zip + Env.user.noteApi.forMod(user.id :: spy.otherUserIds) zip Env.user.lightUserApi.preloadMany { reports.userIds ::: assess.??(_.games).flatMap(_.userIds) } map { - case (bans, _) => + case bans ~ notes ~ _ => html.user.mod(user, emails, spy, assess, bans, history, charges, reports, pref, irwin, notes) } } diff --git a/app/views/user/mod.scala.html b/app/views/user/mod.scala.html index 56e57ad959..d17b368d18 100644 --- a/app/views/user/mod.scala.html +++ b/app/views/user/mod.scala.html @@ -273,9 +273,9 @@ @o.count.game.localize - @defining(notes.filter(_.to == o.id)) { notes => - @if(notes.nonEmpty) { - @notes.size + @defining(notes.filter(_.to == o.id)) { ns => + @if(ns.nonEmpty) { + @ns.size } } @bans.get(o.id).map { nb => @nb } diff --git a/modules/security/src/main/UserSpy.scala b/modules/security/src/main/UserSpy.scala index c7d594585e..930b892108 100644 --- a/modules/security/src/main/UserSpy.scala +++ b/modules/security/src/main/UserSpy.scala @@ -27,6 +27,8 @@ case class UserSpy( OtherUser(_, false, true) } }.sortBy(-_.user.createdAt.getMillis) + + def otherUserIds = otherUsers.map(_.user.id) } object UserSpy { diff --git a/modules/user/src/main/NoteApi.scala b/modules/user/src/main/NoteApi.scala index bbb745cc63..60d621f49c 100644 --- a/modules/user/src/main/NoteApi.scala +++ b/modules/user/src/main/NoteApi.scala @@ -49,6 +49,11 @@ final class NoteApi( .sort($doc("date" -> -1)) .list[Note](20) + def forMod(ids: List[User.ID]): Fu[List[Note]] = + coll.find($doc("to" -> $doc("$in" -> ids))) + .sort($doc("date" -> -1)) + .list[Note](50) + def byMod(ids: List[User.ID]): Fu[List[Note]] = coll.find($doc("to" $in ids)) .sort($doc("date" -> -1))